diff --git a/s/runtests b/s/runtests index ea192b98b..ef7fc71df 100755 --- a/s/runtests +++ b/s/runtests @@ -19,5 +19,6 @@ $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-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-e2.lua b/scripts/run-tests-e2.lua new file mode 100644 index 000000000..aff15eb06 --- /dev/null +++ b/scripts/run-tests-e2.lua @@ -0,0 +1,22 @@ +-- 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) +result = lunit.main() +return result.errors diff --git a/scripts/run-tests-e3.lua b/scripts/run-tests-e3.lua index c201d8750..2f823daa7 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 index 5583ef673..d13a1425b 100644 --- a/scripts/run-tests.lua +++ b/scripts/run-tests.lua @@ -1,8 +1,11 @@ --- 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.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/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'