add luacheck and integration test workflows / fix luacheck errors

partially attends to https://github.com/pandorabox-io/pandorabox.io/issues/444 (the ObjectRef issue)
This commit is contained in:
BuckarooBanzay 2020-02-13 12:26:32 +01:00
parent f3ad7ec6f1
commit f81cb10f20
10 changed files with 152 additions and 28 deletions

14
.github/workflows/integration-test.yml vendored Normal file

@ -0,0 +1,14 @@
name: integration-test
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: integration-test
run: ./integration-test.sh

17
.github/workflows/luacheck.yml vendored Normal file

@ -0,0 +1,17 @@
name: luacheck
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: apt
run: sudo apt-get install -y luarocks
- name: luacheck install
run: luarocks install --local luacheck
- name: luacheck run
run: $HOME/.luarocks/bin/luacheck ./

34
.luacheckrc Normal file

@ -0,0 +1,34 @@
unused_args = false
globals = {
"wieldview",
"armor",
"armor_i18n",
"inventory_plus"
}
read_globals = {
-- Stdlib
string = {fields = {"split"}},
table = {fields = {"copy", "getn"}},
-- Minetest
"vector", "ItemStack",
"dump", "VoxelArea",
-- deps
"default",
"minetest",
"unified_inventory",
"intllib",
"wardrobe",
"player_monoids",
"armor_monoid",
"sfinv",
"ARMOR_MATERIALS",
"ARMOR_FIRE_NODES",
"pova",
"skins",
"u_skins"
}

@ -185,7 +185,6 @@ armor.set_player_armor = function(self, player)
local material = {count=1} local material = {count=1}
local preview = armor:get_preview(name) local preview = armor:get_preview(name)
local texture = "3d_armor_trans.png" local texture = "3d_armor_trans.png"
local textures = {}
local physics = {} local physics = {}
local attributes = {} local attributes = {}
local levels = {} local levels = {}
@ -324,8 +323,8 @@ armor.punch = function(self, player, hitter, time_from_last_punch, tool_capabili
local list = armor_inv:get_list("armor") local list = armor_inv:get_list("armor")
for i, stack in pairs(list) do for i, stack in pairs(list) do
if stack:get_count() == 1 then if stack:get_count() == 1 then
local name = stack:get_name() local itemname = stack:get_name()
local use = minetest.get_item_group(name, "armor_use") or 0 local use = minetest.get_item_group(itemname, "armor_use") or 0
local damage = use > 0 local damage = use > 0
local def = stack:get_definition() or {} local def = stack:get_definition() or {}
if type(def.on_punched) == "function" then if type(def.on_punched) == "function" then
@ -373,7 +372,7 @@ armor.punch = function(self, player, hitter, time_from_last_punch, tool_capabili
end end
end end
if damage == true and hitter == "fire" then if damage == true and hitter == "fire" then
damage = minetest.get_item_group(name, "flammable") > 0 damage = minetest.get_item_group(itemname, "flammable") > 0
end end
if damage == true then if damage == true then
self:damage(player, i, stack, use) self:damage(player, i, stack, use)

@ -15,19 +15,23 @@ local F = minetest.formspec_escape
dofile(modpath.."/api.lua") dofile(modpath.."/api.lua")
-- integration test
if minetest.settings:get_bool("enable_3d_armor_integration_test") then
dofile(modpath.."/integration_test.lua")
end
-- Legacy Config Support -- Legacy Config Support
local input = io.open(modpath.."/armor.conf", "r") local input = io.open(modpath.."/armor.conf", "r")
if input then if input then
dofile(modpath.."/armor.conf") dofile(modpath.."/armor.conf")
input:close() input:close()
input = nil
end end
input = io.open(worldpath.."/armor.conf", "r") input = io.open(worldpath.."/armor.conf", "r")
if input then if input then
dofile(worldpath.."/armor.conf") dofile(worldpath.."/armor.conf")
input:close() input:close()
input = nil
end end
for name, _ in pairs(armor.config) do for name, _ in pairs(armor.config) do
local global = "ARMOR_"..name:upper() local global = "ARMOR_"..name:upper()
@ -169,9 +173,9 @@ local function validate_armor_inventory(player)
end end
end end
local function init_player_armor(player) local function init_player_armor(initplayer)
local name = player:get_player_name() local name = initplayer:get_player_name()
local pos = player:get_pos() local pos = initplayer:get_pos()
if not name or not pos then if not name or not pos then
return false return false
end end
@ -214,20 +218,20 @@ local function init_player_armor(player)
end, end,
}, name) }, name)
armor_inv:set_size("armor", 6) armor_inv:set_size("armor", 6)
if not armor:load_armor_inventory(player) and armor.migrate_old_inventory then if not armor:load_armor_inventory(initplayer) and armor.migrate_old_inventory then
local player_inv = player:get_inventory() local player_inv = initplayer:get_inventory()
player_inv:set_size("armor", 6) player_inv:set_size("armor", 6)
for i=1, 6 do for i=1, 6 do
local stack = player_inv:get_stack("armor", i) local stack = player_inv:get_stack("armor", i)
armor_inv:set_stack("armor", i, stack) armor_inv:set_stack("armor", i, stack)
end end
armor:save_armor_inventory(player) armor:save_armor_inventory(initplayer)
player_inv:set_size("armor", 0) player_inv:set_size("armor", 0)
end end
for i=1, 6 do for i=1, 6 do
local stack = armor_inv:get_stack("armor", i) local stack = armor_inv:get_stack("armor", i)
if stack:get_count() > 0 then if stack:get_count() > 0 then
armor:run_callbacks("on_equip", player, i, stack) armor:run_callbacks("on_equip", initplayer, i, stack)
end end
end end
armor.def[name] = { armor.def[name] = {
@ -263,7 +267,7 @@ local function init_player_armor(player)
end end
end end
end end
armor:set_player_armor(player) armor:set_player_armor(initplayer)
return true return true
end end
@ -291,24 +295,31 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if not name then if not name then
return return
end end
local player_name = player:get_player_name()
for field, _ in pairs(fields) do for field, _ in pairs(fields) do
if string.find(field, "skins_set") then if string.find(field, "skins_set") then
minetest.after(0, function(player) minetest.after(0, function()
local skin = armor:get_player_skin(name) local pplayer = minetest.get_player_by_name(player_name)
armor.textures[name].skin = skin if player then
armor:set_player_armor(player) local skin = armor:get_player_skin(name)
end, player) armor.textures[name].skin = skin
armor:set_player_armor(pplayer)
end
end)
end end
end end
end) end)
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
default.player_set_model(player, "3d_armor_character.b3d") default.player_set_model(player, "3d_armor_character.b3d")
minetest.after(0, function(player) local player_name = player:get_player_name()
if init_player_armor(player) == false then
pending_players[player] = 0 minetest.after(0, function()
local pplayer = minetest.get_player_by_name(player_name)
if pplayer and init_player_armor(pplayer) == false then
pending_players[pplayer] = 0
end end
end, player) end)
end) end)
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)

