From 9b36a7acc0ec9ccf8d9d2dbed0a1b7e8ebb66ffe Mon Sep 17 00:00:00 2001 From: Buckaroo Banzai <39065740+BuckarooBanzay@users.noreply.github.com> Date: Sun, 21 Apr 2024 09:48:13 +0200 Subject: [PATCH] use `mtt` for testing (#113) * use `mtt` for testing * fix modname typo --------- Co-authored-by: BuckarooBanzay --- .github/workflows/integration-test.yml | 14 ----- .github/workflows/test.yml | 15 +++++ .luacheckrc | 3 +- init.lua | 8 +-- integration-test.sh | 27 --------- integration_test.lua | 83 -------------------------- mod.conf | 3 +- mtt.lua | 41 +++++++++++++ 8 files changed, 64 insertions(+), 130 deletions(-) delete mode 100644 .github/workflows/integration-test.yml create mode 100644 .github/workflows/test.yml delete mode 100755 integration-test.sh delete mode 100644 integration_test.lua create mode 100644 mtt.lua diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml deleted file mode 100644 index eb104ac..0000000 --- a/.github/workflows/integration-test.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: integration-test - -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@master - - - name: integration-test - run: ./integration-test.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..f581d5a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,15 @@ +name: test + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: buckaroobanzay/mtt@main + with: + modname: jumpdrive + git_dependencies: | + https://github.com/minetest-mods/areas.git diff --git a/.luacheckrc b/.luacheckrc index 594fd69..353e7cc 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -34,5 +34,6 @@ read_globals = { "player_monoids", "vizlib", "mcl_sounds", - "mcl_formspec" + "mcl_formspec", + "mtt" } diff --git a/init.lua b/init.lua index 127b4fb..14b70b3 100644 --- a/init.lua +++ b/init.lua @@ -22,11 +22,11 @@ jumpdrive = { jumpdrive.sounds = {} if minetest.get_modpath("default") then - jumpdrive.sounds = default + jumpdrive.sounds = default end if minetest.get_modpath("mcl_sounds") then - jumpdrive.sounds = mcl_sounds + jumpdrive.sounds = mcl_sounds end local MP = minetest.get_modpath("jumpdrive") @@ -81,8 +81,8 @@ if minetest.get_modpath("monitoring") then dofile(MP.."/metrics.lua") end -if minetest.settings:get_bool("enable_jumpdrive_integration_test") then - dofile(MP.."/integration_test.lua") +if minetest.get_modpath("mtt") and mtt.enabled then + dofile(MP.."/mtt.lua") end print("[OK] Jumpdrive") diff --git a/integration-test.sh b/integration-test.sh deleted file mode 100755 index ad141cb..0000000 --- a/integration-test.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -# simple integration test - -CFG=/tmp/minetest.conf -MTDIR=/tmp/mt -WORLDDIR=${MTDIR}/worlds/world -WORLDMODSDIR=/tmp/worldmods - -cat < ${CFG} - enable_jumpdrive_integration_test = true -EOF - -# clone repos for testing -mkdir -p ${WORLDMODSDIR} -rm ${WORLDMODSDIR}/jumpdrive -rf -cp -R . ${WORLDMODSDIR}/jumpdrive -git clone https://github.com/minetest-mods/areas.git ${WORLDMODSDIR}/areas - -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 ${WORLDMODSDIR}:/var/lib/minetest/.minetest/worlds/world/worldmods \ - registry.gitlab.com/minetest/minetest/server:5.3.0 - -test -f ${WORLDDIR}/integration_test.json && exit 0 || exit 1 diff --git a/integration_test.lua b/integration_test.lua deleted file mode 100644 index ea52e9d..0000000 --- a/integration_test.lua +++ /dev/null @@ -1,83 +0,0 @@ - -minetest.log("warning", "[TEST] integration-test enabled!") - -local function execute_move(callback) - local source_pos1 = { x=0, y=0, z=0 } - local source_pos2 = { x=5, y=5, z=5 } - local target_pos1 = { x=10, y=10, z=10 } - local target_pos2 = { x=15, y=15, z=15 } - - minetest.get_voxel_manip(source_pos1, source_pos1) - local src_node = minetest.get_node(source_pos1) - - areas:add("dummy", "landscape", source_pos1, source_pos2) - areas:save() - - assert(not minetest.is_protected(source_pos1, "dummy")) - assert(minetest.is_protected(source_pos1, "dummy2")) - - jumpdrive.move(source_pos1, source_pos2, target_pos1, target_pos2) - - assert(not minetest.is_protected(source_pos1, "dummy")) - assert(not minetest.is_protected(source_pos1, "dummy2")) - - assert(not minetest.is_protected(target_pos1, "dummy")) - assert(minetest.is_protected(target_pos1, "dummy2")) - - minetest.get_voxel_manip(target_pos1, target_pos1) - local target_node = minetest.get_node(target_pos1) - - if target_node.name ~= src_node.name then - error("moved node name does not match") - end - - if target_node.param2 ~= src_node.param2 then - error("moved param2 does not match") - end - - callback() -end - -local function execute_mapgen(callback) - local pos1 = { x=-50, y=-10, z=-50 } - local pos2 = { x=50, y=50, z=50 } - minetest.emerge_area(pos1, pos2, callback) -end - -local function execute_test(callback) - execute_mapgen(function(blockpos, _, calls_remaining) - minetest.log("action", "Emerged: " .. minetest.pos_to_string(blockpos)) - if calls_remaining > 0 then - return - end - - jumpdrive.mapgen.reset() - execute_move(function() - callback() - end) - end) -end - -minetest.register_on_mods_loaded(function() - minetest.after(1, function() - execute_test(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) -end) diff --git a/mod.conf b/mod.conf index d94e32d..f526701 100644 --- a/mod.conf +++ b/mod.conf @@ -23,5 +23,6 @@ player_monoids, planet_mars, vizlib, mcl_sounds, -mcl_formspec +mcl_formspec, +mtt """ \ No newline at end of file diff --git a/mtt.lua b/mtt.lua new file mode 100644 index 0000000..8b239e4 --- /dev/null +++ b/mtt.lua @@ -0,0 +1,41 @@ +local pos1 = { x=-50, y=-10, z=-50 } +local pos2 = { x=50, y=50, z=50 } + +mtt.emerge_area(pos1, pos2) + +mtt.register("basic move-test", function(callback) + local source_pos1 = { x=0, y=0, z=0 } + local source_pos2 = { x=5, y=5, z=5 } + local target_pos1 = { x=10, y=10, z=10 } + local target_pos2 = { x=15, y=15, z=15 } + + minetest.get_voxel_manip(source_pos1, source_pos1) + local src_node = minetest.get_node(source_pos1) + + areas:add("dummy", "landscape", source_pos1, source_pos2) + areas:save() + + assert(not minetest.is_protected(source_pos1, "dummy")) + assert(minetest.is_protected(source_pos1, "dummy2")) + + jumpdrive.move(source_pos1, source_pos2, target_pos1, target_pos2) + + assert(not minetest.is_protected(source_pos1, "dummy")) + assert(not minetest.is_protected(source_pos1, "dummy2")) + + assert(not minetest.is_protected(target_pos1, "dummy")) + assert(minetest.is_protected(target_pos1, "dummy2")) + + minetest.get_voxel_manip(target_pos1, target_pos1) + local target_node = minetest.get_node(target_pos1) + + if target_node.name ~= src_node.name then + error("moved node name does not match") + end + + if target_node.param2 ~= src_node.param2 then + error("moved param2 does not match") + end + + callback() +end)