2020-04-19 21:35:48 +02:00
|
|
|
local tcname = 'tests.shared.process'
|
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
|
2015-05-19 23:27:57 +02:00
|
|
|
|
2018-02-10 21:13:09 +01:00
|
|
|
local u, r, f
|
2015-05-19 23:27:57 +02:00
|
|
|
|
|
|
|
function setup()
|
|
|
|
eressea.free_game()
|
|
|
|
r = region.create(0, 0, "plain")
|
2017-03-17 22:31:59 +01:00
|
|
|
f = faction.create("human", "bernd@eressea.de", "de")
|
2015-05-19 23:27:57 +02:00
|
|
|
u = unit.create(f, r, 1)
|
|
|
|
u:add_item("money", 10)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function file_exists(name)
|
|
|
|
local f=io.open(name,"r")
|
|
|
|
if f~=nil then io.close(f) return true else return false end
|
|
|
|
end
|
|
|
|
|
2017-09-18 21:43:52 +02:00
|
|
|
local function assert_file(filename, exists)
|
|
|
|
if exists == nil then exists = true end
|
|
|
|
assert_equal(exists, file_exists(filename))
|
2015-05-19 23:27:57 +02:00
|
|
|
os.remove(filename)
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_process_turn()
|
2018-02-14 20:00:48 +01:00
|
|
|
turn_begin()
|
2018-02-10 21:13:09 +01:00
|
|
|
turn = get_turn()
|
2018-02-14 20:00:48 +01:00
|
|
|
turn_process()
|
|
|
|
turn_end()
|
|
|
|
assert_equal(turn, get_turn())
|
2018-02-10 21:13:09 +01:00
|
|
|
turn_begin()
|
|
|
|
assert_equal(turn+1, get_turn())
|
2018-02-14 20:00:48 +01:00
|
|
|
turn_process()
|
|
|
|
turn_end()
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_write_reports()
|
|
|
|
turn_begin()
|
|
|
|
turn = get_turn()
|
2015-05-19 23:27:57 +02:00
|
|
|
u:add_order("NUMMER PARTEI 777")
|
2018-02-10 21:13:09 +01:00
|
|
|
turn_process()
|
2015-05-19 23:27:57 +02:00
|
|
|
assert_equal(0, init_reports())
|
|
|
|
assert_equal(0, write_reports())
|
2018-02-14 20:00:48 +01:00
|
|
|
assert_file("reports/" .. turn .. "-777.nr")
|
|
|
|
assert_file("reports/" .. turn .. "-777.cr")
|
|
|
|
assert_file("reports/" .. turn .. "-777.txt")
|
2015-05-19 23:27:57 +02:00
|
|
|
assert_file("reports/reports.txt")
|
|
|
|
os.remove("reports")
|
2018-02-14 20:00:48 +01:00
|
|
|
assert_equal(0, eressea.write_game("test.dat"))
|
|
|
|
assert_file("data/test.dat")
|
|
|
|
os.remove("data/test.dat")
|
2018-02-10 21:13:09 +01:00
|
|
|
turn_end()
|
2015-05-19 23:27:57 +02:00
|
|
|
end
|