@ -0,0 +1,25 @@
minetest.log("warning", "[TEST] integration-test enabled!")
minetest.register_on_mods_loaded(function()
minetest.after(1, function()
local data = minetest.write_json({ success = true }, true);
local file = io.open(minetest.get_worldpath().."/integration_test.json", "w" );
if file then
file:write(data)
file:close()
end
file = io.open(minetest.get_worldpath().."/registered_nodes.txt", "w" );
if file then
for name in pairs(minetest.registered_nodes) do
file:write(name .. '\n')
end
file:close()
end
minetest.log("warning", "[TEST] integration tests done!")
minetest.request_shutdown("success")
end)
end)

@ -1,6 +1,9 @@
Modpack - 3d Armor [0.4.13] Modpack - 3d Armor [0.4.13]
=========================== ===========================
![](https://github.com/mt-mods/3d_armor/workflows/luacheck/badge.svg)
![](https://github.com/mt-mods/3d_armor/workflows/integration-test/badge.svg)
### Table of Contents ### Table of Contents
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

20
integration-test.sh Executable file

@ -0,0 +1,20 @@
#!/bin/sh
# simple integration test
CFG=/tmp/minetest.conf
MTDIR=/tmp/mt
WORLDDIR=${MTDIR}/worlds/world
cat <<EOF > ${CFG}
enable_3d_armor_integration_test = true
EOF
mkdir -p ${WORLDDIR}
chmod 777 ${MTDIR} -R
docker run --rm -i \
-v ${CFG}:/etc/minetest/minetest.conf:ro \
-v ${MTDIR}:/var/lib/minetest/.minetest \
-v $(pwd):/var/lib/minetest/.minetest/worlds/world/worldmods/3d_armor \
registry.gitlab.com/minetest/minetest/server:5.0.1
test -f ${WORLDDIR}/integration_test.json && exit 0 || exit 1

@ -2,7 +2,6 @@
local S = armor_i18n.gettext local S = armor_i18n.gettext
local disable_sounds = minetest.settings:get_bool("shields_disable_sounds") local disable_sounds = minetest.settings:get_bool("shields_disable_sounds")
local use_moreores = minetest.get_modpath("moreores")
local function play_sound_effect(player, name) local function play_sound_effect(player, name)
if not disable_sounds and player then if not disable_sounds and player then
local pos = player:get_pos() local pos = player:get_pos()

@ -66,9 +66,12 @@ end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
wieldview.wielded_item[name] = "" wieldview.wielded_item[name] = ""
minetest.after(0, function(player) minetest.after(0, function()
wieldview:update_wielded_item(player) local pplayer = minetest.get_player_by_name(name)
end, player) if player then
wieldview:update_wielded_item(pplayer)
end
end)
end) end)
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
@ -80,4 +83,3 @@ minetest.register_globalstep(function(dtime)
time = 0 time = 0
end end
end) end)