Merge pull request #95 from badgerman/master

when tests are modifying important global state, they should reset it.
This commit is contained in:
Enno Rehling 2015-01-03 16:53:11 +01:00
commit eed26eddd4
2 changed files with 45 additions and 9 deletions

View File

@ -5,10 +5,21 @@ module('eressea.tests.stealth', package.seeall, lunit.testcase)
local f
local u
local settings
local function set_rule(key, value)
if value==nil then
eressea.settings.set(key, settings[key])
else
settings[key] = settings[key] or eressea.settings.get(key)
eressea.settings.set(key, value)
end
end
function setup()
eressea.game.reset()
eressea.settings.set('rules.economy.food', '4')
eressea.settings.set('rules.magic.playerschools', '')
set_rule('rules.economy.food', '4')
set_rule('rules.magic.playerschools', '')
local r = region.create(0,0, "plain")
f = faction.create("stealthy@eressea.de", "human", "de")
@ -16,11 +27,17 @@ function setup()
f = faction.create("stealth@eressea.de", "human", "de")
end
function teardown()
set_rule('rules.economy.food')
set_rule('rules.magic.playerschools')
set_rule('rules.stealth.faction')
end
function test_stealth_faction_on()
u:clear_orders()
u:add_order("TARNEN PARTEI")
eressea.settings.set("rules.stealth.faction", 1)
set_rule("rules.stealth.faction", 1)
process_orders()
assert_not_match("Partei", report.report_unit(u, f))
assert_match("anonym", report.report_unit(u, f))
@ -30,7 +47,7 @@ function test_stealth_faction_off()
u:clear_orders()
u:add_order("TARNEN PARTEI")
eressea.settings.set("rules.stealth.faction", 0)
set_rule("rules.stealth.faction", 0)
process_orders()
assert_match("Partei", report.report_unit(u, f))
assert_not_match("anonym", report.report_unit(u, f))

View File

@ -2,9 +2,31 @@ require "lunit"
module("tests.e3.e3features", package.seeall, lunit.testcase)
local settings
local function set_rule(key, value)
if value==nil then
eressea.settings.set(key, settings[key])
else
settings[key] = settings[key] or eressea.settings.get(key)
eressea.settings.set(key, value)
end
end
function setup()
eressea.game.reset()
eressea.settings.set("rules.economy.food", "4")
settings = {}
set_rule("rules.move.owner_leave", "1")
set_rule("rules.economy.food", "4")
set_rule("rules.ship.drifting", "0")
set_rule("rules.ship.storms", "0")
end
function teardown()
set_rule("rules.move.owner_leave")
set_rule("rules.economy.food")
set_rule("rules.ship.drifting")
set_rule("rules.ship.storms")
end
function disable_test_bug_1738_build_castle_e3()
@ -235,8 +257,6 @@ function test_fishing()
end
function test_ship_capacity()
eressea.settings.set("rules.ship.drifting", "0")
eressea.settings.set("rules.ship.storms", "0")
local r = region.create(0,0, "ocean")
region.create(1,0, "ocean")
local r2 = region.create(2,0, "ocean")
@ -342,7 +362,6 @@ function test_taxes()
end
function test_region_owner_cannot_leave_castle()
eressea.settings.set("rules.move.owner_leave", "1")
local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de")
f.id = 42
@ -703,7 +722,7 @@ end
function test_building_owner_can_enter_ship()
local r1 = region.create(1, 2, "plain")
local f1 = faction.create("noreply@tteessttiinngg.de", "human", "de")
local f1 = faction.create("noreply@eressea.de", "human", "de")
local b1 = building.create(r1, "castle")
b1.size = 10
local s1 = ship.create(r1, "cutter")