Merge branch 'CTD1-repairing_lua_tests' into develop

This commit is contained in:
Enno Rehling 2015-02-20 20:28:50 +01:00
commit 1265daa3c6
13 changed files with 109 additions and 56 deletions

View File

@ -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

View File

@ -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

22
scripts/run-tests-e2.lua Normal file
View File

@ -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

View File

@ -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'

View File

@ -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'

View File

@ -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

View File

@ -0,0 +1,4 @@
-- new tests 2015-02-13
require 'tests.e2.shiplanding'
require 'tests.e2.e2features'

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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'