From 8f21aa7a111bb63369ba3b4179e2fccf5177b823 Mon Sep 17 00:00:00 2001 From: CTD Date: Fri, 13 Feb 2015 16:03:05 +0100 Subject: [PATCH] repairing lua tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Das ist totales Chaos, viele Testcases wurden einfach nicht ausgeführt weil sie nicht in den init files stehen. Etwas neu strukturiert, Test laufen jetzt auch wenn sie nicht aus dem eressea root Ordner gestartet werden wie in s/runtest und es sind einige Testcases mehr als bisher. Auch macht Travis jetzt die E3 Test. Dabei ist ein schwerwiegender Fehler beim neuen Bewache aufgefallen! --- s/runtests | 3 +- s/travis-build | 4 +- scripts/run-tests-basic.lua | 17 +++++++ scripts/run-tests-e2.lua | 21 +++++++++ scripts/run-tests-e3.lua | 9 ++-- scripts/run-tests.lua | 13 ------ .../tests/{eressea.lua => e2/e2features.lua} | 30 ++----------- scripts/tests/e2/init.lua | 4 ++ .../tests/{rules.lua => e2/shiplanding.lua} | 45 ++++++++++++++----- scripts/tests/{ => e3}/morale.lua | 0 scripts/tests/e3/rules.lua | 24 ++++++++++ scripts/tests/{ => e3}/spells-e2.lua | 0 scripts/tests/faction.lua | 9 +--- scripts/tests/init.lua | 8 ++-- 14 files changed, 120 insertions(+), 67 deletions(-) create mode 100644 scripts/run-tests-basic.lua create mode 100644 scripts/run-tests-e2.lua delete mode 100644 scripts/run-tests.lua rename scripts/tests/{eressea.lua => e2/e2features.lua} (91%) create mode 100644 scripts/tests/e2/init.lua rename scripts/tests/{rules.lua => e2/shiplanding.lua} (74%) rename scripts/tests/{ => e3}/morale.lua (100%) rename scripts/tests/{ => e3}/spells-e2.lua (100%) diff --git a/s/runtests b/s/runtests index ea192b98b..00e04a45b 100755 --- a/s/runtests +++ b/s/runtests @@ -18,6 +18,7 @@ fi $ROOT/$BIN_DIR/eressea/test_eressea cd $ROOT [ -e eressea.ini ] || ln -sf conf/eressea.ini -$ROOT/$BIN_DIR/eressea/eressea -v0 scripts/run-tests.lua +$ROOT/$BIN_DIR/eressea/eressea -v0 scripts/run-tests-basic.lua +$ROOT/$BIN_DIR/eressea/eressea -v0 scripts/run-tests-e2.lua $ROOT/$BIN_DIR/eressea/eressea -v0 scripts/run-tests-e3.lua cd $OLDWPD diff --git a/s/travis-build b/s/travis-build index b08a5a890..f27fa2050 100755 --- a/s/travis-build +++ b/s/travis-build @@ -13,4 +13,6 @@ cd build && cmake .. \ -DCMAKE_BUILD_TYPE=Debug .. && \ make && cd .. && inifile && build/eressea/test_eressea && -build/eressea/eressea -v0 scripts/run-tests.lua +build/eressea/eressea -v0 scripts/run-tests-basic.lua +build/eressea/eressea -v0 scripts/run-tests-e2.lua +build/eressea/eressea -v0 scripts/run-tests-e3.lua diff --git a/scripts/run-tests-basic.lua b/scripts/run-tests-basic.lua new file mode 100644 index 000000000..9f0589c4a --- /dev/null +++ b/scripts/run-tests-basic.lua @@ -0,0 +1,17 @@ +-- new tests 2014-06-11 +-- Basic test without loading XML Config. Test care about needed settings. +-- Tests are under scripts/test/ and all files must be in scripts/test/init.lua + +path = 'scripts' +if config.install then + path = config.install .. '/' .. path + package.path = package.path .. ';' .. config.install .. '/lunit/?.lua' + --needed to find lunit if not run form eressea root. Needs right [lua] install setting in eressea.ini (point to eressea root from the start folder) +end +package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' + +require 'eressea' +require 'eressea.path' +require 'tests' +require 'lunit' +lunit.main() diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua new file mode 100644 index 000000000..6b181d790 --- /dev/null +++ b/scripts/run-tests-e2.lua @@ -0,0 +1,21 @@ +-- Tests that work in all games. With game config of E2. +-- Tests are under scripts/test/e2 and all files must be in scripts/test/e2/init.lua + +path = 'scripts' +if config.install then + path = config.install .. '/' .. path + package.path = package.path .. ';' .. config.install .. '/lunit/?.lua' + --needed to find lunit if not run form eressea root. Needs right [lua] install setting in eressea.ini (point to eressea root from the start folder) +end +package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' + +config.rules = 'e2' + +require 'eressea' +require 'eressea.xmlconf' +require 'eressea.path' +require 'tests.e2' +require 'lunit' + +rules = require('eressea.' .. config.rules) +lunit.main() diff --git a/scripts/run-tests-e3.lua b/scripts/run-tests-e3.lua index 3e5ecdcb2..93b3ac81f 100644 --- a/scripts/run-tests-e3.lua +++ b/scripts/run-tests-e3.lua @@ -1,8 +1,11 @@ --- new tests 2014-06-11 +-- Tests that work in E3. With game config of E3. +-- Tests are under scripts/test/e3 and all files must be in scripts/test/e3/init.lua path = 'scripts' -if config.source_dir ~= nil then - path = config.source_dir .. '/' .. path +if config.install then + path = config.install .. '/' .. path + package.path = package.path .. ';' .. config.install .. '/lunit/?.lua' + --needed to find lunit if not run form eressea root. Needs right [lua] install setting in eressea.ini (point to eressea root from the start folder) end package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' diff --git a/scripts/run-tests.lua b/scripts/run-tests.lua deleted file mode 100644 index a230f8e97..000000000 --- a/scripts/run-tests.lua +++ /dev/null @@ -1,13 +0,0 @@ --- new tests 2014-06-11 - -path = 'scripts' -if config.source_dir ~= nil then - path = config.source_dir .. '/' .. path -end -package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' - -require 'eressea' -require 'eressea.path' -require 'tests' -require 'lunit' -lunit.main() diff --git a/scripts/tests/eressea.lua b/scripts/tests/e2/e2features.lua similarity index 91% rename from scripts/tests/eressea.lua rename to scripts/tests/e2/e2features.lua index 789b81b6b..20c3c234b 100644 --- a/scripts/tests/eressea.lua +++ b/scripts/tests/e2/e2features.lua @@ -1,6 +1,6 @@ require "lunit" -module("tests.e3.e2features", package.seeall, lunit.testcase ) +module("tests.e2.e2features", package.seeall, lunit.testcase ) local function one_unit(r, f) local u = unit.create(f, r, 1) @@ -269,7 +269,7 @@ end function test_block_movement_aots() eressea.settings.set("rules.guard.base_stop_prob", "0.0") eressea.settings.set("rules.guard.skill_stop_prob", "1.0") - eressea.settings.set("rules.guard.amulet_stop_prob", "1.1") + eressea.settings.set("rules.guard.amulet_stop_prob", "1.0") local r0 = region.create(0, 0, "plain") local r1 = region.create(1, 0, "plain") @@ -298,7 +298,7 @@ function test_block_movement_aots() u:add_order("NACH o o") end - u12:add_item("aots", 10) + u12:add_item("aots", 1) u22:set_skill("stealth", 1) process_orders() @@ -334,27 +334,3 @@ function test_stonegolems() assert_equal(1 ,u2.number, "There shoud be one Stone Golems") -- end test Stone Golems four stones end - -function test_only_building_owner_can_set_not_paid() - local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") - local u1 = unit.create(f, r, 1) - local u2 = unit.create(f, r, 1) - local mine = building.create(r, "mine") - mine.size = 2 - u1:add_item("money", 500) - u1.building = mine - u2.building = mine - u1:clear_orders() - u2:clear_orders() --- Test that Bezahle nicht is working - u1:add_order("Bezahle nicht") - process_orders() - assert_equal(500, u1:get_item("money")) - u1:clear_orders() --- Test that bug fix 0001976 is working --- Bezahle nicht is not working - u2:add_order("Bezahle nicht") - process_orders() - assert_equal(0, u1:get_item("money")) -end diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua new file mode 100644 index 000000000..1b436fcef --- /dev/null +++ b/scripts/tests/e2/init.lua @@ -0,0 +1,4 @@ +-- new tests 2015-02-13 +require 'tests.e2.shiplanding' +require 'tests.e2.e2features' + diff --git a/scripts/tests/rules.lua b/scripts/tests/e2/shiplanding.lua similarity index 74% rename from scripts/tests/rules.lua rename to scripts/tests/e2/shiplanding.lua index 6ed6601cb..2d9225b8d 100644 --- a/scripts/tests/rules.lua +++ b/scripts/tests/e2/shiplanding.lua @@ -1,19 +1,18 @@ require "lunit" -module("tests.rules", package.seeall, lunit.testcase) +module("tests.e2.shiplanding", package.seeall, lunit.testcase) function setup() eressea.free_game() eressea.settings.set("nmr.removenewbie", "0") eressea.settings.set("nmr.timeout", "0") eressea.settings.set("NewbieImmunity", "0") - eressea.config.parse('{ "races": { "human" : {}}}') end function test_landing1() local ocean = region.create(1, 0, "ocean") local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "insects", "de") + local f = faction.create("noreply@eressea.de", "human", "de") local f2 = faction.create("noreply@eressea.de", "human", "de") local s = ship.create(ocean, "longboat") local u1 = unit.create(f, ocean, 1) @@ -31,7 +30,33 @@ function test_landing1() assert_equal(r.id, u1.region.id) -- the plain case: okay end -function test_landing_harbour() +function test_landing_harbour_with_help() + local ocean = region.create(1, 0, "ocean") + local r = region.create(0, 0, "glacier") + local harbour = building.create(r, "harbour") + harbour.size = 25 + local f = faction.create("noreply@eressea.de", "human", "de") + local f2 = faction.create("noreply@eressea.de", "human", "de") + local s = ship.create(ocean, "longboat") + local u1 = unit.create(f, ocean, 1) + local u2 = unit.create(f2, r, 1) + assert_not_nil(u2) + u1:add_item("money", 1000) + u2:add_item("money", 1000) + u2.building = harbour + u2:clear_orders() + u2:add_order("KONTAKTIERE " .. itoa36(u1.id)) + + u1.ship = s + u1:set_skill("sailing", 10) + u1:clear_orders() + u1:add_order("NACH w") + process_orders() + + assert_equal(r.id, u1.region.id) -- glacier with harbour and help-- okay +end + +function test_landing_harbour_without_help() local ocean = region.create(1, 0, "ocean") local r = region.create(0, 0, "glacier") local harbour = building.create(r, "harbour") @@ -52,7 +77,7 @@ function test_landing_harbour() u1:add_order("NACH w") process_orders() - assert_equal(r.id, u1.region.id) -- glacier with harbour -- okay + assert_equal(ocean.id, u1.region.id) -- glacier with harbour and no help-- cannot land end function test_landing_harbour_unpaid() @@ -61,13 +86,12 @@ function test_landing_harbour_unpaid() local harbour = building.create(r, "harbour") harbour.size = 25 local f = faction.create("noreply@eressea.de", "human", "de") - local f2 = faction.create("noreply@eressea.de", "human", "de") local s = ship.create(ocean, "longboat") local u1 = unit.create(f, ocean, 1) - local u2 = unit.create(f2, r, 1) + local u2 = unit.create(f, r, 1) assert_not_nil(u2) u1:add_item("money", 1000) - u2:add_item("money", 1000) + u2:add_item("money", 20) u1.ship = s u1:set_skill("sailing", 10) @@ -91,8 +115,7 @@ function test_landing_terrain() u2:add_item("money", 1000) u1.ship = s - u1:set_skill("sailing", 10) - u1:clear_orders() + u1:set_skill("sailing", 10) u1:clear_orders() u1:add_order("NACH w") process_orders() @@ -104,7 +127,7 @@ function test_landing_insects() local r = region.create(0, 0, "glacier") local harbour = building.create(r, "harbour") harbour.size = 25 - local f = faction.create("noreply@eressea.de", "insects", "de") + local f = faction.create("noreply@eressea.de", "insect", "de") local f2 = faction.create("noreply@eressea.de", "human", "de") local s = ship.create(ocean, "longboat") local u1 = unit.create(f, ocean, 1) diff --git a/scripts/tests/morale.lua b/scripts/tests/e3/morale.lua similarity index 100% rename from scripts/tests/morale.lua rename to scripts/tests/e3/morale.lua diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index 193551ea9..ca6206419 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -779,3 +779,27 @@ function test_weightless_silver() u1:add_item("money", 540) assert_equal(1000, u1.weight) end + +function test_only_building_owner_can_set_not_paid() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u1 = unit.create(f, r, 1) + local u2 = unit.create(f, r, 1) + local mine = building.create(r, "mine") + mine.size = 2 + u1:add_item("money", 500) + u1.building = mine + u2.building = mine + u1:clear_orders() + u2:clear_orders() +-- Test that Bezahle nicht is working + u1:add_order("Bezahle nicht") + process_orders() + assert_equal(500, u1:get_item("money")) + u1:clear_orders() +-- Test that bug fix 0001976 is working +-- Bezahle nicht is not working + u2:add_order("Bezahle nicht") + process_orders() + assert_equal(0, u1:get_item("money")) +end diff --git a/scripts/tests/spells-e2.lua b/scripts/tests/e3/spells-e2.lua similarity index 100% rename from scripts/tests/spells-e2.lua rename to scripts/tests/e3/spells-e2.lua diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index a6a07a6e1..ab2817fe8 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -1,15 +1,10 @@ +require "lunit" + module ('tests.eressea.faction', package.seeall, lunit.testcase) local f function setup() - conf = [[{ - "races": { - "human" : {} - } - }]] - eressea.config.reset() - assert(eressea.config.parse(conf)==0) f = faction.create("faction@eressea.de", "human", "de") end diff --git a/scripts/tests/init.lua b/scripts/tests/init.lua index deb3e1a89..57477be1d 100644 --- a/scripts/tests/init.lua +++ b/scripts/tests/init.lua @@ -1,9 +1,9 @@ -- new tests 2014-06-11 -require 'tests.pool' -require 'tests.settings' require 'tests.config' require 'tests.faction' require 'tests.locale' -require 'tests.regions' -require 'tests.study' require 'tests.movement' +require 'tests.pool' +require 'tests.regions' +require 'tests.settings' +require 'tests.study'