2020-04-19 21:35:48 +02:00
|
|
|
local tcname = 'tests.shared.report'
|
2020-05-03 16:52:40 +02:00
|
|
|
local lunit = require('lunit')
|
2020-04-19 21:35:48 +02:00
|
|
|
if _VERSION >= 'Lua 5.2' then
|
|
|
|
_ENV = module(tcname, 'seeall')
|
|
|
|
else
|
2020-05-03 16:52:40 +02:00
|
|
|
module(tcname, lunit.testcase, package.seeall)
|
2020-04-19 21:35:48 +02:00
|
|
|
end
|
2016-09-14 17:04:23 +02:00
|
|
|
|
|
|
|
function setup()
|
|
|
|
eressea.free_game()
|
|
|
|
eressea.settings.set("nmr.timeout", "0")
|
|
|
|
eressea.settings.set("rules.food.flags", "4")
|
|
|
|
end
|
|
|
|
|
|
|
|
local function find_in_report(f, pattern, extension)
|
|
|
|
extension = extension or "nr"
|
|
|
|
local filename = config.reportpath .. "/" .. get_turn() .. "-" .. itoa36(f.id) .. "." .. extension
|
|
|
|
local report = io.open(filename, 'r');
|
|
|
|
assert_not_nil(report)
|
|
|
|
t = report:read("*all")
|
|
|
|
report:close()
|
|
|
|
|
|
|
|
local start, _ = string.find(t, pattern)
|
|
|
|
return start~=nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local function remove_report(faction)
|
|
|
|
local filetrunk = config.reportpath .. "/" .. get_turn() .. "-" .. itoa36(faction.id)
|
|
|
|
os.remove(filetrunk .. ".nr")
|
|
|
|
os.remove(filetrunk .. ".cr")
|
|
|
|
os.remove(filetrunk .. ".txt")
|
|
|
|
end
|
|
|
|
|
|
|
|
function setup()
|
|
|
|
eressea.free_game()
|
|
|
|
eressea.settings.set("nmr.timeout", "0")
|
|
|
|
eressea.settings.set("rules.food.flags", "4")
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_coordinates_unnamed_plane()
|
|
|
|
local p = plane.create(0, -3, -3, 7, 7)
|
|
|
|
local r = region.create(0, 0, "mountain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "unnamed@eressea.de", "de")
|
2016-09-14 17:04:23 +02:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
init_reports()
|
|
|
|
write_report(f)
|
|
|
|
assert_true(find_in_report(f, r.name .. " %(0,0%), Berg"))
|
|
|
|
remove_report(f)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_coordinates_no_plane()
|
|
|
|
local r = region.create(0, 0, "mountain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "noplane@eressea.de", "de")
|
2016-09-14 17:04:23 +02:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
init_reports()
|
|
|
|
write_report(f)
|
|
|
|
assert_true(find_in_report(f, r.name .. " %(0,0%), Berg"))
|
|
|
|
remove_report(f)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_show_shadowmaster_attacks()
|
|
|
|
local r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "noreply@eressea.de", "de")
|
2016-09-14 17:04:23 +02:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
u.race = "shadowmaster"
|
|
|
|
u:clear_orders()
|
|
|
|
u:add_order("ZEIGE Schattenmeister")
|
|
|
|
process_orders()
|
|
|
|
init_reports()
|
|
|
|
write_report(f)
|
|
|
|
assert_false(find_in_report(f, ", ,"))
|
|
|
|
remove_report(f)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_coordinates_named_plane()
|
|
|
|
local p = plane.create(0, -3, -3, 7, 7, "Hell")
|
|
|
|
local r = region.create(0, 0, "mountain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "noreply@eressea.de", "de")
|
2016-09-14 17:04:23 +02:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
init_reports()
|
|
|
|
write_report(f)
|
|
|
|
assert_true(find_in_report(f, r.name .. " %(0,0,Hell%), Berg"))
|
|
|
|
remove_report(f)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_coordinates_noname_plane()
|
|
|
|
local p = plane.create(0, -3, -3, 7, 7, "")
|
|
|
|
local r = region.create(0, 0, "mountain")
|
2017-03-17 22:31:59 +01:00
|
|
|
local f = faction.create("human", "noreply@eressea.de", "de")
|
2016-09-14 17:04:23 +02:00
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
init_reports()
|
|
|
|
write_report(f)
|
|
|
|
assert_true(find_in_report(f, r.name .. " %(0,0%), Berg"))
|
|
|
|
remove_report(f)
|
|
|
|
end
|
|
|
|
|
2019-08-20 17:30:21 +02:00
|
|
|
function test_lighthouse()
|
2016-09-14 17:04:23 +02:00
|
|
|
eressea.free_game()
|
|
|
|
local r = region.create(0, 0, "mountain")
|
2020-09-27 15:51:32 +02:00
|
|
|
local f = faction.create("human", "lighthouse@example.com")
|
2019-08-20 17:30:21 +02:00
|
|
|
local f2 = faction.create("dwarf")
|
|
|
|
local r2 = region.create(1, 0, "mountain")
|
|
|
|
unit.create(f2, r2, 1).name = 'The Babadook'
|
2016-09-14 17:04:23 +02:00
|
|
|
region.create(2, 0, "ocean")
|
|
|
|
region.create(0, 1, "firewall")
|
2018-07-17 20:53:34 +02:00
|
|
|
region.create(3, 0, "ocean")
|
2016-09-14 17:04:23 +02:00
|
|
|
region.create(4, 0, "plain")
|
|
|
|
local u = unit.create(f, r, 1)
|
|
|
|
local b = building.create(r, "lighthouse")
|
|
|
|
b.size = 100
|
|
|
|
u.building = b
|
|
|
|
u:set_skill("perception", 9)
|
|
|
|
u:add_item("money", 1000)
|
|
|
|
assert_not_nil(b)
|
|
|
|
|
|
|
|
init_reports()
|
|
|
|
write_report(f)
|
2019-08-20 17:30:21 +02:00
|
|
|
assert_false(find_in_report(f, "The Babadook"))
|
|
|
|
assert_true(find_in_report(f, " %(1,0%) %(vom Turm erblickt%)"))
|
2016-09-14 17:04:23 +02:00
|
|
|
assert_true(find_in_report(f, " %(2,0%) %(vom Turm erblickt%)"))
|
|
|
|
assert_true(find_in_report(f, " %(3,0%) %(vom Turm erblickt%)"))
|
2019-08-20 17:30:21 +02:00
|
|
|
assert_true(find_in_report(f, " %(0,1%) %(vom Turm erblickt%)"))
|
2016-09-14 17:04:23 +02:00
|
|
|
|
|
|
|
assert_false(find_in_report(f, " %(0,0%) %(vom Turm erblickt%)"))
|
|
|
|
assert_false(find_in_report(f, " %(4,0%) %(vom Turm erblickt%)"))
|
|
|
|
remove_report(f)
|
|
|
|
end
|
|
|
|
|