diff --git a/s/runtests b/s/runtests index 247db2251..68e08b607 100755 --- a/s/runtests +++ b/s/runtests @@ -15,8 +15,7 @@ if [ ! -d $ROOT/$BIN_DIR ]; then exit fi -echo $ROOT $ROOT/$BIN_DIR/eressea/test_eressea -cd $ROOT/scripts -$ROOT/$BIN_DIR/eressea/eressea -v0 runtests.lua - +cd $ROOT +$ROOT/$BIN_DIR/eressea/eressea -v0 scripts/runtests.lua +cd - diff --git a/scripts/runtests.lua b/scripts/runtests.lua index 8ea9614c0..dcf73fb08 100644 --- a/scripts/runtests.lua +++ b/scripts/runtests.lua @@ -1,9 +1,6 @@ -- new tests 2014-06-11 require "lunit" -require "tests.settings" -require "tests.config" --- require "tests.ships" - +require "tests" lunit.main() diff --git a/tests/config.lua b/tests/config.lua new file mode 100644 index 000000000..b24da72bc --- /dev/null +++ b/tests/config.lua @@ -0,0 +1,39 @@ +require "lunit" + +module("tests.eressea.config", package.seeall, lunit.testcase ) + +function setup() + eressea.free_game() +end + +function test_read_race() + local f + eressea.free_game() + f = faction.create("orc@example.com", "orc", "en") + assert_equal(nil, f) + assert_not_nil(eressea.config) + eressea.config.parse('{ "races": { "orc" : {}}}') + f = faction.create("orc@example.com", "orc", "en") + assert_not_nil(f) +end + +function test_read_ship() + local s + eressea.free_game() + s = ship.create(nil, "boat") + assert_equal(nil, s) + assert_not_nil(eressea.config) + conf = [[{ + "ships": { + "boat" : { + "construction" : { + "maxsize" : 20 + } + } + } + }]] + eressea.config.parse(conf); + s = ship.create(nil, "boat") + assert_not_nil(s) +end + diff --git a/tests/init.lua b/tests/init.lua new file mode 100644 index 000000000..f6e5a307c --- /dev/null +++ b/tests/init.lua @@ -0,0 +1,5 @@ +-- new tests 2014-06-11 +require "tests.settings" +require "tests.config" +require "tests.regions" +--require "tests.ships" diff --git a/tests/regions.lua b/tests/regions.lua new file mode 100644 index 000000000..ca9e9af45 --- /dev/null +++ b/tests/regions.lua @@ -0,0 +1,22 @@ +require "lunit" + +module("tests.regions", package.seeall, lunit.testcase) + +function setup() + eressea.free_game() + conf = [[{ + "terrains" : { + "ocean": {}, + "plain": {} + } + }]] + eressea.config.parse(conf) +end + +function test_create() + local r + r = region.create(0, 0, "ocean") + assert_not_nil(r) +end + + diff --git a/tests/settings.lua b/tests/settings.lua new file mode 100644 index 000000000..a454a1152 --- /dev/null +++ b/tests/settings.lua @@ -0,0 +1,13 @@ +require "lunit" + +module("tests.eressea.settings", package.seeall, lunit.testcase ) + +function setup() + eressea.free_game() +end + +function test_settings() + assert_equal(nil, eressea.settings.get("foo")) + eressea.settings.set("foo", "bar") + assert_equal("bar", eressea.settings.get("foo")) +end diff --git a/tests/ships.lua b/tests/ships.lua new file mode 100644 index 000000000..35ef87fc7 --- /dev/null +++ b/tests/ships.lua @@ -0,0 +1,52 @@ +require "lunit" + +module("tests.ships", 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") + conf = [[{ + "races": { + "human" : {}, + "insect" : {} + }, + "ships" : { + "boat" : {}, + "longboat" : {} + }, + "buildings" : { + "harbour" : {} + }, + "terrains" : { + "ocean": {}, + "plain": {} + } + }]] + + eressea.config.parse(conf) +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", "insect", "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) + + u1.ship = s + u1:set_skill("sailing", 10) + u1:clear_orders() + u1:add_order("NACH w") + process_orders() + + assert_equal(r, u1.region) -- the plain case: okay +end + +