Merge pull request #901 from ennorehling/develop

Develop
This commit is contained in:
Enno Rehling 2020-05-03 20:24:55 +02:00 committed by GitHub
commit 1c32d1f9f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
69 changed files with 722 additions and 489 deletions

3
.gitmodules vendored
View File

@ -1,6 +1,3 @@
[submodule "lunit"]
path = lunit
url = https://github.com/ennorehling/lunit.git
[submodule "dlmalloc"] [submodule "dlmalloc"]
path = dlmalloc path = dlmalloc
url = https://github.com/ennorehling/dlmalloc.git url = https://github.com/ennorehling/dlmalloc.git

View File

@ -17,6 +17,7 @@ addons:
- valgrind - valgrind
- cppcheck - cppcheck
- shellcheck - shellcheck
- luarocks
os: os:
- linux - linux
notifications: notifications:

View File

@ -48,8 +48,12 @@ endif()
find_package(EXPAT REQUIRED) find_package(EXPAT REQUIRED)
find_package (ToLua REQUIRED) find_package (ToLua REQUIRED)
if (TOLUA_FOUND) if (TOLUA_FOUND)
if (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.2") if (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.3")
find_package (Lua 5.3 REQUIRED)
elseif (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.2")
find_package (Lua 5.2 REQUIRED) find_package (Lua 5.2 REQUIRED)
elseif (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.3")
find_package ( Lua 5.3 REQUIRED)
else () else ()
find_package (Lua51 REQUIRED) find_package (Lua51 REQUIRED)
endif() endif()

2
clibs

@ -1 +1 @@
Subproject commit abe774f70265de14ea7f5e530518ca130562a9c9 Subproject commit 484fbf23e34f6844f1c4e3f685bb6c53cadf5bfe

1
lunit

@ -1 +0,0 @@
Subproject commit 155c96594435413b4f704eb17558ea0b70631bad

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
ROOT=$(git rev-parse --show-toplevel) ROOT=$(git rev-parse --show-toplevel)
eval $(luarocks path)
[ -z "$BUILD" ] && BUILD=Debug [ -z "$BUILD" ] && BUILD=Debug
if [ -z "$JOBS" ] ; then if [ -z "$JOBS" ] ; then
if [ -e /usr/sbin/sysctl ]; then if [ -e /usr/sbin/sysctl ]; then

View File

@ -6,6 +6,7 @@ pkg-config --exists sqlite3 && ERESSEA_DB=sqlite
GETOPT=getopt GETOPT=getopt
GETOPT_LONG=1 GETOPT_LONG=1
luarocks install lunitx --local
if [ "Darwin" = "$(uname)" ] ; then if [ "Darwin" = "$(uname)" ] ; then
if [ -x "/usr/local/opt/gnu-getopt/bin/getopt" ] ; then if [ -x "/usr/local/opt/gnu-getopt/bin/getopt" ] ; then
GETOPT="/usr/local/opt/gnu-getopt/bin/getopt" GETOPT="/usr/local/opt/gnu-getopt/bin/getopt"
@ -74,18 +75,19 @@ fi
DEST=$(dirname $ROOT)/server DEST=$(dirname $ROOT)/server
git submodule update --init
LUA_VERSION="5.2" LUA_VERSION="5.2"
LUA_INCLUDE=/usr/include LUA_INCLUDE=/usr/include
LUA_DIR=/usr LUA_DIR=/usr
if [ -d /usr/include/lua5.1 ]; then if [ -d /usr/local/include/lua5.3 ]; then
LUA_VERSION="5.1" LUA_VERSION="5.3"
LUA_INCLUDE=/usr/include/lua5.1 LUA_INCLUDE=/usr/local/include/lua5.3
elif [ -d /usr/include/lua5.2 ]; then elif [ -d /usr/include/lua5.2 ]; then
export LUA_DIR=/usr export LUA_DIR=/usr
LUA_VERSION="5.2" LUA_VERSION="5.2"
LUA_INCLUDE=/usr/include/lua5.2 LUA_INCLUDE=/usr/include/lua5.2
elif [ -d /usr/include/lua5.1 ]; then
LUA_VERSION="5.1"
LUA_INCLUDE=/usr/include/lua5.1
elif [ -d /usr/local/include/lua5.1 ]; then elif [ -d /usr/local/include/lua5.1 ]; then
export LUA_DIR=/usr/local export LUA_DIR=/usr/local
LUA_VERSION="5.1" LUA_VERSION="5.1"
@ -125,6 +127,7 @@ TOLUA
else else
echo "tolua is $path" echo "tolua is $path"
fi fi
luarocks --local install lunitx
unset path unset path
set -e set -e

View File

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
set -e set -e
eval $(luarocks path)
ROOT=$(git rev-parse --show-toplevel) ROOT=$(git rev-parse --show-toplevel)
[ -z $BUILD ] && BUILD=Debug ; export BUILD [ -z $BUILD ] && BUILD=Debug ; export BUILD

View File

@ -3,4 +3,3 @@ if config.paths ~= nil then
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
end end
end end
-- print(package.path)

View File

@ -1,11 +1,14 @@
-- Tests that work in all games. With game config of E2. -- 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 -- Tests are under scripts/test/e2 and all files must be in scripts/test/e2/init.lua
lunit = require('lunit')
if _VERSION >= 'Lua 5.2' then
module = lunit.module
end
path = 'scripts' path = 'scripts'
if config.install then if config.install then
path = config.install .. '/' .. path path = config.install .. '/' .. path
package.path = package.path .. ';' .. config.install .. '/lunit/?.lua'
--needed to find lunit if not run from eressea root. Needs right [lua] install setting in eressea.ini (point to eressea root from the start folder)
end end
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
@ -15,7 +18,6 @@ require 'eressea'
require 'eressea.xmlconf' require 'eressea.xmlconf'
require 'eressea.path' require 'eressea.path'
require 'tests.e2' require 'tests.e2'
require 'lunit'
rng.inject(0) rng.inject(0)
eressea.settings.set("rules.food.flags", "4") eressea.settings.set("rules.food.flags", "4")

View File

@ -1,11 +1,14 @@
-- Tests that work in E3. With game config of E3. -- 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 -- Tests are under scripts/test/e3 and all files must be in scripts/test/e3/init.lua
lunit = require('lunit')
if _VERSION >= 'Lua 5.2' then
module = lunit.module
end
path = 'scripts' path = 'scripts'
if config.install then if config.install then
path = config.install .. '/' .. path 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 end
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
@ -15,7 +18,6 @@ require 'eressea'
require 'eressea.path' require 'eressea.path'
require 'eressea.xmlconf' require 'eressea.xmlconf'
require 'tests.e3' require 'tests.e3'
require 'lunit'
rng.inject(0) rng.inject(0)
eressea.settings.set("rules.alliances", "0") eressea.settings.set("rules.alliances", "0")

View File

@ -1,17 +1,19 @@
-- Basic test without loading XML Config. Test care about needed settings. -- 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 -- Tests are under scripts/test/ and all files must be in scripts/test/init.lua
lunit = require('lunit')
if _VERSION >= 'Lua 5.2' then
module = lunit.module
end
path = 'scripts' path = 'scripts'
if config.install then if config.install then
path = config.install .. '/' .. path 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 end
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
require 'eressea' require 'eressea'
require 'eressea.path' require 'eressea.path'
require 'tests' require 'tests'
require 'lunit'
result = lunit.main() result = lunit.main()
return result.errors + result.failed return result.errors + result.failed

View File

@ -1,10 +1,13 @@
require "lunit" local tcname = 'tests.bindings'
local lunit = require('lunit')
if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
local eressea = eressea
local _G = _G local _G = _G
module("tests.bindings", lunit.testcase)
function test_eressea() function test_eressea()
assert_equal("function", _G.type(eressea.free_game)) assert_equal("function", _G.type(eressea.free_game))
assert_equal("function", _G.type(eressea.read_game)) assert_equal("function", _G.type(eressea.read_game))

View File

@ -1,4 +1,10 @@
require "lunit" local tcname = 'tests.shared.common'
local lunit = require('lunit')
if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
local function _test_create_ship(r) local function _test_create_ship(r)
local s = ship.create(r, config.ships[1]) local s = ship.create(r, config.ships[1])
@ -26,8 +32,6 @@ local function two_factions()
return f1, f2 return f1, f2
end end
module("tests.common", package.seeall, lunit.testcase)
function setup() function setup()
eressea.free_game() eressea.free_game()
eressea.settings.set("nmr.timeout", "0") eressea.settings.set("nmr.timeout", "0")
@ -894,307 +898,3 @@ function test_walk_and_carry_the_cart()
process_orders() process_orders()
assert_equal(1, u.region.x) assert_equal(1, u.region.x)
end end
module("tests.recruit", package.seeall, lunit.testcase)
function setup()
eressea.free_game()
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set("rules.peasants.growth", "0")
end
function test_bug_1795_limit()
local r = region.create(0, 0, "plain")
local f = create_faction('human')
local u1 = one_unit(r,f)
u1:add_item("money", 100000000)
u1:add_order("REKRUTIEREN 9999")
r:set_resource("peasant", 2000) -- no fractional growth!
local peasants = r:get_resource("peasant")
local limit,frac = math.modf(peasants/40) -- one day this should be a parameter
process_orders()
assert_equal(limit+1, u1.number, u1.number .. "!=" .. (limit+1))
assert_equal(peasants-limit, r:get_resource("peasant"))
end
function test_bug_1795_demons()
local r = region.create(0, 0, "plain")
local f = create_faction('demon')
local u1 = one_unit(r,f)
r:set_resource("peasant", 2000)
local peasants = r:get_resource("peasant")
local limit,frac = math.modf(peasants/40)
u1:add_item("money", 100000000)
u1:add_order("REKRUTIEREN 9999")
process_orders()
assert_equal(limit+1, u1.number, u1.number .. "!=" .. (limit+1))
assert_equal(peasants, r:get_resource("peasant"))
end
module("tests.parser", package.seeall, lunit.testcase)
function setup()
eressea.free_game()
eressea.settings.set("rules.food.flags", "4") -- FOOD_IS_FREE
eressea.settings.set("rules.move.owner_leave", "0")
end
function test_parser()
local r = region.create(0, 0, "mountain")
local f = create_faction('human')
local u = unit.create(f, r, 1)
local filename = "orders.txt"
local file = io.open(filename, "w")
assert_not_nil(file)
f.password = 'Hodor'
file:write('ERESSEA ' .. itoa36(f.id) .. ' "Hodor"\n')
file:write('EINHEIT ' .. itoa36(u.id) .. "\n")
file:write("BENENNEN EINHEIT 'Goldene Herde'\n")
file:close()
eressea.read_orders(filename)
process_orders()
os.remove(filename)
assert_equal("Goldene Herde", u.name)
end
local function set_order(u, str)
u:clear_orders()
u:add_order(str)
end
function test_prefix()
local r0 = region.create(0, 0, "plain")
local f1 = create_faction('human')
local u1 = unit.create(f1, r0, 1)
set_order(u1, "PRAEFIX See")
process_orders()
assert_not_nil(u1:show():find("Seemensch"))
u1.race = "elf"
assert_not_nil(u1:show():find("Seeelf"))
set_order(u1, "PRAEFIX Mond")
process_orders()
assert_not_nil(u1:show():find("Mondelf"))
set_order(u1, "PRAEFIX")
process_orders()
assert_not_nil(u1:show():find("Elf"))
set_order(u1, "PRAEFIX Erz")
process_orders()
assert_not_nil(u1:show():find("Erzelf"))
u1.faction.locale = "en"
assert_not_nil(u1:show():find("archelf"))
end
function test_recruit()
local r = region.create(0, 0, "plain")
local f = create_faction('human')
local u = unit.create(f, r, 1)
u:add_item("money", 1000)
set_order(u, "REKRUTIERE 5")
process_orders()
for u in f.units do
assert_equal(6, u.number)
end
end
function test_give_horses()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de")
local u = unit.create(f, r, 1)
r:set_resource("horse", 0)
u:add_item("horse", 21)
u:add_item("dolphin", 10)
u:add_order("GIB 0 7 PFERD")
u:add_order("GIB 0 5 DELPHIN")
process_orders()
assert_equal(7, r:get_resource("horse"))
assert_equal(5, u:get_item("dolphin"))
assert_equal(14, u:get_item("horse"))
end
function test_give_silver()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de")
local u = unit.create(f, r, 1)
r:set_resource("peasant", 0)
r:set_resource("money", 11)
u:clear_orders()
u:add_item("money", 20)
u:add_order("GIB 0 10 SILBER")
process_orders()
assert_equal(21, r:get_resource("money"))
assert_equal(10, u:get_item("money"))
end
function test_give_horses()
local r = region.create(0, 0, "plain")
local f = create_faction('human')
local u = unit.create(f, r, 1)
r:set_resource("horse", 0)
u:add_item("horse", 21)
u:add_item("dolphin", 10)
u:add_order("GIB 0 7 PFERD")
u:add_order("GIB 0 5 DELPHIN")
process_orders()
assert_equal(7, r:get_resource("horse"))
assert_equal(5, u:get_item("dolphin"))
assert_equal(14, u:get_item("horse"))
end
function test_give_silver()
local r = region.create(0, 0, "plain")
local f = create_faction('human')
local u = unit.create(f, r, 1)
r:set_resource("peasant", 0)
r:set_resource("money", 11)
u:clear_orders()
u:add_item("money", 20)
u:add_order("GIB 0 10 SILBER")
process_orders()
assert_equal(21, r:get_resource("money"))
assert_equal(10, u:get_item("money"))
end
function test_build_castle_one_stage()
local r = region.create(0, 0, 'plain')
local f = faction.create('human')
local u = unit.create(f, r, 2)
u:add_item('stone', 4)
u:set_skill('building', 1)
u:add_order('MACHE BURG')
process_orders()
assert_equal(2, u.building.size)
assert_equal(2, u:get_item('stone'))
end
function test_build_castle()
local r = region.create(0, 0, "plain")
local f = create_faction('human')
local u = unit.create(f, r, 1)
u:add_item('stone', 1)
u:set_skill('building', 1)
u:add_order("MACHE BURG")
process_orders()
assert_not_nil(u.building)
assert_equal(1, u.building.size)
assert_equal(u.building.name, "Burg")
end
function test_route()
local r1 = region.create(0, 0, "plain")
local r2 = region.create(1, 0, "plain")
local f = faction.create("human", "route@example.com")
local u = unit.create(f, r1, 1)
u:add_order("ROUTE O W P")
process_orders()
assert_equal("ROUTE West PAUSE Ost", u:get_order(0))
assert_equal(r2, u.region)
end
function test_route_horse()
local r1 = region.create(0, 0, "plain")
local r2 = region.create(1, 0, "plain")
local f = faction.create("human", "route@example.com")
local u = unit.create(f, r1, 1)
u:add_order("ROUTE O P W P")
u:add_item('horse', 1)
u:set_skill('riding', 1)
process_orders()
assert_equal("ROUTE West PAUSE Ost PAUSE", u:get_order(0))
assert_equal(r2, u.region)
end
function test_route_pause()
local r1 = region.create(0, 0, "plain")
local r2 = region.create(1, 0, "plain")
local f = faction.create("human", "route@example.com")
local u = unit.create(f, r1, 1)
u:add_order("ROUTE P O W")
process_orders()
assert_equal("ROUTE P O W", u:get_order(0))
assert_equal(r1, u.region)
end
function test_immunity_stops_guard()
eressea.settings.set("NewbieImmunity", 2)
local f = faction.create('human')
local r = region.create(0, 0, 'plain')
local u = unit.create(f, r)
u:set_skill('polearm', 2)
u:add_item('lance', 1)
u:add_order('BEWACHE')
process_orders()
assert_equal(f.age, 1)
assert_true(not u.guard)
process_orders()
assert_equal(f.age, 2)
assert_true(u.guard)
end
function test_region_keys()
local r = region.create(0, 0, 'plain')
assert_nil(r:get_key('test'))
assert_nil(r:get_key('more'))
r:set_key('test', 42)
r:set_key('more') -- default is 1
assert_equal(42, r:get_key('test'))
assert_equal(1, r:get_key('more'))
end
function test_faction_keys()
local f = faction.create('human')
assert_nil(f:get_key('test'))
assert_nil(f:get_key('more'))
f:set_key('test', 42)
f:set_key('more') -- default is 1
assert_equal(42, f:get_key('test'))
assert_equal(1, f:get_key('more'))
end
function test_cartmaking()
local f = faction.create('human')
local r = region.create(0, 0, 'plain')
local u = unit.create(f, r)
u:set_skill('cartmaking', 1)
u:add_item('log', 10)
u:add_order('MACHE Wagen')
process_orders()
assert_equal(1, u:get_item('cart'))
assert_equal(5, u:get_item('log'))
end
function test_promote_after_recruit()
local f = faction.create('human')
local r1 = region.create(0, 0, 'plain')
local r2 = region.create(1, 0, 'plain')
local u1 = unit.create(f, r1, 1)
local u2 = unit.create(f, r2, 55)
u2:add_order('REKRUTIERE 1')
u1:add_order('BEFOERDERE')
u1:add_item('money', 57)
u2:add_item('money', 150)
local fl = u1.flags
process_orders()
assert_equal(56, u2.number)
assert_equal(fl + 128, u1.flags) -- UFL_HERO
assert_equal(0, u1:get_item('money'))
end

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.shared.config'
local lunit = require('lunit')
module("tests.eressea.config", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.adamantium'
local lunit = require('lunit')
module("tests.e2.adamantium", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.allies'
local lunit = require('lunit')
module("tests.e2.allies", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.astral'
local lunit = require('lunit')
module("tests.e2.astral", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()
@ -17,7 +21,7 @@ function test_fetch_astral()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local ra = r:get_astral('fog') local ra = r:get_astral('fog')
local rb = region.create(ra.x + 1, ra.y, 'fog') local rb = region.create(ra.x + 1, ra.y, 'fog')
local f = faction.create("human") local f = faction.create("human");
local u1 = unit.create(f, r, 1) local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1) local u2 = unit.create(f, r, 1)
local u3 = unit.create(f, rb, 1) local u3 = unit.create(f, rb, 1)

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.buildings'
local lunit = require('lunit')
module("tests.e2.buildings", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.carts'
local lunit = require('lunit')
module("tests.e2.carts", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.destroy'
local lunit = require('lunit')
module("tests.e2.destroy", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.features'
local lunit = require('lunit')
module("tests.e2.e2features", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.guard'
local lunit = require('lunit')
module("tests.e2.guard", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -3,7 +3,6 @@ require 'tests.e2.trees'
require 'tests.e2.buildings' require 'tests.e2.buildings'
require 'tests.e2.movement' require 'tests.e2.movement'
require 'tests.e2.carts' require 'tests.e2.carts'
require 'tests.e2.quit'
require 'tests.e2.astral' require 'tests.e2.astral'
require 'tests.e2.spells' require 'tests.e2.spells'
require 'tests.e2.e2features' require 'tests.e2.e2features'
@ -23,6 +22,8 @@ require 'tests.items'
require 'tests.economy' require 'tests.economy'
require 'tests.orders' require 'tests.orders'
require 'tests.common' require 'tests.common'
require 'tests.recruit'
require 'tests.parser'
require 'tests.report' require 'tests.report'
require 'tests.storage' require 'tests.storage'
require 'tests.magicbag' require 'tests.magicbag'
@ -31,3 +32,4 @@ require 'tests.xmas'
require 'tests.production' require 'tests.production'
require 'tests.spells' require 'tests.spells'
require 'tests.undead' require 'tests.undead'

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.insects'
local lunit = require('lunit')
module("tests.e2.insects", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.items'
local lunit = require('lunit')
module("tests.e2.items", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.movement'
local lunit = require('lunit')
module("tests.e2.movement", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.production'
local lunit = require('lunit')
module("tests.e2.production", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.quit'
local lunit = require('lunit')
module("tests.e2.quit", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function test_quit_faction() function test_quit_faction()
local r = region.create(47, 0, "plain") local r = region.create(47, 0, "plain")

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.shiplanding'
local lunit = require('lunit')
module("tests.e2.shiplanding", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.ships'
local lunit = require('lunit')
module("tests.e2.ships", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.spells'
local lunit = require('lunit')
module("tests.e2.spells", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.stealth'
local lunit = require('lunit')
module('tests.e2.stealth', package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
local f local f
local u local u

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.trees'
local lunit = require('lunit')
module("tests.e2.trees", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.trolls'
local lunit = require('lunit')
module("tests.e2.trolls", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e2.undead'
local lunit = require('lunit')
module("tests.e2.undead", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e3.buildings'
local lunit = require('lunit')
module("tests.e3.buildings", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()

View File

@ -10,6 +10,8 @@ require 'tests.spells'
require 'tests.economy' require 'tests.economy'
require 'tests.orders' require 'tests.orders'
require 'tests.common' require 'tests.common'
require 'tests.recruit'
require 'tests.parser'
require 'tests.items' require 'tests.items'
require 'tests.magicbag' require 'tests.magicbag'
require 'tests.process' require 'tests.process'

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e3.items'
local lunit = require('lunit')
module("tests.e3.items", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e3.morale'
local lunit = require('lunit')
module("tests.e3.morale", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()
@ -171,7 +175,7 @@ function test_morale_change()
run_a_turn() run_a_turn()
assert_equal(4, r.morale) assert_equal(4, r.morale)
-- regel: ohne herrscher fällt die moral jede woche um 1 punkt, bis sie 1 erreicht -- regel: ohne herrscher fällt die moral jede woche um 1 punkt, bis sie 1 erreicht
assert_false(r.is_mourning) assert_false(r.is_mourning)
u1.building = nil u1.building = nil
update_owners() update_owners()
@ -186,7 +190,7 @@ function test_morale_change()
run_a_turn() run_a_turn()
assert_equal(1, r.morale) assert_equal(1, r.morale)
-- ohne herrscher ändert sich auch beschissene Moral nicht: -- ohne herrscher ändert sich auch beschissene Moral nicht:
r.morale = 0 r.morale = 0
run_a_turn() run_a_turn()
assert_equal(0, r.morale) assert_equal(0, r.morale)

View File

@ -1,6 +1,10 @@
require 'lunit' local tcname = 'tests.e3.parser'
local lunit = require('lunit')
module('tests.e3.parser', package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e3.production'
local lunit = require('lunit')
module("tests.e3.production", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e3.rules'
local lunit = require('lunit')
module("tests.e3.e3features", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
local settings local settings

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e3.e2spells'
local lunit = require('lunit')
module("tests.e3.spells-e2", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
local r, f, u local r, f, u

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e3.spells'
local lunit = require('lunit')
module("tests.e3.spells", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.e3.stealth'
local lunit = require('lunit')
module("tests.e3.stealth", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
local f local f
local u local u

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.shared.economy'
local lunit = require('lunit')
module("tests.economy", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.faction'
local lunit = require('lunit')
module ('tests.eressea.faction', package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
local f local f

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.hunger'
local lunit = require('lunit')
module("tests.hunger", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.shared.items'
local lunit = require("lunit")
module("tests.items", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.laws'
local lunit = require('lunit')
module("tests.laws", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()
@ -115,3 +119,4 @@ function test_force_leave_postcombat()
assert_equal(nil, u3.building) assert_equal(nil, u3.building)
assert_equal(1, u3.number) assert_equal(1, u3.number)
end end

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.locale'
local lunit = require('lunit')
module("tests.eressea.locale", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.shared.magicbag'
local lunit = require('lunit')
module("tests.magicbag", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
local u local u

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.movement'
local lunit = require("lunit")
module("tests.movement", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname , 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,12 +1,14 @@
require "lunit" local tcname = 'tests.shared.orders'
local lunit = require("lunit")
if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname , 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
local _G = _G local _G = _G
local eressea = eressea
local default_ship = config.ships[1] local default_ship = config.ships[1]
local default_building = config.buildings[1] local default_building = config.buildings[1]
module('tests.eressea.orders', package.seeall, lunit.testcase)
local r, f, u local r, f, u
function setup() function setup()

270
scripts/tests/parser.lua Normal file
View File

@ -0,0 +1,270 @@
local tcname = 'tests.shared.parser'
local lunit = require('lunit')
if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup()
eressea.free_game()
eressea.settings.set("rules.food.flags", "4") -- FOOD_IS_FREE
eressea.settings.set("rules.move.owner_leave", "0")
end
function test_parser()
local r = region.create(0, 0, "mountain")
local f = faction.create('human')
local u = unit.create(f, r, 1)
local filename = "orders.txt"
local file = io.open(filename, "w")
assert_not_nil(file)
f.password = 'Hodor'
file:write('ERESSEA ' .. itoa36(f.id) .. ' "Hodor"\n')
file:write('EINHEIT ' .. itoa36(u.id) .. "\n")
file:write("BENENNEN EINHEIT 'Goldene Herde'\n")
file:close()
eressea.read_orders(filename)
process_orders()
os.remove(filename)
assert_equal("Goldene Herde", u.name)
end
local function set_order(u, str)
u:clear_orders()
u:add_order(str)
end
function test_prefix()
local r0 = region.create(0, 0, "plain")
local f1 = faction.create('human')
local u1 = unit.create(f1, r0, 1)
set_order(u1, "PRAEFIX See")
process_orders()
assert_not_nil(u1:show():find("Seemensch"))
u1.race = "elf"
assert_not_nil(u1:show():find("Seeelf"))
set_order(u1, "PRAEFIX Mond")
process_orders()
assert_not_nil(u1:show():find("Mondelf"))
set_order(u1, "PRAEFIX")
process_orders()
assert_not_nil(u1:show():find("Elf"))
set_order(u1, "PRAEFIX Erz")
process_orders()
assert_not_nil(u1:show():find("Erzelf"))
u1.faction.locale = "en"
assert_not_nil(u1:show():find("archelf"))
end
function test_recruit()
local r = region.create(0, 0, "plain")
local f = faction.create('human')
local u = unit.create(f, r, 1)
u:add_item("money", 1000)
set_order(u, "REKRUTIERE 5")
process_orders()
for u in f.units do
assert_equal(6, u.number)
end
end
function test_give_horses()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de")
local u = unit.create(f, r, 1)
r:set_resource("horse", 0)
u:add_item("horse", 21)
u:add_item("dolphin", 10)
u:add_order("GIB 0 7 PFERD")
u:add_order("GIB 0 5 DELPHIN")
process_orders()
assert_equal(7, r:get_resource("horse"))
assert_equal(5, u:get_item("dolphin"))
assert_equal(14, u:get_item("horse"))
end
function test_give_silver()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de")
local u = unit.create(f, r, 1)
r:set_resource("peasant", 0)
r:set_resource("money", 11)
u:clear_orders()
u:add_item("money", 20)
u:add_order("GIB 0 10 SILBER")
process_orders()
assert_equal(21, r:get_resource("money"))
assert_equal(10, u:get_item("money"))
end
function test_give_horses()
local r = region.create(0, 0, "plain")
local f = faction.create('human')
local u = unit.create(f, r, 1)
r:set_resource("horse", 0)
u:add_item("horse", 21)
u:add_item("dolphin", 10)
u:add_order("GIB 0 7 PFERD")
u:add_order("GIB 0 5 DELPHIN")
process_orders()
assert_equal(7, r:get_resource("horse"))
assert_equal(5, u:get_item("dolphin"))
assert_equal(14, u:get_item("horse"))
end
function test_give_silver()
local r = region.create(0, 0, "plain")
local f = faction.create('human')
local u = unit.create(f, r, 1)
r:set_resource("peasant", 0)
r:set_resource("money", 11)
u:clear_orders()
u:add_item("money", 20)
u:add_order("GIB 0 10 SILBER")
process_orders()
assert_equal(21, r:get_resource("money"))
assert_equal(10, u:get_item("money"))
end
function test_build_castle_one_stage()
local r = region.create(0, 0, 'plain')
local f = faction.create('human')
local u = unit.create(f, r, 2)
u:add_item('stone', 4)
u:set_skill('building', 1)
u:add_order('MACHE BURG')
process_orders()
assert_equal(2, u.building.size)
assert_equal(2, u:get_item('stone'))
end
function test_build_castle()
local r = region.create(0, 0, "plain")
local f = faction.create('human')
local u = unit.create(f, r, 1)
u:add_item('stone', 1)
u:set_skill('building', 1)
u:add_order("MACHE BURG")
process_orders()
assert_not_nil(u.building)
assert_equal(1, u.building.size)
assert_equal(u.building.name, "Burg")
end
function test_route()
local r1 = region.create(0, 0, "plain")
local r2 = region.create(1, 0, "plain")
local f = faction.create("human", "route@example.com")
local u = unit.create(f, r1, 1)
u:add_order("ROUTE O W P")
process_orders()
assert_equal("ROUTE West PAUSE Ost", u:get_order(0))
assert_equal(r2, u.region)
end
function test_route_horse()
local r1 = region.create(0, 0, "plain")
local r2 = region.create(1, 0, "plain")
local f = faction.create("human", "route@example.com")
local u = unit.create(f, r1, 1)
u:add_order("ROUTE O P W P")
u:add_item('horse', 1)
u:set_skill('riding', 1)
process_orders()
assert_equal("ROUTE West PAUSE Ost PAUSE", u:get_order(0))
assert_equal(r2, u.region)
end
function test_route_pause()
local r1 = region.create(0, 0, "plain")
local r2 = region.create(1, 0, "plain")
local f = faction.create("human", "route@example.com")
local u = unit.create(f, r1, 1)
u:add_order("ROUTE P O W")
process_orders()
assert_equal("ROUTE P O W", u:get_order(0))
assert_equal(r1, u.region)
end
function test_immunity_stops_guard()
eressea.settings.set("NewbieImmunity", 2)
local f = faction.create('human')
local r = region.create(0, 0, 'plain')
local u = unit.create(f, r)
u:set_skill('polearm', 2)
u:add_item('lance', 1)
u:add_order('BEWACHE')
process_orders()
assert_equal(f.age, 1)
assert_true(not u.guard)
process_orders()
assert_equal(f.age, 2)
assert_true(u.guard)
end
function test_region_keys()
local r = region.create(0, 0, 'plain')
assert_nil(r:get_key('test'))
assert_nil(r:get_key('more'))
r:set_key('test', 42)
r:set_key('more') -- default is 1
assert_equal(42, r:get_key('test'))
assert_equal(1, r:get_key('more'))
end
function test_faction_keys()
local f = faction.create('human')
assert_nil(f:get_key('test'))
assert_nil(f:get_key('more'))
f:set_key('test', 42)
f:set_key('more') -- default is 1
assert_equal(42, f:get_key('test'))
assert_equal(1, f:get_key('more'))
end
function test_cartmaking()
local f = faction.create('human')
local r = region.create(0, 0, 'plain')
local u = unit.create(f, r)
u:set_skill('cartmaking', 1)
u:add_item('log', 10)
u:add_order('MACHE Wagen')
process_orders()
assert_equal(1, u:get_item('cart'))
assert_equal(5, u:get_item('log'))
end
function test_promote_after_recruit()
local f = faction.create('human')
local r1 = region.create(0, 0, 'plain')
local r2 = region.create(1, 0, 'plain')
local u1 = unit.create(f, r1, 1)
u1.name = 'Xolgrim'
local u2 = unit.create(f, r2, 55)
u2:add_order('REKRUTIERE 1')
u1:add_order('BEFOERDERE')
u1:add_item('money', 57)
u2:add_item('money', 150)
local fl = u1.flags
process_orders()
assert_equal(56, u2.number)
assert_equal(fl + 128, u1.flags) -- UFL_HERO
assert_equal(0, u1:get_item('money'))
end

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.pool'
local lunit = require('lunit')
module("tests.eressea.pool", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.shared.process'
local lunit = require('lunit')
module("tests.process", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
local u, r, f local u, r, f

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.shared.production'
local lunit = require('lunit')
module("tests.production", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()

46
scripts/tests/recruit.lua Normal file
View File

@ -0,0 +1,46 @@
local tcname = 'tests.shared.recruit'
local lunit = require('lunit')
if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup()
eressea.free_game()
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set("rules.peasants.growth", "0")
end
function test_bug_1795_limit()
local r = region.create(0, 0, "plain")
local f = faction.create('human')
local u1 = unit.create(f, r, 1)
u1:add_item("money", 100000000)
u1:add_order("REKRUTIEREN 9999")
r:set_resource("peasant", 2000) -- no fractional growth!
local peasants = r:get_resource("peasant")
local limit,frac = math.modf(peasants/40) -- one day this should be a parameter
process_orders()
assert_equal(limit+1, u1.number, u1.number .. "!=" .. (limit+1))
local np = r:get_resource("peasant")
assert_equal(peasants-limit, np)
end
function test_bug_1795_demons()
local r = region.create(0, 0, "plain")
local f = faction.create('demon')
local u1 = unit.create(f, r, 1)
r:set_resource("peasant", 2000)
local peasants = r:get_resource("peasant")
local limit,frac = math.modf(peasants/40)
u1:add_item("money", 100000000)
u1:add_order("REKRUTIEREN 9999")
process_orders()
assert_equal(limit+1, u1.number, u1.number .. "!=" .. (limit+1))
assert_equal(peasants, r:get_resource("peasant"))
end

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.regions'
local lunit = require('lunit')
module("tests.regions", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.game.reset() eressea.game.reset()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.shared.report'
local lunit = require('lunit')
module("tests.report", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require 'lunit' local tcname = 'tests.settings'
local lunit = require('lunit')
module('tests.eressea.settings', package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,5 +1,10 @@
require 'lunit' local tcname = 'tests.shared.spells'
module("tests.spells", package.seeall, lunit.testcase) local lunit = require('lunit')
if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.shared.storage'
local lunit = require('lunit')
module("tests.storage", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.study'
local lunit = require('lunit')
module("tests.eressea.study", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
conf = [[{ conf = [[{

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.shared.undead'
local lunit = require('lunit')
module("tests.undead", package.seeall, lunit.testcase) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -1,6 +1,10 @@
require "lunit" local tcname = 'tests.shared.xmas'
local lunit = require('lunit')
module("tests.xmas", package.seeall, lunit.testcase ) if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, lunit.testcase, package.seeall)
end
function setup() function setup()
eressea.free_game() eressea.free_game()

View File

@ -684,7 +684,7 @@ growing_trees(region * r, const season_t current_season, const season_t last_wee
a->data.sa[0] = (short)cap_int(rtrees(r, 0), 0, SHRT_MAX); a->data.sa[0] = (short)cap_int(rtrees(r, 0), 0, SHRT_MAX);
a->data.sa[1] = (short)cap_int(rtrees(r, 1), 0, SHRT_MAX); a->data.sa[1] = (short)cap_int(rtrees(r, 1), 0, SHRT_MAX);
} }
else if (a->data.sa[0] < 0 || a->data.sa[1] << 0) { else if (a->data.sa[0] < 0 || a->data.sa[1] < 0) {
a->data.sa[0] = (short)cap_int(a->data.sa[0], 0, SHRT_MAX); a->data.sa[0] = (short)cap_int(a->data.sa[0], 0, SHRT_MAX);
a->data.sa[1] = (short)cap_int(a->data.sa[1], 0, SHRT_MAX); a->data.sa[1] = (short)cap_int(a->data.sa[1], 0, SHRT_MAX);
} }