From ef6fa16496df82cc379f7edc1b451da7fa9fe8f2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 19 Apr 2020 21:35:48 +0200 Subject: [PATCH 01/26] convert to lua 5.3 --- .gitmodules | 3 --- CMakeLists.txt | 2 ++ lunit | 1 - s/cmake-init | 4 ++++ s/runtests | 1 + scripts/run-tests-e2.lua | 4 ++-- scripts/run-tests-e3.lua | 5 +++-- scripts/run-tests.lua | 5 +++-- scripts/tests/bindings.lua | 11 +++++++---- scripts/tests/common.lua | 10 +++++++--- scripts/tests/config.lua | 10 +++++++--- scripts/tests/e2/adamantium.lua | 10 +++++++--- scripts/tests/e2/allies.lua | 10 +++++++--- scripts/tests/e2/astral.lua | 12 ++++++++---- scripts/tests/e2/buildings.lua | 10 +++++++--- scripts/tests/e2/carts.lua | 10 +++++++--- scripts/tests/e2/destroy.lua | 10 +++++++--- scripts/tests/e2/e2features.lua | 10 +++++++--- scripts/tests/e2/guard.lua | 10 +++++++--- scripts/tests/e2/init.lua | 1 - scripts/tests/e2/insects.lua | 10 +++++++--- scripts/tests/e2/items.lua | 10 +++++++--- scripts/tests/e2/movement.lua | 10 +++++++--- scripts/tests/e2/production.lua | 10 +++++++--- scripts/tests/e2/quit.lua | 10 +++++++--- scripts/tests/e2/shiplanding.lua | 10 +++++++--- scripts/tests/e2/ships.lua | 10 +++++++--- scripts/tests/e2/spells.lua | 10 +++++++--- scripts/tests/e2/stealth.lua | 10 +++++++--- scripts/tests/e2/undead.lua | 10 +++++++--- scripts/tests/economy.lua | 10 +++++++--- scripts/tests/faction.lua | 9 ++++++--- scripts/tests/hunger.lua | 10 +++++++--- scripts/tests/items.lua | 10 +++++++--- scripts/tests/laws.lua | 10 +++++++--- scripts/tests/locale.lua | 9 ++++++--- scripts/tests/magicbag.lua | 10 +++++++--- scripts/tests/movement.lua | 9 ++++++--- scripts/tests/orders.lua | 12 +++++++----- scripts/tests/pool.lua | 9 ++++++--- scripts/tests/process.lua | 10 +++++++--- scripts/tests/production.lua | 10 +++++++--- scripts/tests/regions.lua | 10 +++++++--- scripts/tests/report.lua | 10 +++++++--- scripts/tests/settings.lua | 10 +++++++--- scripts/tests/spells.lua | 9 +++++++-- scripts/tests/storage.lua | 10 +++++++--- scripts/tests/study.lua | 10 +++++++--- scripts/tests/undead.lua | 10 +++++++--- scripts/tests/xmas.lua | 10 +++++++--- 50 files changed, 299 insertions(+), 137 deletions(-) delete mode 160000 lunit diff --git a/.gitmodules b/.gitmodules index 4d903c57f..f76a3af9c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "lunit"] - path = lunit - url = https://github.com/ennorehling/lunit.git [submodule "dlmalloc"] path = dlmalloc url = https://github.com/ennorehling/dlmalloc.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d2635f05..e8c4893d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,8 @@ find_package (ToLua REQUIRED) if (TOLUA_FOUND) if (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.2") find_package (Lua 5.2 REQUIRED) +elseif (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.3") +find_package ( Lua 5.3 REQUIRED) else () find_package (Lua51 REQUIRED) endif() diff --git a/lunit b/lunit deleted file mode 160000 index 155c96594..000000000 --- a/lunit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 155c96594435413b4f704eb17558ea0b70631bad diff --git a/s/cmake-init b/s/cmake-init index eea222334..da747e3ec 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -82,6 +82,10 @@ LUA_DIR=/usr if [ -d /usr/include/lua5.1 ]; then LUA_VERSION="5.1" LUA_INCLUDE=/usr/include/lua5.1 +elif [ -d /usr/include/lua5.3 ]; then + export LUA_DIR=/usr + LUA_VERSION="5.3" + LUA_INCLUDE=/usr/include/lua5.3 elif [ -d /usr/include/lua5.2 ]; then export LUA_DIR=/usr LUA_VERSION="5.2" diff --git a/s/runtests b/s/runtests index b74a4b785..2c8049098 100755 --- a/s/runtests +++ b/s/runtests @@ -1,6 +1,7 @@ #!/bin/bash set -e +eval $(luarocks path) ROOT=$(git rev-parse --show-toplevel) [ -z $BUILD ] && BUILD=Debug ; export BUILD diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua index b5f18c7f7..a421904f6 100644 --- a/scripts/run-tests-e2.lua +++ b/scripts/run-tests-e2.lua @@ -1,10 +1,11 @@ -- 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 +lunit = require('lunit') +module = lunit.module path = 'scripts' if config.install then 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 package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' @@ -15,7 +16,6 @@ require 'eressea' require 'eressea.xmlconf' require 'eressea.path' require 'tests.e2' -require 'lunit' rng.inject(0) eressea.settings.set("rules.food.flags", "4") diff --git a/scripts/run-tests-e3.lua b/scripts/run-tests-e3.lua index 3332df306..f50ac71eb 100644 --- a/scripts/run-tests-e3.lua +++ b/scripts/run-tests-e3.lua @@ -1,10 +1,12 @@ -- 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 +lunit = require('lunit') +module = lunit.module + path = 'scripts' if config.install then 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 package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' @@ -15,7 +17,6 @@ require 'eressea' require 'eressea.path' require 'eressea.xmlconf' require 'tests.e3' -require 'lunit' rng.inject(0) eressea.settings.set("rules.alliances", "0") diff --git a/scripts/run-tests.lua b/scripts/run-tests.lua index d1306ddcd..5a7bcb9ad 100644 --- a/scripts/run-tests.lua +++ b/scripts/run-tests.lua @@ -4,14 +4,15 @@ path = 'scripts' if config.install then 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 package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' require 'eressea' require 'eressea.path' + +lunit = require('lunit') +module = lunit.module require 'tests' -require 'lunit' result = lunit.main() return result.errors + result.failed diff --git a/scripts/tests/bindings.lua b/scripts/tests/bindings.lua index 5820e0a47..4e308de99 100644 --- a/scripts/tests/bindings.lua +++ b/scripts/tests/bindings.lua @@ -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, 'seeall') +end -local eressea = eressea local _G = _G -module("tests.bindings", lunit.testcase) - function test_eressea() assert_equal("function", _G.type(eressea.free_game)) assert_equal("function", _G.type(eressea.read_game)) diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 96069d4a5..ca09fe6c9 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -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, 'seeall') +end local function _test_create_ship(r) local s = ship.create(r, config.ships[1]) @@ -26,8 +32,6 @@ local function two_factions() return f1, f2 end -module("tests.common", package.seeall, lunit.testcase) - function setup() eressea.free_game() eressea.settings.set("nmr.timeout", "0") diff --git a/scripts/tests/config.lua b/scripts/tests/config.lua index 733a8ee07..cdf93ed2c 100644 --- a/scripts/tests/config.lua +++ b/scripts/tests/config.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.eressea.config", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.config' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/adamantium.lua b/scripts/tests/e2/adamantium.lua index a893d32d5..0a0c2ec6b 100644 --- a/scripts/tests/e2/adamantium.lua +++ b/scripts/tests/e2/adamantium.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.adamantium", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.adamantium' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/allies.lua b/scripts/tests/e2/allies.lua index ef38a97bf..a5177944f 100644 --- a/scripts/tests/e2/allies.lua +++ b/scripts/tests/e2/allies.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.allies", package.seeall, lunit.testcase) +local tcname = 'tests.e2.allies' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function skip_test_get_set_ally() local f1 = faction.create("human") diff --git a/scripts/tests/e2/astral.lua b/scripts/tests/e2/astral.lua index 5c4461921..c183c6207 100644 --- a/scripts/tests/e2/astral.lua +++ b/scripts/tests/e2/astral.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.astral", package.seeall, lunit.testcase) +local tcname = 'tests.e2.astral' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() @@ -17,7 +21,7 @@ function test_fetch_astral() local r = region.create(0, 0, "plain") local ra = r:get_astral('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 u2 = unit.create(f, r, 1) local u3 = unit.create(f, rb, 1) diff --git a/scripts/tests/e2/buildings.lua b/scripts/tests/e2/buildings.lua index 845c4ba7d..7eb3b41c8 100644 --- a/scripts/tests/e2/buildings.lua +++ b/scripts/tests/e2/buildings.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.buildings", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.buildings' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/carts.lua b/scripts/tests/e2/carts.lua index 025b473df..f649451e2 100644 --- a/scripts/tests/e2/carts.lua +++ b/scripts/tests/e2/carts.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.carts", package.seeall, lunit.testcase) +local tcname = 'tests.e2.carts' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/destroy.lua b/scripts/tests/e2/destroy.lua index 430ca301c..1813c108b 100644 --- a/scripts/tests/e2/destroy.lua +++ b/scripts/tests/e2/destroy.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.destroy", package.seeall, lunit.testcase) +local tcname = 'tests.e2.destroy' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index b0233c3fb..a9ba6ed51 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.e2features", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.features' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/guard.lua b/scripts/tests/e2/guard.lua index e3cf8075f..fd7f37ad0 100644 --- a/scripts/tests/e2/guard.lua +++ b/scripts/tests/e2/guard.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.guard", package.seeall, lunit.testcase) +local tcname = 'tests.e2.guard' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 3bd09bafc..095d2bcf0 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -3,7 +3,6 @@ require 'tests.e2.allies' require 'tests.e2.quit' require 'tests.e2.movement' require 'tests.e2.carts' -require 'tests.e2.quit' require 'tests.e2.astral' require 'tests.e2.spells' require 'tests.e2.e2features' diff --git a/scripts/tests/e2/insects.lua b/scripts/tests/e2/insects.lua index f5b8a3213..296c67e82 100644 --- a/scripts/tests/e2/insects.lua +++ b/scripts/tests/e2/insects.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.insects", package.seeall, lunit.testcase) +local tcname = 'tests.e2.insects' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/items.lua b/scripts/tests/e2/items.lua index 2492a7fdb..9221d424b 100644 --- a/scripts/tests/e2/items.lua +++ b/scripts/tests/e2/items.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.items", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.items' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/movement.lua b/scripts/tests/e2/movement.lua index aa42857f3..db9f4fbdd 100644 --- a/scripts/tests/e2/movement.lua +++ b/scripts/tests/e2/movement.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.movement", package.seeall, lunit.testcase) +local tcname = 'tests.e2.movement' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/production.lua b/scripts/tests/e2/production.lua index 80d3447d2..7941c1af4 100644 --- a/scripts/tests/e2/production.lua +++ b/scripts/tests/e2/production.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.production", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.production' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/quit.lua b/scripts/tests/e2/quit.lua index 7db59091b..9d02c49eb 100644 --- a/scripts/tests/e2/quit.lua +++ b/scripts/tests/e2/quit.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.quit", package.seeall, lunit.testcase) +local tcname = 'tests.e2.quit' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function test_quit_faction() local r = region.create(47, 0, "plain") diff --git a/scripts/tests/e2/shiplanding.lua b/scripts/tests/e2/shiplanding.lua index 2258a1992..7b146f2e6 100644 --- a/scripts/tests/e2/shiplanding.lua +++ b/scripts/tests/e2/shiplanding.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.shiplanding", package.seeall, lunit.testcase) +local tcname = 'tests.e2.shiplanding' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/ships.lua b/scripts/tests/e2/ships.lua index 5b77220ec..2f5db607d 100644 --- a/scripts/tests/e2/ships.lua +++ b/scripts/tests/e2/ships.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.ships", package.seeall, lunit.testcase) +local tcname = 'tests.e2.ships' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/spells.lua b/scripts/tests/e2/spells.lua index de2386113..39a867507 100644 --- a/scripts/tests/e2/spells.lua +++ b/scripts/tests/e2/spells.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.spells", package.seeall, lunit.testcase) +local tcname = 'tests.e2.spells' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/stealth.lua b/scripts/tests/e2/stealth.lua index 7f531776c..60b66e83f 100644 --- a/scripts/tests/e2/stealth.lua +++ b/scripts/tests/e2/stealth.lua @@ -1,6 +1,10 @@ -require "lunit" - -module('tests.e2.stealth', package.seeall, lunit.testcase) +local tcname = 'tests.e2.stealth' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local f local u diff --git a/scripts/tests/e2/undead.lua b/scripts/tests/e2/undead.lua index f7586ee4b..8e072e489 100644 --- a/scripts/tests/e2/undead.lua +++ b/scripts/tests/e2/undead.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.undead", package.seeall, lunit.testcase) +local tcname = 'tests.e2.undead' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/economy.lua b/scripts/tests/economy.lua index 0c140e418..17dcbfc61 100644 --- a/scripts/tests/economy.lua +++ b/scripts/tests/economy.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.economy", package.seeall, lunit.testcase) +local tcname = 'tests.shared.economy' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index c264f4596..7247498ea 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -1,6 +1,9 @@ -require "lunit" - -module ('tests.eressea.faction', package.seeall, lunit.testcase) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.faction", 'seeall') +else + module("tests.faction", 'seeall') +end local f diff --git a/scripts/tests/hunger.lua b/scripts/tests/hunger.lua index a33c2208b..fed24440e 100644 --- a/scripts/tests/hunger.lua +++ b/scripts/tests/hunger.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.hunger", package.seeall, lunit.testcase) +local tcname = 'tests.hunger' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/items.lua b/scripts/tests/items.lua index f4d8657c6..e1e780f3c 100644 --- a/scripts/tests/items.lua +++ b/scripts/tests/items.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.items", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.items' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/laws.lua b/scripts/tests/laws.lua index 6dc37daf7..e22bc5d8f 100644 --- a/scripts/tests/laws.lua +++ b/scripts/tests/laws.lua @@ -1,6 +1,9 @@ -require "lunit" - -module("tests.laws", package.seeall, lunit.testcase) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.laws", 'seeall') +else + module("tests.laws", 'seeall') +end function setup() eressea.free_game() @@ -115,3 +118,4 @@ function test_force_leave_postcombat() assert_equal(nil, u3.building) assert_equal(1, u3.number) end + diff --git a/scripts/tests/locale.lua b/scripts/tests/locale.lua index 2770beb3f..d1d35ded3 100644 --- a/scripts/tests/locale.lua +++ b/scripts/tests/locale.lua @@ -1,6 +1,9 @@ -require "lunit" - -module("tests.eressea.locale", package.seeall, lunit.testcase ) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.locale", 'seeall') +else + module("tests.locale", 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/magicbag.lua b/scripts/tests/magicbag.lua index b51925726..7e4629707 100644 --- a/scripts/tests/magicbag.lua +++ b/scripts/tests/magicbag.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.magicbag", package.seeall, lunit.testcase) +local tcname = 'tests.shared.magicbag' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local u diff --git a/scripts/tests/movement.lua b/scripts/tests/movement.lua index 22bd8d30e..943e912a8 100644 --- a/scripts/tests/movement.lua +++ b/scripts/tests/movement.lua @@ -1,6 +1,9 @@ -require "lunit" - -module("tests.movement", package.seeall, lunit.testcase) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.movement", 'seeall') +else + module("tests.movement", 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/orders.lua b/scripts/tests/orders.lua index 6dc191d6c..c63254315 100644 --- a/scripts/tests/orders.lua +++ b/scripts/tests/orders.lua @@ -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, 'seeall') +end local _G = _G -local eressea = eressea local default_ship = config.ships[1] local default_building = config.buildings[1] - -module('tests.eressea.orders', package.seeall, lunit.testcase) - local r, f, u function setup() diff --git a/scripts/tests/pool.lua b/scripts/tests/pool.lua index 0d24f8129..06f212f60 100644 --- a/scripts/tests/pool.lua +++ b/scripts/tests/pool.lua @@ -1,6 +1,9 @@ -require "lunit" - -module("tests.eressea.pool", package.seeall, lunit.testcase ) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.pool", 'seeall') +else + module("tests.pool", 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/process.lua b/scripts/tests/process.lua index 1fc9a64f5..0b9b3e35b 100644 --- a/scripts/tests/process.lua +++ b/scripts/tests/process.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.process", package.seeall, lunit.testcase) +local tcname = 'tests.shared.process' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local u, r, f diff --git a/scripts/tests/production.lua b/scripts/tests/production.lua index c8a299676..b127fff02 100644 --- a/scripts/tests/production.lua +++ b/scripts/tests/production.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.production", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.production' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/regions.lua b/scripts/tests/regions.lua index 32197f0fd..e16dd1691 100644 --- a/scripts/tests/regions.lua +++ b/scripts/tests/regions.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.regions", package.seeall, lunit.testcase) +local tcname = 'tests.regions' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/report.lua b/scripts/tests/report.lua index b02f4a908..66eaa7d89 100644 --- a/scripts/tests/report.lua +++ b/scripts/tests/report.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.report", package.seeall, lunit.testcase) +local tcname = 'tests.shared.report' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/settings.lua b/scripts/tests/settings.lua index 8f2c5e637..f321a515b 100644 --- a/scripts/tests/settings.lua +++ b/scripts/tests/settings.lua @@ -1,6 +1,10 @@ -require 'lunit' - -module('tests.eressea.settings', package.seeall, lunit.testcase ) +local tcname = 'tests.settings' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/spells.lua b/scripts/tests/spells.lua index 27a5424f7..767df5d16 100644 --- a/scripts/tests/spells.lua +++ b/scripts/tests/spells.lua @@ -1,5 +1,10 @@ -require 'lunit' -module("tests.spells", package.seeall, lunit.testcase) +local tcname = 'tests.shared.spells' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/storage.lua b/scripts/tests/storage.lua index 32fbe9ef3..22af5a221 100644 --- a/scripts/tests/storage.lua +++ b/scripts/tests/storage.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.storage", package.seeall, lunit.testcase) +local tcname = 'tests.shared.storage' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/study.lua b/scripts/tests/study.lua index 32638ba90..21c70044e 100644 --- a/scripts/tests/study.lua +++ b/scripts/tests/study.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.eressea.study", package.seeall, lunit.testcase) +local tcname = 'tests.study' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() conf = [[{ diff --git a/scripts/tests/undead.lua b/scripts/tests/undead.lua index a3c541afa..4cb86fc67 100644 --- a/scripts/tests/undead.lua +++ b/scripts/tests/undead.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.undead", package.seeall, lunit.testcase) +local tcname = 'tests.shared.undead' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/xmas.lua b/scripts/tests/xmas.lua index 8ae85fc76..10386c0ed 100644 --- a/scripts/tests/xmas.lua +++ b/scripts/tests/xmas.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.xmas", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.xmas' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() From f5d352b68054059099530606e5078e19cc8164bc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Apr 2020 20:58:52 +0200 Subject: [PATCH 02/26] use luarocks --- .travis.yml | 1 + clibs | 2 +- s/build | 2 +- s/cmake-init | 3 +-- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index d7a014d89..b702efaab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ addons: - valgrind - cppcheck - shellcheck + - luarocks os: - linux notifications: diff --git a/clibs b/clibs index abe774f70..484fbf23e 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit abe774f70265de14ea7f5e530518ca130562a9c9 +Subproject commit 484fbf23e34f6844f1c4e3f685bb6c53cadf5bfe diff --git a/s/build b/s/build index 709c92510..e54f83ace 100755 --- a/s/build +++ b/s/build @@ -1,6 +1,6 @@ #!/bin/sh ROOT=$(git rev-parse --show-toplevel) - +eval $(luarocks path) [ -z "$BUILD" ] && BUILD=Debug if [ -z "$JOBS" ] ; then if [ -e /usr/sbin/sysctl ]; then diff --git a/s/cmake-init b/s/cmake-init index da747e3ec..916d3ae39 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -6,6 +6,7 @@ pkg-config --exists sqlite3 && ERESSEA_DB=sqlite GETOPT=getopt GETOPT_LONG=1 +luarocks install lunitx --local if [ "Darwin" = "$(uname)" ] ; then if [ -x "/usr/local/opt/gnu-getopt/bin/getopt" ] ; then GETOPT="/usr/local/opt/gnu-getopt/bin/getopt" @@ -74,8 +75,6 @@ fi DEST=$(dirname $ROOT)/server -git submodule update --init - LUA_VERSION="5.2" LUA_INCLUDE=/usr/include LUA_DIR=/usr From a977e853b401ed6a598e4b0835e8bfb251910374 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Apr 2020 22:34:12 +0200 Subject: [PATCH 03/26] es wird immer der erste lange Befehl ausgefuehrt. --- scripts/tests/e2/destroy.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/e2/destroy.lua b/scripts/tests/e2/destroy.lua index 430ca301c..db6f09c2a 100644 --- a/scripts/tests/e2/destroy.lua +++ b/scripts/tests/e2/destroy.lua @@ -41,8 +41,8 @@ function test_destroy_is_long() local u = unit.create(faction.create("human", "one@example.com", "de"), r1, 10) u.building = building.create(u.region, "castle") u:clear_orders() - u:add_order("LERNE Unterhaltung") u:add_order("ZERSTOERE " .. itoa36(u.building.id)) + u:add_order("LERNE Unterhaltung") process_orders() assert_equal(0, u:get_skill("entertainment")) assert_equal(nil, u.building) From 5fb87570471364149ae834ee78c26fb1e1ec52c9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 22 Apr 2020 03:03:44 +0200 Subject: [PATCH 04/26] make all test modules work with lunitx --- scripts/tests/common.lua | 304 -------------------------------- scripts/tests/e2/init.lua | 2 + scripts/tests/e3/buildings.lua | 10 +- scripts/tests/e3/init.lua | 2 + scripts/tests/e3/items.lua | 10 +- scripts/tests/e3/morale.lua | 14 +- scripts/tests/e3/parser.lua | 10 +- scripts/tests/e3/production.lua | 10 +- scripts/tests/e3/rules.lua | 10 +- scripts/tests/e3/spells-e2.lua | 10 +- scripts/tests/e3/spells.lua | 10 +- scripts/tests/e3/stealth.lua | 10 +- scripts/tests/parser.lua | 270 ++++++++++++++++++++++++++++ scripts/tests/recruit.lua | 46 +++++ 14 files changed, 385 insertions(+), 333 deletions(-) create mode 100644 scripts/tests/parser.lua create mode 100644 scripts/tests/recruit.lua diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index ca09fe6c9..0c0fed3c9 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -899,307 +899,3 @@ function test_walk_and_carry_the_cart() assert_equal(1, u.region.x) 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) - 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 diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 095d2bcf0..0226ab11e 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -21,6 +21,8 @@ require 'tests.items' require 'tests.economy' require 'tests.orders' require 'tests.common' +require 'tests.recruit' +require 'tests.parser' require 'tests.report' require 'tests.storage' require 'tests.magicbag' diff --git a/scripts/tests/e3/buildings.lua b/scripts/tests/e3/buildings.lua index d5ea4fa51..fa9f5d16f 100644 --- a/scripts/tests/e3/buildings.lua +++ b/scripts/tests/e3/buildings.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.buildings", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.buildings' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/init.lua b/scripts/tests/e3/init.lua index 04b7da4a2..2ccd19139 100644 --- a/scripts/tests/e3/init.lua +++ b/scripts/tests/e3/init.lua @@ -10,6 +10,8 @@ require 'tests.spells' require 'tests.economy' require 'tests.orders' require 'tests.common' +require 'tests.recruit' +require 'tests.parser' require 'tests.items' require 'tests.magicbag' require 'tests.process' diff --git a/scripts/tests/e3/items.lua b/scripts/tests/e3/items.lua index 1df6be85a..1036f6ca4 100644 --- a/scripts/tests/e3/items.lua +++ b/scripts/tests/e3/items.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.items", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.items' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/morale.lua b/scripts/tests/e3/morale.lua index 1dd92a758..898e08674 100644 --- a/scripts/tests/e3/morale.lua +++ b/scripts/tests/e3/morale.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.morale", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.morale' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() @@ -171,7 +175,7 @@ function test_morale_change() run_a_turn() 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) u1.building = nil update_owners() @@ -186,7 +190,7 @@ function test_morale_change() run_a_turn() assert_equal(1, r.morale) - -- ohne herrscher ändert sich auch beschissene Moral nicht: + -- ohne herrscher ändert sich auch beschissene Moral nicht: r.morale = 0 run_a_turn() assert_equal(0, r.morale) diff --git a/scripts/tests/e3/parser.lua b/scripts/tests/e3/parser.lua index a56f08f76..52a082bf1 100644 --- a/scripts/tests/e3/parser.lua +++ b/scripts/tests/e3/parser.lua @@ -1,6 +1,10 @@ -require 'lunit' - -module('tests.e3.parser', package.seeall, lunit.testcase) +local tcname = 'tests.e3.parser' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/production.lua b/scripts/tests/e3/production.lua index 3469b06c4..1ff3e4260 100644 --- a/scripts/tests/e3/production.lua +++ b/scripts/tests/e3/production.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.production", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.production' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index aae3b3ab1..ae2766d2c 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.e3features", package.seeall, lunit.testcase) +local tcname = 'tests.e3.rules' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local settings diff --git a/scripts/tests/e3/spells-e2.lua b/scripts/tests/e3/spells-e2.lua index f232b8a1a..205450268 100644 --- a/scripts/tests/e3/spells-e2.lua +++ b/scripts/tests/e3/spells-e2.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.spells-e2", package.seeall, lunit.testcase) +local tcname = 'tests.e3.e2spells' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local r, f, u diff --git a/scripts/tests/e3/spells.lua b/scripts/tests/e3/spells.lua index 24f97c221..1d76bb3f1 100644 --- a/scripts/tests/e3/spells.lua +++ b/scripts/tests/e3/spells.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.spells", package.seeall, lunit.testcase) +local tcname = 'tests.e3.spells' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/stealth.lua b/scripts/tests/e3/stealth.lua index 866eb4f14..0c0df3c2b 100644 --- a/scripts/tests/e3/stealth.lua +++ b/scripts/tests/e3/stealth.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.stealth", package.seeall, lunit.testcase) +local tcname = 'tests.e3.stealth' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local f local u diff --git a/scripts/tests/parser.lua b/scripts/tests/parser.lua new file mode 100644 index 000000000..835e08d92 --- /dev/null +++ b/scripts/tests/parser.lua @@ -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, '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 diff --git a/scripts/tests/recruit.lua b/scripts/tests/recruit.lua new file mode 100644 index 000000000..d783fc692 --- /dev/null +++ b/scripts/tests/recruit.lua @@ -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, '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 From 8e7919f206ab7cb3aeee034814b5d47c22a67687 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 30 Apr 2020 19:46:23 +0200 Subject: [PATCH 05/26] clibs submodule update --- clibs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clibs b/clibs index abe774f70..484fbf23e 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit abe774f70265de14ea7f5e530518ca130562a9c9 +Subproject commit 484fbf23e34f6844f1c4e3f685bb6c53cadf5bfe From 2529a781d81e5dc7fe443b879adc72697ad13cdd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 30 Apr 2020 20:01:02 +0200 Subject: [PATCH 06/26] fix lunit --- scripts/run-tests-e2.lua | 2 +- scripts/run-tests-e3.lua | 2 +- scripts/run-tests.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua index b5f18c7f7..64a090108 100644 --- a/scripts/run-tests-e2.lua +++ b/scripts/run-tests-e2.lua @@ -11,11 +11,11 @@ package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' config.rules = 'e2' +lunit = require 'lunit' require 'eressea' require 'eressea.xmlconf' require 'eressea.path' require 'tests.e2' -require 'lunit' rng.inject(0) eressea.settings.set("rules.food.flags", "4") diff --git a/scripts/run-tests-e3.lua b/scripts/run-tests-e3.lua index 3332df306..43d42635e 100644 --- a/scripts/run-tests-e3.lua +++ b/scripts/run-tests-e3.lua @@ -11,11 +11,11 @@ package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' config.rules = 'e3' +lunit = require 'lunit' require 'eressea' require 'eressea.path' require 'eressea.xmlconf' require 'tests.e3' -require 'lunit' rng.inject(0) eressea.settings.set("rules.alliances", "0") diff --git a/scripts/run-tests.lua b/scripts/run-tests.lua index d1306ddcd..c41c29f01 100644 --- a/scripts/run-tests.lua +++ b/scripts/run-tests.lua @@ -9,9 +9,9 @@ if config.install then end package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' +lunit = require 'lunit' require 'eressea' require 'eressea.path' require 'tests' -require 'lunit' result = lunit.main() return result.errors + result.failed From e337fa996c468417f78ecc41eb6ec2d11c27ce4b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 1 May 2020 17:06:08 +0200 Subject: [PATCH 07/26] do not include lunit in the project, use luarocks to install --- .gitmodules | 3 --- lunit | 1 - 2 files changed, 4 deletions(-) delete mode 160000 lunit diff --git a/.gitmodules b/.gitmodules index 4d903c57f..f76a3af9c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "lunit"] - path = lunit - url = https://github.com/ennorehling/lunit.git [submodule "dlmalloc"] path = dlmalloc url = https://github.com/ennorehling/dlmalloc.git diff --git a/lunit b/lunit deleted file mode 160000 index 155c96594..000000000 --- a/lunit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 155c96594435413b4f704eb17558ea0b70631bad From 8982b649815774b1b2a64010ff563a496e7919f4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 1 May 2020 17:12:16 +0200 Subject: [PATCH 08/26] install lunitx as part of setup --- s/cmake-init | 1 + 1 file changed, 1 insertion(+) diff --git a/s/cmake-init b/s/cmake-init index eea222334..22d98b42e 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -125,6 +125,7 @@ TOLUA else echo "tolua is $path" fi +luarocks --local install lunitx unset path set -e From bd4db1a9d8e2bd67a9647c3e58751ff64c808900 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 1 May 2020 17:23:00 +0200 Subject: [PATCH 09/26] no need to modify package.path --- scripts/eressea/path.lua | 1 - scripts/run-tests-e2.lua | 2 -- scripts/run-tests-e3.lua | 2 -- scripts/run-tests.lua | 2 -- 4 files changed, 7 deletions(-) diff --git a/scripts/eressea/path.lua b/scripts/eressea/path.lua index def970919..085cda997 100644 --- a/scripts/eressea/path.lua +++ b/scripts/eressea/path.lua @@ -3,4 +3,3 @@ if config.paths ~= nil then package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' end end --- print(package.path) diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua index 64a090108..2495b8385 100644 --- a/scripts/run-tests-e2.lua +++ b/scripts/run-tests-e2.lua @@ -4,8 +4,6 @@ path = 'scripts' if config.install then 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 package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' diff --git a/scripts/run-tests-e3.lua b/scripts/run-tests-e3.lua index 43d42635e..e6c8c9186 100644 --- a/scripts/run-tests-e3.lua +++ b/scripts/run-tests-e3.lua @@ -4,8 +4,6 @@ path = 'scripts' if config.install then 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 package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' diff --git a/scripts/run-tests.lua b/scripts/run-tests.lua index c41c29f01..c14e15a3a 100644 --- a/scripts/run-tests.lua +++ b/scripts/run-tests.lua @@ -4,8 +4,6 @@ path = 'scripts' if config.install then 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 package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' From f0387825cb05c6d7583e5fc7ab68f80133912f10 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 1 May 2020 17:35:45 +0200 Subject: [PATCH 10/26] include luarocks in travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index d7a014d89..b702efaab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ addons: - valgrind - cppcheck - shellcheck + - luarocks os: - linux notifications: From 9f5ffe974f642a8d695b26829f4982fbdf46c46a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 1 May 2020 17:41:29 +0200 Subject: [PATCH 11/26] set luarocks path before runnign tests --- s/runtests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s/runtests b/s/runtests index b74a4b785..f62d410a5 100755 --- a/s/runtests +++ b/s/runtests @@ -1,6 +1,6 @@ #!/bin/bash set -e - +eval ($luarocks path) ROOT=$(git rev-parse --show-toplevel) [ -z $BUILD ] && BUILD=Debug ; export BUILD From c17a2ffe0226150455e686bb55612956e871f54c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 1 May 2020 17:46:14 +0200 Subject: [PATCH 12/26] typo in last commit --- s/runtests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s/runtests b/s/runtests index f62d410a5..429f8ef03 100755 --- a/s/runtests +++ b/s/runtests @@ -1,6 +1,6 @@ #!/bin/bash set -e -eval ($luarocks path) +eval $(luarocks path) ROOT=$(git rev-parse --show-toplevel) [ -z $BUILD ] && BUILD=Debug ; export BUILD From 64a2890c9107531356c14bfc6dff9b7b4ea6a2ec Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 19 Apr 2020 21:35:48 +0200 Subject: [PATCH 13/26] convert to lua 5.3 --- CMakeLists.txt | 2 ++ s/cmake-init | 4 ++++ s/runtests | 1 + scripts/run-tests-e2.lua | 2 ++ scripts/run-tests-e3.lua | 3 +++ scripts/run-tests.lua | 3 +++ scripts/tests/bindings.lua | 11 +++++++---- scripts/tests/common.lua | 10 +++++++--- scripts/tests/config.lua | 10 +++++++--- scripts/tests/e2/adamantium.lua | 10 +++++++--- scripts/tests/e2/allies.lua | 10 +++++++--- scripts/tests/e2/astral.lua | 12 ++++++++---- scripts/tests/e2/buildings.lua | 10 +++++++--- scripts/tests/e2/carts.lua | 10 +++++++--- scripts/tests/e2/destroy.lua | 10 +++++++--- scripts/tests/e2/e2features.lua | 10 +++++++--- scripts/tests/e2/guard.lua | 10 +++++++--- scripts/tests/e2/init.lua | 1 - scripts/tests/e2/insects.lua | 10 +++++++--- scripts/tests/e2/items.lua | 10 +++++++--- scripts/tests/e2/movement.lua | 10 +++++++--- scripts/tests/e2/production.lua | 10 +++++++--- scripts/tests/e2/quit.lua | 10 +++++++--- scripts/tests/e2/shiplanding.lua | 10 +++++++--- scripts/tests/e2/ships.lua | 10 +++++++--- scripts/tests/e2/spells.lua | 10 +++++++--- scripts/tests/e2/stealth.lua | 10 +++++++--- scripts/tests/e2/undead.lua | 10 +++++++--- scripts/tests/economy.lua | 10 +++++++--- scripts/tests/faction.lua | 9 ++++++--- scripts/tests/hunger.lua | 10 +++++++--- scripts/tests/items.lua | 10 +++++++--- scripts/tests/laws.lua | 10 +++++++--- scripts/tests/locale.lua | 9 ++++++--- scripts/tests/magicbag.lua | 10 +++++++--- scripts/tests/movement.lua | 9 ++++++--- scripts/tests/orders.lua | 12 +++++++----- scripts/tests/pool.lua | 9 ++++++--- scripts/tests/process.lua | 10 +++++++--- scripts/tests/production.lua | 10 +++++++--- scripts/tests/regions.lua | 10 +++++++--- scripts/tests/report.lua | 10 +++++++--- scripts/tests/settings.lua | 10 +++++++--- scripts/tests/spells.lua | 9 +++++++-- scripts/tests/storage.lua | 10 +++++++--- scripts/tests/study.lua | 10 +++++++--- scripts/tests/undead.lua | 10 +++++++--- scripts/tests/xmas.lua | 10 +++++++--- 48 files changed, 299 insertions(+), 127 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d2635f05..e8c4893d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,8 @@ find_package (ToLua REQUIRED) if (TOLUA_FOUND) if (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.2") find_package (Lua 5.2 REQUIRED) +elseif (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.3") +find_package ( Lua 5.3 REQUIRED) else () find_package (Lua51 REQUIRED) endif() diff --git a/s/cmake-init b/s/cmake-init index 22d98b42e..03759b16c 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -82,6 +82,10 @@ LUA_DIR=/usr if [ -d /usr/include/lua5.1 ]; then LUA_VERSION="5.1" LUA_INCLUDE=/usr/include/lua5.1 +elif [ -d /usr/include/lua5.3 ]; then + export LUA_DIR=/usr + LUA_VERSION="5.3" + LUA_INCLUDE=/usr/include/lua5.3 elif [ -d /usr/include/lua5.2 ]; then export LUA_DIR=/usr LUA_VERSION="5.2" diff --git a/s/runtests b/s/runtests index 429f8ef03..2c8049098 100755 --- a/s/runtests +++ b/s/runtests @@ -1,5 +1,6 @@ #!/bin/bash set -e + eval $(luarocks path) ROOT=$(git rev-parse --show-toplevel) [ -z $BUILD ] && BUILD=Debug ; export BUILD diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua index 2495b8385..f12ed0128 100644 --- a/scripts/run-tests-e2.lua +++ b/scripts/run-tests-e2.lua @@ -1,6 +1,8 @@ -- 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 +lunit = require('lunit') +module = lunit.module path = 'scripts' if config.install then path = config.install .. '/' .. path diff --git a/scripts/run-tests-e3.lua b/scripts/run-tests-e3.lua index e6c8c9186..67ae860eb 100644 --- a/scripts/run-tests-e3.lua +++ b/scripts/run-tests-e3.lua @@ -1,6 +1,9 @@ -- 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 +lunit = require('lunit') +module = lunit.module + path = 'scripts' if config.install then path = config.install .. '/' .. path diff --git a/scripts/run-tests.lua b/scripts/run-tests.lua index c14e15a3a..e81ceeede 100644 --- a/scripts/run-tests.lua +++ b/scripts/run-tests.lua @@ -10,6 +10,9 @@ package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' lunit = require 'lunit' require 'eressea' require 'eressea.path' + +lunit = require('lunit') +module = lunit.module require 'tests' result = lunit.main() return result.errors + result.failed diff --git a/scripts/tests/bindings.lua b/scripts/tests/bindings.lua index 5820e0a47..4e308de99 100644 --- a/scripts/tests/bindings.lua +++ b/scripts/tests/bindings.lua @@ -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, 'seeall') +end -local eressea = eressea local _G = _G -module("tests.bindings", lunit.testcase) - function test_eressea() assert_equal("function", _G.type(eressea.free_game)) assert_equal("function", _G.type(eressea.read_game)) diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 70ff2527d..a11a28bed 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -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, 'seeall') +end local function _test_create_ship(r) local s = ship.create(r, config.ships[1]) @@ -26,8 +32,6 @@ local function two_factions() return f1, f2 end -module("tests.common", package.seeall, lunit.testcase) - function setup() eressea.free_game() eressea.settings.set("nmr.timeout", "0") diff --git a/scripts/tests/config.lua b/scripts/tests/config.lua index 733a8ee07..cdf93ed2c 100644 --- a/scripts/tests/config.lua +++ b/scripts/tests/config.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.eressea.config", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.config' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/adamantium.lua b/scripts/tests/e2/adamantium.lua index a893d32d5..0a0c2ec6b 100644 --- a/scripts/tests/e2/adamantium.lua +++ b/scripts/tests/e2/adamantium.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.adamantium", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.adamantium' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/allies.lua b/scripts/tests/e2/allies.lua index 8c0352923..52f69ba98 100644 --- a/scripts/tests/e2/allies.lua +++ b/scripts/tests/e2/allies.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.allies", package.seeall, lunit.testcase) +local tcname = 'tests.e2.allies' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/astral.lua b/scripts/tests/e2/astral.lua index 5c4461921..c183c6207 100644 --- a/scripts/tests/e2/astral.lua +++ b/scripts/tests/e2/astral.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.astral", package.seeall, lunit.testcase) +local tcname = 'tests.e2.astral' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() @@ -17,7 +21,7 @@ function test_fetch_astral() local r = region.create(0, 0, "plain") local ra = r:get_astral('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 u2 = unit.create(f, r, 1) local u3 = unit.create(f, rb, 1) diff --git a/scripts/tests/e2/buildings.lua b/scripts/tests/e2/buildings.lua index a2407335b..0e735f0b9 100644 --- a/scripts/tests/e2/buildings.lua +++ b/scripts/tests/e2/buildings.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.buildings", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.buildings' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/carts.lua b/scripts/tests/e2/carts.lua index 025b473df..f649451e2 100644 --- a/scripts/tests/e2/carts.lua +++ b/scripts/tests/e2/carts.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.carts", package.seeall, lunit.testcase) +local tcname = 'tests.e2.carts' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/destroy.lua b/scripts/tests/e2/destroy.lua index db6f09c2a..7a02f0840 100644 --- a/scripts/tests/e2/destroy.lua +++ b/scripts/tests/e2/destroy.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.destroy", package.seeall, lunit.testcase) +local tcname = 'tests.e2.destroy' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index 3175a091e..dc083e69d 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.e2features", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.features' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/guard.lua b/scripts/tests/e2/guard.lua index e3cf8075f..fd7f37ad0 100644 --- a/scripts/tests/e2/guard.lua +++ b/scripts/tests/e2/guard.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.guard", package.seeall, lunit.testcase) +local tcname = 'tests.e2.guard' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 4246fd288..0e93bdeae 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -3,7 +3,6 @@ require 'tests.e2.trees' require 'tests.e2.buildings' require 'tests.e2.movement' require 'tests.e2.carts' -require 'tests.e2.quit' require 'tests.e2.astral' require 'tests.e2.spells' require 'tests.e2.e2features' diff --git a/scripts/tests/e2/insects.lua b/scripts/tests/e2/insects.lua index f5b8a3213..296c67e82 100644 --- a/scripts/tests/e2/insects.lua +++ b/scripts/tests/e2/insects.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.insects", package.seeall, lunit.testcase) +local tcname = 'tests.e2.insects' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/items.lua b/scripts/tests/e2/items.lua index 2492a7fdb..9221d424b 100644 --- a/scripts/tests/e2/items.lua +++ b/scripts/tests/e2/items.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.items", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.items' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/movement.lua b/scripts/tests/e2/movement.lua index aa42857f3..db9f4fbdd 100644 --- a/scripts/tests/e2/movement.lua +++ b/scripts/tests/e2/movement.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.movement", package.seeall, lunit.testcase) +local tcname = 'tests.e2.movement' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/production.lua b/scripts/tests/e2/production.lua index 80d3447d2..7941c1af4 100644 --- a/scripts/tests/e2/production.lua +++ b/scripts/tests/e2/production.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.production", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.production' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/quit.lua b/scripts/tests/e2/quit.lua index 7db59091b..9d02c49eb 100644 --- a/scripts/tests/e2/quit.lua +++ b/scripts/tests/e2/quit.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.quit", package.seeall, lunit.testcase) +local tcname = 'tests.e2.quit' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function test_quit_faction() local r = region.create(47, 0, "plain") diff --git a/scripts/tests/e2/shiplanding.lua b/scripts/tests/e2/shiplanding.lua index 2258a1992..7b146f2e6 100644 --- a/scripts/tests/e2/shiplanding.lua +++ b/scripts/tests/e2/shiplanding.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.shiplanding", package.seeall, lunit.testcase) +local tcname = 'tests.e2.shiplanding' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/ships.lua b/scripts/tests/e2/ships.lua index 5b77220ec..2f5db607d 100644 --- a/scripts/tests/e2/ships.lua +++ b/scripts/tests/e2/ships.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.ships", package.seeall, lunit.testcase) +local tcname = 'tests.e2.ships' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/spells.lua b/scripts/tests/e2/spells.lua index 8942ee1f5..cf8814de2 100644 --- a/scripts/tests/e2/spells.lua +++ b/scripts/tests/e2/spells.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.spells", package.seeall, lunit.testcase) +local tcname = 'tests.e2.spells' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/stealth.lua b/scripts/tests/e2/stealth.lua index 7f531776c..60b66e83f 100644 --- a/scripts/tests/e2/stealth.lua +++ b/scripts/tests/e2/stealth.lua @@ -1,6 +1,10 @@ -require "lunit" - -module('tests.e2.stealth', package.seeall, lunit.testcase) +local tcname = 'tests.e2.stealth' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local f local u diff --git a/scripts/tests/e2/undead.lua b/scripts/tests/e2/undead.lua index b283d1fcc..d43f67164 100644 --- a/scripts/tests/e2/undead.lua +++ b/scripts/tests/e2/undead.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.undead", package.seeall, lunit.testcase) +local tcname = 'tests.e2.undead' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/economy.lua b/scripts/tests/economy.lua index 0c140e418..17dcbfc61 100644 --- a/scripts/tests/economy.lua +++ b/scripts/tests/economy.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.economy", package.seeall, lunit.testcase) +local tcname = 'tests.shared.economy' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index c264f4596..7247498ea 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -1,6 +1,9 @@ -require "lunit" - -module ('tests.eressea.faction', package.seeall, lunit.testcase) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.faction", 'seeall') +else + module("tests.faction", 'seeall') +end local f diff --git a/scripts/tests/hunger.lua b/scripts/tests/hunger.lua index a33c2208b..fed24440e 100644 --- a/scripts/tests/hunger.lua +++ b/scripts/tests/hunger.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.hunger", package.seeall, lunit.testcase) +local tcname = 'tests.hunger' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/items.lua b/scripts/tests/items.lua index f4d8657c6..e1e780f3c 100644 --- a/scripts/tests/items.lua +++ b/scripts/tests/items.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.items", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.items' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/laws.lua b/scripts/tests/laws.lua index 6dc37daf7..e22bc5d8f 100644 --- a/scripts/tests/laws.lua +++ b/scripts/tests/laws.lua @@ -1,6 +1,9 @@ -require "lunit" - -module("tests.laws", package.seeall, lunit.testcase) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.laws", 'seeall') +else + module("tests.laws", 'seeall') +end function setup() eressea.free_game() @@ -115,3 +118,4 @@ function test_force_leave_postcombat() assert_equal(nil, u3.building) assert_equal(1, u3.number) end + diff --git a/scripts/tests/locale.lua b/scripts/tests/locale.lua index 2770beb3f..d1d35ded3 100644 --- a/scripts/tests/locale.lua +++ b/scripts/tests/locale.lua @@ -1,6 +1,9 @@ -require "lunit" - -module("tests.eressea.locale", package.seeall, lunit.testcase ) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.locale", 'seeall') +else + module("tests.locale", 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/magicbag.lua b/scripts/tests/magicbag.lua index b51925726..7e4629707 100644 --- a/scripts/tests/magicbag.lua +++ b/scripts/tests/magicbag.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.magicbag", package.seeall, lunit.testcase) +local tcname = 'tests.shared.magicbag' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local u diff --git a/scripts/tests/movement.lua b/scripts/tests/movement.lua index 22bd8d30e..943e912a8 100644 --- a/scripts/tests/movement.lua +++ b/scripts/tests/movement.lua @@ -1,6 +1,9 @@ -require "lunit" - -module("tests.movement", package.seeall, lunit.testcase) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.movement", 'seeall') +else + module("tests.movement", 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/orders.lua b/scripts/tests/orders.lua index 6dc191d6c..c63254315 100644 --- a/scripts/tests/orders.lua +++ b/scripts/tests/orders.lua @@ -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, 'seeall') +end local _G = _G -local eressea = eressea local default_ship = config.ships[1] local default_building = config.buildings[1] - -module('tests.eressea.orders', package.seeall, lunit.testcase) - local r, f, u function setup() diff --git a/scripts/tests/pool.lua b/scripts/tests/pool.lua index 0d24f8129..06f212f60 100644 --- a/scripts/tests/pool.lua +++ b/scripts/tests/pool.lua @@ -1,6 +1,9 @@ -require "lunit" - -module("tests.eressea.pool", package.seeall, lunit.testcase ) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.pool", 'seeall') +else + module("tests.pool", 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/process.lua b/scripts/tests/process.lua index 1fc9a64f5..0b9b3e35b 100644 --- a/scripts/tests/process.lua +++ b/scripts/tests/process.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.process", package.seeall, lunit.testcase) +local tcname = 'tests.shared.process' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local u, r, f diff --git a/scripts/tests/production.lua b/scripts/tests/production.lua index c8a299676..b127fff02 100644 --- a/scripts/tests/production.lua +++ b/scripts/tests/production.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.production", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.production' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/regions.lua b/scripts/tests/regions.lua index 32197f0fd..e16dd1691 100644 --- a/scripts/tests/regions.lua +++ b/scripts/tests/regions.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.regions", package.seeall, lunit.testcase) +local tcname = 'tests.regions' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/report.lua b/scripts/tests/report.lua index b02f4a908..66eaa7d89 100644 --- a/scripts/tests/report.lua +++ b/scripts/tests/report.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.report", package.seeall, lunit.testcase) +local tcname = 'tests.shared.report' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/settings.lua b/scripts/tests/settings.lua index 8f2c5e637..f321a515b 100644 --- a/scripts/tests/settings.lua +++ b/scripts/tests/settings.lua @@ -1,6 +1,10 @@ -require 'lunit' - -module('tests.eressea.settings', package.seeall, lunit.testcase ) +local tcname = 'tests.settings' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/spells.lua b/scripts/tests/spells.lua index 27a5424f7..767df5d16 100644 --- a/scripts/tests/spells.lua +++ b/scripts/tests/spells.lua @@ -1,5 +1,10 @@ -require 'lunit' -module("tests.spells", package.seeall, lunit.testcase) +local tcname = 'tests.shared.spells' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/storage.lua b/scripts/tests/storage.lua index 32fbe9ef3..22af5a221 100644 --- a/scripts/tests/storage.lua +++ b/scripts/tests/storage.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.storage", package.seeall, lunit.testcase) +local tcname = 'tests.shared.storage' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/study.lua b/scripts/tests/study.lua index 32638ba90..21c70044e 100644 --- a/scripts/tests/study.lua +++ b/scripts/tests/study.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.eressea.study", package.seeall, lunit.testcase) +local tcname = 'tests.study' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() conf = [[{ diff --git a/scripts/tests/undead.lua b/scripts/tests/undead.lua index a3c541afa..4cb86fc67 100644 --- a/scripts/tests/undead.lua +++ b/scripts/tests/undead.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.undead", package.seeall, lunit.testcase) +local tcname = 'tests.shared.undead' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/xmas.lua b/scripts/tests/xmas.lua index 8ae85fc76..10386c0ed 100644 --- a/scripts/tests/xmas.lua +++ b/scripts/tests/xmas.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.xmas", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.xmas' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() From 34e076f75bffadacf8c275e7c11865ab0e9958c9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Apr 2020 20:58:52 +0200 Subject: [PATCH 14/26] use luarocks --- s/build | 2 +- s/cmake-init | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/s/build b/s/build index 709c92510..e54f83ace 100755 --- a/s/build +++ b/s/build @@ -1,6 +1,6 @@ #!/bin/sh ROOT=$(git rev-parse --show-toplevel) - +eval $(luarocks path) [ -z "$BUILD" ] && BUILD=Debug if [ -z "$JOBS" ] ; then if [ -e /usr/sbin/sysctl ]; then diff --git a/s/cmake-init b/s/cmake-init index 03759b16c..9d64a9666 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -6,6 +6,7 @@ pkg-config --exists sqlite3 && ERESSEA_DB=sqlite GETOPT=getopt GETOPT_LONG=1 +luarocks install lunitx --local if [ "Darwin" = "$(uname)" ] ; then if [ -x "/usr/local/opt/gnu-getopt/bin/getopt" ] ; then GETOPT="/usr/local/opt/gnu-getopt/bin/getopt" @@ -74,8 +75,6 @@ fi DEST=$(dirname $ROOT)/server -git submodule update --init - LUA_VERSION="5.2" LUA_INCLUDE=/usr/include LUA_DIR=/usr From 947a72278ec6b168cb0436399ce26de9de5e23ad Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 22 Apr 2020 03:03:44 +0200 Subject: [PATCH 15/26] make all test modules work with lunitx --- scripts/tests/common.lua | 304 -------------------------------- scripts/tests/e2/init.lua | 2 + scripts/tests/e3/buildings.lua | 10 +- scripts/tests/e3/init.lua | 2 + scripts/tests/e3/items.lua | 10 +- scripts/tests/e3/morale.lua | 14 +- scripts/tests/e3/parser.lua | 10 +- scripts/tests/e3/production.lua | 10 +- scripts/tests/e3/rules.lua | 10 +- scripts/tests/e3/spells-e2.lua | 10 +- scripts/tests/e3/spells.lua | 10 +- scripts/tests/e3/stealth.lua | 10 +- scripts/tests/parser.lua | 270 ++++++++++++++++++++++++++++ scripts/tests/recruit.lua | 46 +++++ 14 files changed, 385 insertions(+), 333 deletions(-) create mode 100644 scripts/tests/parser.lua create mode 100644 scripts/tests/recruit.lua diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index a11a28bed..10084f554 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -898,307 +898,3 @@ function test_walk_and_carry_the_cart() process_orders() assert_equal(1, u.region.x) 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 diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 0e93bdeae..6a4d7bca2 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -22,6 +22,8 @@ require 'tests.items' require 'tests.economy' require 'tests.orders' require 'tests.common' +require 'tests.recruit' +require 'tests.parser' require 'tests.report' require 'tests.storage' require 'tests.magicbag' diff --git a/scripts/tests/e3/buildings.lua b/scripts/tests/e3/buildings.lua index d5ea4fa51..fa9f5d16f 100644 --- a/scripts/tests/e3/buildings.lua +++ b/scripts/tests/e3/buildings.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.buildings", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.buildings' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/init.lua b/scripts/tests/e3/init.lua index 04b7da4a2..2ccd19139 100644 --- a/scripts/tests/e3/init.lua +++ b/scripts/tests/e3/init.lua @@ -10,6 +10,8 @@ require 'tests.spells' require 'tests.economy' require 'tests.orders' require 'tests.common' +require 'tests.recruit' +require 'tests.parser' require 'tests.items' require 'tests.magicbag' require 'tests.process' diff --git a/scripts/tests/e3/items.lua b/scripts/tests/e3/items.lua index 1df6be85a..1036f6ca4 100644 --- a/scripts/tests/e3/items.lua +++ b/scripts/tests/e3/items.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.items", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.items' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/morale.lua b/scripts/tests/e3/morale.lua index 1dd92a758..898e08674 100644 --- a/scripts/tests/e3/morale.lua +++ b/scripts/tests/e3/morale.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.morale", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.morale' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() @@ -171,7 +175,7 @@ function test_morale_change() run_a_turn() 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) u1.building = nil update_owners() @@ -186,7 +190,7 @@ function test_morale_change() run_a_turn() assert_equal(1, r.morale) - -- ohne herrscher ändert sich auch beschissene Moral nicht: + -- ohne herrscher ändert sich auch beschissene Moral nicht: r.morale = 0 run_a_turn() assert_equal(0, r.morale) diff --git a/scripts/tests/e3/parser.lua b/scripts/tests/e3/parser.lua index a56f08f76..52a082bf1 100644 --- a/scripts/tests/e3/parser.lua +++ b/scripts/tests/e3/parser.lua @@ -1,6 +1,10 @@ -require 'lunit' - -module('tests.e3.parser', package.seeall, lunit.testcase) +local tcname = 'tests.e3.parser' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/production.lua b/scripts/tests/e3/production.lua index 3469b06c4..1ff3e4260 100644 --- a/scripts/tests/e3/production.lua +++ b/scripts/tests/e3/production.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.production", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.production' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index aae3b3ab1..ae2766d2c 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.e3features", package.seeall, lunit.testcase) +local tcname = 'tests.e3.rules' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local settings diff --git a/scripts/tests/e3/spells-e2.lua b/scripts/tests/e3/spells-e2.lua index f232b8a1a..205450268 100644 --- a/scripts/tests/e3/spells-e2.lua +++ b/scripts/tests/e3/spells-e2.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.spells-e2", package.seeall, lunit.testcase) +local tcname = 'tests.e3.e2spells' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local r, f, u diff --git a/scripts/tests/e3/spells.lua b/scripts/tests/e3/spells.lua index 24f97c221..1d76bb3f1 100644 --- a/scripts/tests/e3/spells.lua +++ b/scripts/tests/e3/spells.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.spells", package.seeall, lunit.testcase) +local tcname = 'tests.e3.spells' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/stealth.lua b/scripts/tests/e3/stealth.lua index 866eb4f14..0c0df3c2b 100644 --- a/scripts/tests/e3/stealth.lua +++ b/scripts/tests/e3/stealth.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.stealth", package.seeall, lunit.testcase) +local tcname = 'tests.e3.stealth' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local f local u diff --git a/scripts/tests/parser.lua b/scripts/tests/parser.lua new file mode 100644 index 000000000..835e08d92 --- /dev/null +++ b/scripts/tests/parser.lua @@ -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, '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 diff --git a/scripts/tests/recruit.lua b/scripts/tests/recruit.lua new file mode 100644 index 000000000..d783fc692 --- /dev/null +++ b/scripts/tests/recruit.lua @@ -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, '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 From c1412d3050a4533c0e17759c3aa97c14ae83871b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 21 Apr 2020 21:18:24 +0200 Subject: [PATCH 16/26] remove duplicate test functions --- scripts/tests/e2/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 6a4d7bca2..587c295c0 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -32,3 +32,4 @@ require 'tests.xmas' require 'tests.production' require 'tests.spells' require 'tests.undead' + From 0d5bef52567b16956dd1a1d3b49c979c7a2f9748 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 2 May 2020 11:13:26 +0200 Subject: [PATCH 17/26] re-enable missing tests in E2 --- scripts/tests/e2/trees.lua | 10 +++++++--- scripts/tests/e2/trolls.lua | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/tests/e2/trees.lua b/scripts/tests/e2/trees.lua index 739d9f1e6..21f7611cd 100644 --- a/scripts/tests/e2/trees.lua +++ b/scripts/tests/e2/trees.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.trees", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.trees' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/trolls.lua b/scripts/tests/e2/trolls.lua index b6d96b015..811f1f736 100644 --- a/scripts/tests/e2/trolls.lua +++ b/scripts/tests/e2/trolls.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.trolls", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.trolls' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() From 3c533580f721be42313a6e72c2324f00ef765f6d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 3 May 2020 15:05:22 +0200 Subject: [PATCH 18/26] tolua 5.3 support on macOS --- CMakeLists.txt | 4 +++- s/cmake-init | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d2635f05..9bd567d24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,9 @@ endif() find_package(EXPAT REQUIRED) find_package (ToLua REQUIRED) 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) else () find_package (Lua51 REQUIRED) diff --git a/s/cmake-init b/s/cmake-init index 22d98b42e..a8228c379 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -79,13 +79,16 @@ git submodule update --init LUA_VERSION="5.2" LUA_INCLUDE=/usr/include LUA_DIR=/usr -if [ -d /usr/include/lua5.1 ]; then - LUA_VERSION="5.1" - LUA_INCLUDE=/usr/include/lua5.1 +if [ -d /usr/local/include/lua5.3 ]; then + LUA_VERSION="5.3" + LUA_INCLUDE=/usr/local/include/lua5.3 elif [ -d /usr/include/lua5.2 ]; then export LUA_DIR=/usr LUA_VERSION="5.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 export LUA_DIR=/usr/local LUA_VERSION="5.1" From 97cb46933eccb9590a34cd0ccc7c37c2914257a4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 3 May 2020 15:16:25 +0200 Subject: [PATCH 19/26] typo, ccidental bit-shift operation --- src/laws.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/laws.c b/src/laws.c index fc1c8dc88..01aa4be8d 100644 --- a/src/laws.c +++ b/src/laws.c @@ -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[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[1] = (short)cap_int(a->data.sa[1], 0, SHRT_MAX); } From 17e5d6ab78f83ee088dd2012db26c1564bebc83a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 19 Apr 2020 21:35:48 +0200 Subject: [PATCH 20/26] convert to lua 5.3 --- CMakeLists.txt | 2 ++ s/runtests | 1 + scripts/run-tests-e2.lua | 2 ++ scripts/run-tests-e3.lua | 3 +++ scripts/run-tests.lua | 3 +++ scripts/tests/bindings.lua | 11 +++++++---- scripts/tests/common.lua | 10 +++++++--- scripts/tests/config.lua | 10 +++++++--- scripts/tests/e2/adamantium.lua | 10 +++++++--- scripts/tests/e2/allies.lua | 10 +++++++--- scripts/tests/e2/astral.lua | 12 ++++++++---- scripts/tests/e2/buildings.lua | 10 +++++++--- scripts/tests/e2/carts.lua | 10 +++++++--- scripts/tests/e2/destroy.lua | 10 +++++++--- scripts/tests/e2/e2features.lua | 10 +++++++--- scripts/tests/e2/guard.lua | 10 +++++++--- scripts/tests/e2/init.lua | 1 - scripts/tests/e2/insects.lua | 10 +++++++--- scripts/tests/e2/items.lua | 10 +++++++--- scripts/tests/e2/movement.lua | 10 +++++++--- scripts/tests/e2/production.lua | 10 +++++++--- scripts/tests/e2/quit.lua | 10 +++++++--- scripts/tests/e2/shiplanding.lua | 10 +++++++--- scripts/tests/e2/ships.lua | 10 +++++++--- scripts/tests/e2/spells.lua | 10 +++++++--- scripts/tests/e2/stealth.lua | 10 +++++++--- scripts/tests/e2/undead.lua | 10 +++++++--- scripts/tests/economy.lua | 10 +++++++--- scripts/tests/faction.lua | 9 ++++++--- scripts/tests/hunger.lua | 10 +++++++--- scripts/tests/items.lua | 10 +++++++--- scripts/tests/laws.lua | 10 +++++++--- scripts/tests/locale.lua | 9 ++++++--- scripts/tests/magicbag.lua | 10 +++++++--- scripts/tests/movement.lua | 9 ++++++--- scripts/tests/orders.lua | 12 +++++++----- scripts/tests/pool.lua | 9 ++++++--- scripts/tests/process.lua | 10 +++++++--- scripts/tests/production.lua | 10 +++++++--- scripts/tests/regions.lua | 10 +++++++--- scripts/tests/report.lua | 10 +++++++--- scripts/tests/settings.lua | 10 +++++++--- scripts/tests/spells.lua | 9 +++++++-- scripts/tests/storage.lua | 10 +++++++--- scripts/tests/study.lua | 10 +++++++--- scripts/tests/undead.lua | 10 +++++++--- scripts/tests/xmas.lua | 10 +++++++--- 47 files changed, 295 insertions(+), 127 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bd567d24..0edbe230c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,8 @@ 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) +elseif (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.3") +find_package ( Lua 5.3 REQUIRED) else () find_package (Lua51 REQUIRED) endif() diff --git a/s/runtests b/s/runtests index 429f8ef03..2c8049098 100755 --- a/s/runtests +++ b/s/runtests @@ -1,5 +1,6 @@ #!/bin/bash set -e + eval $(luarocks path) ROOT=$(git rev-parse --show-toplevel) [ -z $BUILD ] && BUILD=Debug ; export BUILD diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua index 2495b8385..f12ed0128 100644 --- a/scripts/run-tests-e2.lua +++ b/scripts/run-tests-e2.lua @@ -1,6 +1,8 @@ -- 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 +lunit = require('lunit') +module = lunit.module path = 'scripts' if config.install then path = config.install .. '/' .. path diff --git a/scripts/run-tests-e3.lua b/scripts/run-tests-e3.lua index e6c8c9186..67ae860eb 100644 --- a/scripts/run-tests-e3.lua +++ b/scripts/run-tests-e3.lua @@ -1,6 +1,9 @@ -- 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 +lunit = require('lunit') +module = lunit.module + path = 'scripts' if config.install then path = config.install .. '/' .. path diff --git a/scripts/run-tests.lua b/scripts/run-tests.lua index c14e15a3a..e81ceeede 100644 --- a/scripts/run-tests.lua +++ b/scripts/run-tests.lua @@ -10,6 +10,9 @@ package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' lunit = require 'lunit' require 'eressea' require 'eressea.path' + +lunit = require('lunit') +module = lunit.module require 'tests' result = lunit.main() return result.errors + result.failed diff --git a/scripts/tests/bindings.lua b/scripts/tests/bindings.lua index 5820e0a47..4e308de99 100644 --- a/scripts/tests/bindings.lua +++ b/scripts/tests/bindings.lua @@ -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, 'seeall') +end -local eressea = eressea local _G = _G -module("tests.bindings", lunit.testcase) - function test_eressea() assert_equal("function", _G.type(eressea.free_game)) assert_equal("function", _G.type(eressea.read_game)) diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 70ff2527d..a11a28bed 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -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, 'seeall') +end local function _test_create_ship(r) local s = ship.create(r, config.ships[1]) @@ -26,8 +32,6 @@ local function two_factions() return f1, f2 end -module("tests.common", package.seeall, lunit.testcase) - function setup() eressea.free_game() eressea.settings.set("nmr.timeout", "0") diff --git a/scripts/tests/config.lua b/scripts/tests/config.lua index 733a8ee07..cdf93ed2c 100644 --- a/scripts/tests/config.lua +++ b/scripts/tests/config.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.eressea.config", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.config' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/adamantium.lua b/scripts/tests/e2/adamantium.lua index a893d32d5..0a0c2ec6b 100644 --- a/scripts/tests/e2/adamantium.lua +++ b/scripts/tests/e2/adamantium.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.adamantium", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.adamantium' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/allies.lua b/scripts/tests/e2/allies.lua index 8c0352923..52f69ba98 100644 --- a/scripts/tests/e2/allies.lua +++ b/scripts/tests/e2/allies.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.allies", package.seeall, lunit.testcase) +local tcname = 'tests.e2.allies' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/astral.lua b/scripts/tests/e2/astral.lua index 5c4461921..c183c6207 100644 --- a/scripts/tests/e2/astral.lua +++ b/scripts/tests/e2/astral.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.astral", package.seeall, lunit.testcase) +local tcname = 'tests.e2.astral' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() @@ -17,7 +21,7 @@ function test_fetch_astral() local r = region.create(0, 0, "plain") local ra = r:get_astral('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 u2 = unit.create(f, r, 1) local u3 = unit.create(f, rb, 1) diff --git a/scripts/tests/e2/buildings.lua b/scripts/tests/e2/buildings.lua index a2407335b..0e735f0b9 100644 --- a/scripts/tests/e2/buildings.lua +++ b/scripts/tests/e2/buildings.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.buildings", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.buildings' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/carts.lua b/scripts/tests/e2/carts.lua index 025b473df..f649451e2 100644 --- a/scripts/tests/e2/carts.lua +++ b/scripts/tests/e2/carts.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.carts", package.seeall, lunit.testcase) +local tcname = 'tests.e2.carts' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/destroy.lua b/scripts/tests/e2/destroy.lua index db6f09c2a..7a02f0840 100644 --- a/scripts/tests/e2/destroy.lua +++ b/scripts/tests/e2/destroy.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.destroy", package.seeall, lunit.testcase) +local tcname = 'tests.e2.destroy' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index 3175a091e..dc083e69d 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.e2features", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.features' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/guard.lua b/scripts/tests/e2/guard.lua index e3cf8075f..fd7f37ad0 100644 --- a/scripts/tests/e2/guard.lua +++ b/scripts/tests/e2/guard.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.guard", package.seeall, lunit.testcase) +local tcname = 'tests.e2.guard' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 4246fd288..0e93bdeae 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -3,7 +3,6 @@ require 'tests.e2.trees' require 'tests.e2.buildings' require 'tests.e2.movement' require 'tests.e2.carts' -require 'tests.e2.quit' require 'tests.e2.astral' require 'tests.e2.spells' require 'tests.e2.e2features' diff --git a/scripts/tests/e2/insects.lua b/scripts/tests/e2/insects.lua index f5b8a3213..296c67e82 100644 --- a/scripts/tests/e2/insects.lua +++ b/scripts/tests/e2/insects.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.insects", package.seeall, lunit.testcase) +local tcname = 'tests.e2.insects' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/items.lua b/scripts/tests/e2/items.lua index 2492a7fdb..9221d424b 100644 --- a/scripts/tests/e2/items.lua +++ b/scripts/tests/e2/items.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.items", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.items' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/movement.lua b/scripts/tests/e2/movement.lua index aa42857f3..db9f4fbdd 100644 --- a/scripts/tests/e2/movement.lua +++ b/scripts/tests/e2/movement.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.movement", package.seeall, lunit.testcase) +local tcname = 'tests.e2.movement' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/production.lua b/scripts/tests/e2/production.lua index 80d3447d2..7941c1af4 100644 --- a/scripts/tests/e2/production.lua +++ b/scripts/tests/e2/production.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.production", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.production' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/quit.lua b/scripts/tests/e2/quit.lua index 7db59091b..9d02c49eb 100644 --- a/scripts/tests/e2/quit.lua +++ b/scripts/tests/e2/quit.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.quit", package.seeall, lunit.testcase) +local tcname = 'tests.e2.quit' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function test_quit_faction() local r = region.create(47, 0, "plain") diff --git a/scripts/tests/e2/shiplanding.lua b/scripts/tests/e2/shiplanding.lua index 2258a1992..7b146f2e6 100644 --- a/scripts/tests/e2/shiplanding.lua +++ b/scripts/tests/e2/shiplanding.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.shiplanding", package.seeall, lunit.testcase) +local tcname = 'tests.e2.shiplanding' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/ships.lua b/scripts/tests/e2/ships.lua index 5b77220ec..2f5db607d 100644 --- a/scripts/tests/e2/ships.lua +++ b/scripts/tests/e2/ships.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.ships", package.seeall, lunit.testcase) +local tcname = 'tests.e2.ships' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/spells.lua b/scripts/tests/e2/spells.lua index 8942ee1f5..cf8814de2 100644 --- a/scripts/tests/e2/spells.lua +++ b/scripts/tests/e2/spells.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.spells", package.seeall, lunit.testcase) +local tcname = 'tests.e2.spells' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/stealth.lua b/scripts/tests/e2/stealth.lua index 7f531776c..60b66e83f 100644 --- a/scripts/tests/e2/stealth.lua +++ b/scripts/tests/e2/stealth.lua @@ -1,6 +1,10 @@ -require "lunit" - -module('tests.e2.stealth', package.seeall, lunit.testcase) +local tcname = 'tests.e2.stealth' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local f local u diff --git a/scripts/tests/e2/undead.lua b/scripts/tests/e2/undead.lua index b283d1fcc..d43f67164 100644 --- a/scripts/tests/e2/undead.lua +++ b/scripts/tests/e2/undead.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.undead", package.seeall, lunit.testcase) +local tcname = 'tests.e2.undead' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/economy.lua b/scripts/tests/economy.lua index 0c140e418..17dcbfc61 100644 --- a/scripts/tests/economy.lua +++ b/scripts/tests/economy.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.economy", package.seeall, lunit.testcase) +local tcname = 'tests.shared.economy' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index c264f4596..7247498ea 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -1,6 +1,9 @@ -require "lunit" - -module ('tests.eressea.faction', package.seeall, lunit.testcase) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.faction", 'seeall') +else + module("tests.faction", 'seeall') +end local f diff --git a/scripts/tests/hunger.lua b/scripts/tests/hunger.lua index a33c2208b..fed24440e 100644 --- a/scripts/tests/hunger.lua +++ b/scripts/tests/hunger.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.hunger", package.seeall, lunit.testcase) +local tcname = 'tests.hunger' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/items.lua b/scripts/tests/items.lua index f4d8657c6..e1e780f3c 100644 --- a/scripts/tests/items.lua +++ b/scripts/tests/items.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.items", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.items' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/laws.lua b/scripts/tests/laws.lua index 6dc37daf7..e22bc5d8f 100644 --- a/scripts/tests/laws.lua +++ b/scripts/tests/laws.lua @@ -1,6 +1,9 @@ -require "lunit" - -module("tests.laws", package.seeall, lunit.testcase) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.laws", 'seeall') +else + module("tests.laws", 'seeall') +end function setup() eressea.free_game() @@ -115,3 +118,4 @@ function test_force_leave_postcombat() assert_equal(nil, u3.building) assert_equal(1, u3.number) end + diff --git a/scripts/tests/locale.lua b/scripts/tests/locale.lua index 2770beb3f..d1d35ded3 100644 --- a/scripts/tests/locale.lua +++ b/scripts/tests/locale.lua @@ -1,6 +1,9 @@ -require "lunit" - -module("tests.eressea.locale", package.seeall, lunit.testcase ) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.locale", 'seeall') +else + module("tests.locale", 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/magicbag.lua b/scripts/tests/magicbag.lua index b51925726..7e4629707 100644 --- a/scripts/tests/magicbag.lua +++ b/scripts/tests/magicbag.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.magicbag", package.seeall, lunit.testcase) +local tcname = 'tests.shared.magicbag' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local u diff --git a/scripts/tests/movement.lua b/scripts/tests/movement.lua index 22bd8d30e..943e912a8 100644 --- a/scripts/tests/movement.lua +++ b/scripts/tests/movement.lua @@ -1,6 +1,9 @@ -require "lunit" - -module("tests.movement", package.seeall, lunit.testcase) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.movement", 'seeall') +else + module("tests.movement", 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/orders.lua b/scripts/tests/orders.lua index 6dc191d6c..c63254315 100644 --- a/scripts/tests/orders.lua +++ b/scripts/tests/orders.lua @@ -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, 'seeall') +end local _G = _G -local eressea = eressea local default_ship = config.ships[1] local default_building = config.buildings[1] - -module('tests.eressea.orders', package.seeall, lunit.testcase) - local r, f, u function setup() diff --git a/scripts/tests/pool.lua b/scripts/tests/pool.lua index 0d24f8129..06f212f60 100644 --- a/scripts/tests/pool.lua +++ b/scripts/tests/pool.lua @@ -1,6 +1,9 @@ -require "lunit" - -module("tests.eressea.pool", package.seeall, lunit.testcase ) +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module("tests.pool", 'seeall') +else + module("tests.pool", 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/process.lua b/scripts/tests/process.lua index 1fc9a64f5..0b9b3e35b 100644 --- a/scripts/tests/process.lua +++ b/scripts/tests/process.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.process", package.seeall, lunit.testcase) +local tcname = 'tests.shared.process' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local u, r, f diff --git a/scripts/tests/production.lua b/scripts/tests/production.lua index c8a299676..b127fff02 100644 --- a/scripts/tests/production.lua +++ b/scripts/tests/production.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.production", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.production' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/regions.lua b/scripts/tests/regions.lua index 32197f0fd..e16dd1691 100644 --- a/scripts/tests/regions.lua +++ b/scripts/tests/regions.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.regions", package.seeall, lunit.testcase) +local tcname = 'tests.regions' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/report.lua b/scripts/tests/report.lua index b02f4a908..66eaa7d89 100644 --- a/scripts/tests/report.lua +++ b/scripts/tests/report.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.report", package.seeall, lunit.testcase) +local tcname = 'tests.shared.report' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/settings.lua b/scripts/tests/settings.lua index 8f2c5e637..f321a515b 100644 --- a/scripts/tests/settings.lua +++ b/scripts/tests/settings.lua @@ -1,6 +1,10 @@ -require 'lunit' - -module('tests.eressea.settings', package.seeall, lunit.testcase ) +local tcname = 'tests.settings' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/spells.lua b/scripts/tests/spells.lua index 27a5424f7..767df5d16 100644 --- a/scripts/tests/spells.lua +++ b/scripts/tests/spells.lua @@ -1,5 +1,10 @@ -require 'lunit' -module("tests.spells", package.seeall, lunit.testcase) +local tcname = 'tests.shared.spells' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/storage.lua b/scripts/tests/storage.lua index 32fbe9ef3..22af5a221 100644 --- a/scripts/tests/storage.lua +++ b/scripts/tests/storage.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.storage", package.seeall, lunit.testcase) +local tcname = 'tests.shared.storage' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/study.lua b/scripts/tests/study.lua index 32638ba90..21c70044e 100644 --- a/scripts/tests/study.lua +++ b/scripts/tests/study.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.eressea.study", package.seeall, lunit.testcase) +local tcname = 'tests.study' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() conf = [[{ diff --git a/scripts/tests/undead.lua b/scripts/tests/undead.lua index a3c541afa..4cb86fc67 100644 --- a/scripts/tests/undead.lua +++ b/scripts/tests/undead.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.undead", package.seeall, lunit.testcase) +local tcname = 'tests.shared.undead' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() diff --git a/scripts/tests/xmas.lua b/scripts/tests/xmas.lua index 8ae85fc76..10386c0ed 100644 --- a/scripts/tests/xmas.lua +++ b/scripts/tests/xmas.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.xmas", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.xmas' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() From 614209492fbcfb8a82a5c71e9045074b39f6577c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Apr 2020 20:58:52 +0200 Subject: [PATCH 21/26] use luarocks --- s/build | 2 +- s/cmake-init | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/s/build b/s/build index 709c92510..e54f83ace 100755 --- a/s/build +++ b/s/build @@ -1,6 +1,6 @@ #!/bin/sh ROOT=$(git rev-parse --show-toplevel) - +eval $(luarocks path) [ -z "$BUILD" ] && BUILD=Debug if [ -z "$JOBS" ] ; then if [ -e /usr/sbin/sysctl ]; then diff --git a/s/cmake-init b/s/cmake-init index a8228c379..00e6d3d06 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -6,6 +6,7 @@ pkg-config --exists sqlite3 && ERESSEA_DB=sqlite GETOPT=getopt GETOPT_LONG=1 +luarocks install lunitx --local if [ "Darwin" = "$(uname)" ] ; then if [ -x "/usr/local/opt/gnu-getopt/bin/getopt" ] ; then GETOPT="/usr/local/opt/gnu-getopt/bin/getopt" @@ -74,8 +75,6 @@ fi DEST=$(dirname $ROOT)/server -git submodule update --init - LUA_VERSION="5.2" LUA_INCLUDE=/usr/include LUA_DIR=/usr From 80f5ec9adae44b22ad2855d75a8217e7a2b854e2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 22 Apr 2020 03:03:44 +0200 Subject: [PATCH 22/26] make all test modules work with lunitx --- scripts/tests/common.lua | 304 -------------------------------- scripts/tests/e2/init.lua | 2 + scripts/tests/e3/buildings.lua | 10 +- scripts/tests/e3/init.lua | 2 + scripts/tests/e3/items.lua | 10 +- scripts/tests/e3/morale.lua | 14 +- scripts/tests/e3/parser.lua | 10 +- scripts/tests/e3/production.lua | 10 +- scripts/tests/e3/rules.lua | 10 +- scripts/tests/e3/spells-e2.lua | 10 +- scripts/tests/e3/spells.lua | 10 +- scripts/tests/e3/stealth.lua | 10 +- scripts/tests/parser.lua | 270 ++++++++++++++++++++++++++++ scripts/tests/recruit.lua | 46 +++++ 14 files changed, 385 insertions(+), 333 deletions(-) create mode 100644 scripts/tests/parser.lua create mode 100644 scripts/tests/recruit.lua diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index a11a28bed..10084f554 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -898,307 +898,3 @@ function test_walk_and_carry_the_cart() process_orders() assert_equal(1, u.region.x) 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 diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 0e93bdeae..6a4d7bca2 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -22,6 +22,8 @@ require 'tests.items' require 'tests.economy' require 'tests.orders' require 'tests.common' +require 'tests.recruit' +require 'tests.parser' require 'tests.report' require 'tests.storage' require 'tests.magicbag' diff --git a/scripts/tests/e3/buildings.lua b/scripts/tests/e3/buildings.lua index d5ea4fa51..fa9f5d16f 100644 --- a/scripts/tests/e3/buildings.lua +++ b/scripts/tests/e3/buildings.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.buildings", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.buildings' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/init.lua b/scripts/tests/e3/init.lua index 04b7da4a2..2ccd19139 100644 --- a/scripts/tests/e3/init.lua +++ b/scripts/tests/e3/init.lua @@ -10,6 +10,8 @@ require 'tests.spells' require 'tests.economy' require 'tests.orders' require 'tests.common' +require 'tests.recruit' +require 'tests.parser' require 'tests.items' require 'tests.magicbag' require 'tests.process' diff --git a/scripts/tests/e3/items.lua b/scripts/tests/e3/items.lua index 1df6be85a..1036f6ca4 100644 --- a/scripts/tests/e3/items.lua +++ b/scripts/tests/e3/items.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.items", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.items' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/morale.lua b/scripts/tests/e3/morale.lua index 1dd92a758..898e08674 100644 --- a/scripts/tests/e3/morale.lua +++ b/scripts/tests/e3/morale.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.morale", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.morale' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() @@ -171,7 +175,7 @@ function test_morale_change() run_a_turn() 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) u1.building = nil update_owners() @@ -186,7 +190,7 @@ function test_morale_change() run_a_turn() assert_equal(1, r.morale) - -- ohne herrscher ändert sich auch beschissene Moral nicht: + -- ohne herrscher ändert sich auch beschissene Moral nicht: r.morale = 0 run_a_turn() assert_equal(0, r.morale) diff --git a/scripts/tests/e3/parser.lua b/scripts/tests/e3/parser.lua index a56f08f76..52a082bf1 100644 --- a/scripts/tests/e3/parser.lua +++ b/scripts/tests/e3/parser.lua @@ -1,6 +1,10 @@ -require 'lunit' - -module('tests.e3.parser', package.seeall, lunit.testcase) +local tcname = 'tests.e3.parser' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/production.lua b/scripts/tests/e3/production.lua index 3469b06c4..1ff3e4260 100644 --- a/scripts/tests/e3/production.lua +++ b/scripts/tests/e3/production.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.production", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.production' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index aae3b3ab1..ae2766d2c 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.e3features", package.seeall, lunit.testcase) +local tcname = 'tests.e3.rules' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local settings diff --git a/scripts/tests/e3/spells-e2.lua b/scripts/tests/e3/spells-e2.lua index f232b8a1a..205450268 100644 --- a/scripts/tests/e3/spells-e2.lua +++ b/scripts/tests/e3/spells-e2.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.spells-e2", package.seeall, lunit.testcase) +local tcname = 'tests.e3.e2spells' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local r, f, u diff --git a/scripts/tests/e3/spells.lua b/scripts/tests/e3/spells.lua index 24f97c221..1d76bb3f1 100644 --- a/scripts/tests/e3/spells.lua +++ b/scripts/tests/e3/spells.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.spells", package.seeall, lunit.testcase) +local tcname = 'tests.e3.spells' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/stealth.lua b/scripts/tests/e3/stealth.lua index 866eb4f14..0c0df3c2b 100644 --- a/scripts/tests/e3/stealth.lua +++ b/scripts/tests/e3/stealth.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.stealth", package.seeall, lunit.testcase) +local tcname = 'tests.e3.stealth' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end local f local u diff --git a/scripts/tests/parser.lua b/scripts/tests/parser.lua new file mode 100644 index 000000000..835e08d92 --- /dev/null +++ b/scripts/tests/parser.lua @@ -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, '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 diff --git a/scripts/tests/recruit.lua b/scripts/tests/recruit.lua new file mode 100644 index 000000000..d783fc692 --- /dev/null +++ b/scripts/tests/recruit.lua @@ -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, '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 From 5010b2e8d1ed1a6c57af24fba0d241998f99841a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 21 Apr 2020 21:18:24 +0200 Subject: [PATCH 23/26] remove duplicate test functions --- scripts/tests/e2/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 6a4d7bca2..587c295c0 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -32,3 +32,4 @@ require 'tests.xmas' require 'tests.production' require 'tests.spells' require 'tests.undead' + From 649e662331d87e86f320400c355a67dbd5d4e84d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 2 May 2020 11:13:26 +0200 Subject: [PATCH 24/26] re-enable missing tests in E2 --- scripts/tests/e2/trees.lua | 10 +++++++--- scripts/tests/e2/trolls.lua | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/tests/e2/trees.lua b/scripts/tests/e2/trees.lua index 739d9f1e6..21f7611cd 100644 --- a/scripts/tests/e2/trees.lua +++ b/scripts/tests/e2/trees.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.trees", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.trees' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/trolls.lua b/scripts/tests/e2/trolls.lua index b6d96b015..811f1f736 100644 --- a/scripts/tests/e2/trolls.lua +++ b/scripts/tests/e2/trolls.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.trolls", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.trolls' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, 'seeall') +end function setup() eressea.free_game() From 6cf6f96fb8af700c663533c5fb4e575788d19ee3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 3 May 2020 16:52:40 +0200 Subject: [PATCH 25/26] Fix test to work with lunitx on Lua 5.1 --- scripts/run-tests-e2.lua | 3 +++ scripts/run-tests-e3.lua | 3 ++- scripts/run-tests.lua | 9 +++++---- scripts/tests/bindings.lua | 4 ++-- scripts/tests/common.lua | 4 ++-- scripts/tests/config.lua | 4 ++-- scripts/tests/e2/adamantium.lua | 4 ++-- scripts/tests/e2/allies.lua | 4 ++-- scripts/tests/e2/astral.lua | 4 ++-- scripts/tests/e2/buildings.lua | 4 ++-- scripts/tests/e2/carts.lua | 4 ++-- scripts/tests/e2/destroy.lua | 4 ++-- scripts/tests/e2/e2features.lua | 4 ++-- scripts/tests/e2/guard.lua | 4 ++-- scripts/tests/e2/insects.lua | 4 ++-- scripts/tests/e2/items.lua | 4 ++-- scripts/tests/e2/movement.lua | 4 ++-- scripts/tests/e2/production.lua | 4 ++-- scripts/tests/e2/quit.lua | 4 ++-- scripts/tests/e2/shiplanding.lua | 4 ++-- scripts/tests/e2/ships.lua | 4 ++-- scripts/tests/e2/spells.lua | 4 ++-- scripts/tests/e2/stealth.lua | 4 ++-- scripts/tests/e2/trees.lua | 4 ++-- scripts/tests/e2/trolls.lua | 4 ++-- scripts/tests/e2/undead.lua | 4 ++-- scripts/tests/e3/buildings.lua | 4 ++-- scripts/tests/e3/items.lua | 4 ++-- scripts/tests/e3/morale.lua | 4 ++-- scripts/tests/e3/parser.lua | 4 ++-- scripts/tests/e3/production.lua | 4 ++-- scripts/tests/e3/rules.lua | 4 ++-- scripts/tests/e3/spells-e2.lua | 4 ++-- scripts/tests/e3/spells.lua | 4 ++-- scripts/tests/e3/stealth.lua | 4 ++-- scripts/tests/economy.lua | 4 ++-- scripts/tests/faction.lua | 7 ++++--- scripts/tests/hunger.lua | 4 ++-- scripts/tests/items.lua | 2 +- scripts/tests/laws.lua | 7 ++++--- scripts/tests/locale.lua | 7 ++++--- scripts/tests/magicbag.lua | 4 ++-- scripts/tests/movement.lua | 5 +++-- scripts/tests/orders.lua | 4 ++-- scripts/tests/parser.lua | 4 ++-- scripts/tests/pool.lua | 7 ++++--- scripts/tests/process.lua | 4 ++-- scripts/tests/production.lua | 4 ++-- scripts/tests/recruit.lua | 4 ++-- scripts/tests/regions.lua | 4 ++-- scripts/tests/report.lua | 4 ++-- scripts/tests/settings.lua | 4 ++-- scripts/tests/spells.lua | 4 ++-- scripts/tests/storage.lua | 4 ++-- scripts/tests/study.lua | 4 ++-- scripts/tests/undead.lua | 4 ++-- scripts/tests/xmas.lua | 4 ++-- 57 files changed, 126 insertions(+), 116 deletions(-) diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua index 8ee3da320..dd0631086 100644 --- a/scripts/run-tests-e2.lua +++ b/scripts/run-tests-e2.lua @@ -2,7 +2,10 @@ -- 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' if config.install then path = config.install .. '/' .. path diff --git a/scripts/run-tests-e3.lua b/scripts/run-tests-e3.lua index 67ae860eb..e2a808147 100644 --- a/scripts/run-tests-e3.lua +++ b/scripts/run-tests-e3.lua @@ -2,7 +2,9 @@ -- 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' if config.install then @@ -12,7 +14,6 @@ package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' config.rules = 'e3' -lunit = require 'lunit' require 'eressea' require 'eressea.path' require 'eressea.xmlconf' diff --git a/scripts/run-tests.lua b/scripts/run-tests.lua index e81ceeede..e21ac3aa9 100644 --- a/scripts/run-tests.lua +++ b/scripts/run-tests.lua @@ -1,18 +1,19 @@ -- 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 +lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then +module = lunit.module +end + path = 'scripts' if config.install then path = config.install .. '/' .. path end package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' -lunit = require 'lunit' require 'eressea' require 'eressea.path' - -lunit = require('lunit') -module = lunit.module require 'tests' result = lunit.main() return result.errors + result.failed diff --git a/scripts/tests/bindings.lua b/scripts/tests/bindings.lua index 4e308de99..bdacf2660 100644 --- a/scripts/tests/bindings.lua +++ b/scripts/tests/bindings.lua @@ -1,9 +1,9 @@ local tcname = 'tests.bindings' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end local _G = _G diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 10084f554..058a53e2f 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.common' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end local function _test_create_ship(r) diff --git a/scripts/tests/config.lua b/scripts/tests/config.lua index cdf93ed2c..0ea46b133 100644 --- a/scripts/tests/config.lua +++ b/scripts/tests/config.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.config' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/adamantium.lua b/scripts/tests/e2/adamantium.lua index 0a0c2ec6b..49766cb52 100644 --- a/scripts/tests/e2/adamantium.lua +++ b/scripts/tests/e2/adamantium.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.adamantium' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/allies.lua b/scripts/tests/e2/allies.lua index 52f69ba98..977d75c61 100644 --- a/scripts/tests/e2/allies.lua +++ b/scripts/tests/e2/allies.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.allies' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/astral.lua b/scripts/tests/e2/astral.lua index c183c6207..20e53cb73 100644 --- a/scripts/tests/e2/astral.lua +++ b/scripts/tests/e2/astral.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.astral' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/buildings.lua b/scripts/tests/e2/buildings.lua index 0e735f0b9..3ae9c0337 100644 --- a/scripts/tests/e2/buildings.lua +++ b/scripts/tests/e2/buildings.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.buildings' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/carts.lua b/scripts/tests/e2/carts.lua index f649451e2..f96affba7 100644 --- a/scripts/tests/e2/carts.lua +++ b/scripts/tests/e2/carts.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.carts' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/destroy.lua b/scripts/tests/e2/destroy.lua index 7a02f0840..bbdab2b0d 100644 --- a/scripts/tests/e2/destroy.lua +++ b/scripts/tests/e2/destroy.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.destroy' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index dc083e69d..f0ee62414 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.features' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/guard.lua b/scripts/tests/e2/guard.lua index fd7f37ad0..0cc970f8c 100644 --- a/scripts/tests/e2/guard.lua +++ b/scripts/tests/e2/guard.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.guard' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/insects.lua b/scripts/tests/e2/insects.lua index 296c67e82..2e7fe5282 100644 --- a/scripts/tests/e2/insects.lua +++ b/scripts/tests/e2/insects.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.insects' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/items.lua b/scripts/tests/e2/items.lua index 9221d424b..ba0d305c8 100644 --- a/scripts/tests/e2/items.lua +++ b/scripts/tests/e2/items.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.items' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/movement.lua b/scripts/tests/e2/movement.lua index db9f4fbdd..d5f2f886f 100644 --- a/scripts/tests/e2/movement.lua +++ b/scripts/tests/e2/movement.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.movement' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/production.lua b/scripts/tests/e2/production.lua index 7941c1af4..092e44dd6 100644 --- a/scripts/tests/e2/production.lua +++ b/scripts/tests/e2/production.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.production' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/quit.lua b/scripts/tests/e2/quit.lua index 9d02c49eb..f1a8e6a0c 100644 --- a/scripts/tests/e2/quit.lua +++ b/scripts/tests/e2/quit.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.quit' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function test_quit_faction() diff --git a/scripts/tests/e2/shiplanding.lua b/scripts/tests/e2/shiplanding.lua index 7b146f2e6..f5eb9f400 100644 --- a/scripts/tests/e2/shiplanding.lua +++ b/scripts/tests/e2/shiplanding.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.shiplanding' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/ships.lua b/scripts/tests/e2/ships.lua index 2f5db607d..db44871b3 100644 --- a/scripts/tests/e2/ships.lua +++ b/scripts/tests/e2/ships.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.ships' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/spells.lua b/scripts/tests/e2/spells.lua index cf8814de2..2a5c50b2c 100644 --- a/scripts/tests/e2/spells.lua +++ b/scripts/tests/e2/spells.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.spells' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/stealth.lua b/scripts/tests/e2/stealth.lua index 60b66e83f..6a8fcd9f9 100644 --- a/scripts/tests/e2/stealth.lua +++ b/scripts/tests/e2/stealth.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.stealth' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end local f diff --git a/scripts/tests/e2/trees.lua b/scripts/tests/e2/trees.lua index 21f7611cd..b5bfa1f6b 100644 --- a/scripts/tests/e2/trees.lua +++ b/scripts/tests/e2/trees.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.trees' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/trolls.lua b/scripts/tests/e2/trolls.lua index 811f1f736..cc60ade2d 100644 --- a/scripts/tests/e2/trolls.lua +++ b/scripts/tests/e2/trolls.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.trolls' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e2/undead.lua b/scripts/tests/e2/undead.lua index d43f67164..5b8170ef6 100644 --- a/scripts/tests/e2/undead.lua +++ b/scripts/tests/e2/undead.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e2.undead' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e3/buildings.lua b/scripts/tests/e3/buildings.lua index fa9f5d16f..1258f9824 100644 --- a/scripts/tests/e3/buildings.lua +++ b/scripts/tests/e3/buildings.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e3.buildings' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e3/items.lua b/scripts/tests/e3/items.lua index 1036f6ca4..60fce6b7a 100644 --- a/scripts/tests/e3/items.lua +++ b/scripts/tests/e3/items.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e3.items' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e3/morale.lua b/scripts/tests/e3/morale.lua index 898e08674..60ed55965 100644 --- a/scripts/tests/e3/morale.lua +++ b/scripts/tests/e3/morale.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e3.morale' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e3/parser.lua b/scripts/tests/e3/parser.lua index 52a082bf1..862f9d946 100644 --- a/scripts/tests/e3/parser.lua +++ b/scripts/tests/e3/parser.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e3.parser' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e3/production.lua b/scripts/tests/e3/production.lua index 1ff3e4260..9a631c755 100644 --- a/scripts/tests/e3/production.lua +++ b/scripts/tests/e3/production.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e3.production' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index ae2766d2c..89a6d822a 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e3.rules' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end local settings diff --git a/scripts/tests/e3/spells-e2.lua b/scripts/tests/e3/spells-e2.lua index 205450268..0e2ab4e6d 100644 --- a/scripts/tests/e3/spells-e2.lua +++ b/scripts/tests/e3/spells-e2.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e3.e2spells' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end local r, f, u diff --git a/scripts/tests/e3/spells.lua b/scripts/tests/e3/spells.lua index 1d76bb3f1..fb68ba3d1 100644 --- a/scripts/tests/e3/spells.lua +++ b/scripts/tests/e3/spells.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e3.spells' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/e3/stealth.lua b/scripts/tests/e3/stealth.lua index 0c0df3c2b..1db6436a1 100644 --- a/scripts/tests/e3/stealth.lua +++ b/scripts/tests/e3/stealth.lua @@ -1,9 +1,9 @@ local tcname = 'tests.e3.stealth' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end local f diff --git a/scripts/tests/economy.lua b/scripts/tests/economy.lua index 17dcbfc61..271d245d6 100644 --- a/scripts/tests/economy.lua +++ b/scripts/tests/economy.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.economy' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index 7247498ea..fe728e9a0 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -1,8 +1,9 @@ -local lunit = require("lunit") +local tcname = 'tests.faction' +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then - _ENV = module("tests.faction", 'seeall') + _ENV = module(tcname, 'seeall') else - module("tests.faction", 'seeall') + module(tcname, lunit.testcase, package.seeall) end local f diff --git a/scripts/tests/hunger.lua b/scripts/tests/hunger.lua index fed24440e..750d7c74b 100644 --- a/scripts/tests/hunger.lua +++ b/scripts/tests/hunger.lua @@ -1,9 +1,9 @@ local tcname = 'tests.hunger' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/items.lua b/scripts/tests/items.lua index e1e780f3c..c6252db17 100644 --- a/scripts/tests/items.lua +++ b/scripts/tests/items.lua @@ -3,7 +3,7 @@ local lunit = require("lunit") if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/laws.lua b/scripts/tests/laws.lua index e22bc5d8f..d9a379319 100644 --- a/scripts/tests/laws.lua +++ b/scripts/tests/laws.lua @@ -1,8 +1,9 @@ -local lunit = require("lunit") +local tcname = 'tests.laws' +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then - _ENV = module("tests.laws", 'seeall') + _ENV = module(tcname, 'seeall') else - module("tests.laws", 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/locale.lua b/scripts/tests/locale.lua index d1d35ded3..2b4dbea8c 100644 --- a/scripts/tests/locale.lua +++ b/scripts/tests/locale.lua @@ -1,8 +1,9 @@ -local lunit = require("lunit") +local tcname = 'tests.locale' +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then - _ENV = module("tests.locale", 'seeall') + _ENV = module(tcname, 'seeall') else - module("tests.locale", 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/magicbag.lua b/scripts/tests/magicbag.lua index 7e4629707..e34d5fba5 100644 --- a/scripts/tests/magicbag.lua +++ b/scripts/tests/magicbag.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.magicbag' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end local u diff --git a/scripts/tests/movement.lua b/scripts/tests/movement.lua index 943e912a8..16868dfec 100644 --- a/scripts/tests/movement.lua +++ b/scripts/tests/movement.lua @@ -1,8 +1,9 @@ +local tcname = 'tests.movement' local lunit = require("lunit") if _VERSION >= 'Lua 5.2' then - _ENV = module("tests.movement", 'seeall') + _ENV = module(tcname , 'seeall') else - module("tests.movement", 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/orders.lua b/scripts/tests/orders.lua index c63254315..d3ade71d2 100644 --- a/scripts/tests/orders.lua +++ b/scripts/tests/orders.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.orders' local lunit = require("lunit") if _VERSION >= 'Lua 5.2' then - _ENV = module(tcname, 'seeall') + _ENV = module(tcname , 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end local _G = _G diff --git a/scripts/tests/parser.lua b/scripts/tests/parser.lua index 835e08d92..7cd42b17f 100644 --- a/scripts/tests/parser.lua +++ b/scripts/tests/parser.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.parser' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/pool.lua b/scripts/tests/pool.lua index 06f212f60..398ff6fa2 100644 --- a/scripts/tests/pool.lua +++ b/scripts/tests/pool.lua @@ -1,8 +1,9 @@ -local lunit = require("lunit") +local tcname = 'tests.pool' +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then - _ENV = module("tests.pool", 'seeall') + _ENV = module(tcname, 'seeall') else - module("tests.pool", 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/process.lua b/scripts/tests/process.lua index 0b9b3e35b..b9fcf5055 100644 --- a/scripts/tests/process.lua +++ b/scripts/tests/process.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.process' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end local u, r, f diff --git a/scripts/tests/production.lua b/scripts/tests/production.lua index b127fff02..bea8fcf33 100644 --- a/scripts/tests/production.lua +++ b/scripts/tests/production.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.production' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/recruit.lua b/scripts/tests/recruit.lua index d783fc692..6a0cc5de6 100644 --- a/scripts/tests/recruit.lua +++ b/scripts/tests/recruit.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.recruit' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/regions.lua b/scripts/tests/regions.lua index e16dd1691..881930a40 100644 --- a/scripts/tests/regions.lua +++ b/scripts/tests/regions.lua @@ -1,9 +1,9 @@ local tcname = 'tests.regions' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/report.lua b/scripts/tests/report.lua index 66eaa7d89..466e77e1a 100644 --- a/scripts/tests/report.lua +++ b/scripts/tests/report.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.report' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/settings.lua b/scripts/tests/settings.lua index f321a515b..ec4cac2d1 100644 --- a/scripts/tests/settings.lua +++ b/scripts/tests/settings.lua @@ -1,9 +1,9 @@ local tcname = 'tests.settings' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/spells.lua b/scripts/tests/spells.lua index 767df5d16..b0def9560 100644 --- a/scripts/tests/spells.lua +++ b/scripts/tests/spells.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.spells' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/storage.lua b/scripts/tests/storage.lua index 22af5a221..d51912694 100644 --- a/scripts/tests/storage.lua +++ b/scripts/tests/storage.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.storage' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/study.lua b/scripts/tests/study.lua index 21c70044e..51065b12a 100644 --- a/scripts/tests/study.lua +++ b/scripts/tests/study.lua @@ -1,9 +1,9 @@ local tcname = 'tests.study' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/undead.lua b/scripts/tests/undead.lua index 4cb86fc67..43d910c9f 100644 --- a/scripts/tests/undead.lua +++ b/scripts/tests/undead.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.undead' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() diff --git a/scripts/tests/xmas.lua b/scripts/tests/xmas.lua index 10386c0ed..58400aa9f 100644 --- a/scripts/tests/xmas.lua +++ b/scripts/tests/xmas.lua @@ -1,9 +1,9 @@ local tcname = 'tests.shared.xmas' -local lunit = require("lunit") +local lunit = require('lunit') if _VERSION >= 'Lua 5.2' then _ENV = module(tcname, 'seeall') else - module(tcname, 'seeall') + module(tcname, lunit.testcase, package.seeall) end function setup() From 4f2a34ae10d32eb22016d76c2fcb723d1ddc80c7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 3 May 2020 16:59:28 +0200 Subject: [PATCH 26/26] make cmake-init executable --- s/cmake-init | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 s/cmake-init diff --git a/s/cmake-init b/s/cmake-init old mode 100644 new mode 100755