From 14b1a164edd967b1efaa6618a92932153b93ecf7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 3 Jan 2015 16:11:33 +0100 Subject: [PATCH] when tests are modifying important global state, they should reset it in teardown. TODO: actually, they probably should not modify state in the first place. --- scripts/eressea/tests/stealth.lua | 25 +++++++++++++++++++++---- scripts/tests/e3/rules.lua | 29 ++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/scripts/eressea/tests/stealth.lua b/scripts/eressea/tests/stealth.lua index fcdf48b70..6d1a1dee4 100644 --- a/scripts/eressea/tests/stealth.lua +++ b/scripts/eressea/tests/stealth.lua @@ -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)) diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index 587310926..2be016a22 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -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")