From 316c0c7224301a2de41477e64d04763eefb3d4bd Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 25 Mar 2024 20:45:31 +0100 Subject: [PATCH] Add workflow that runs simple test with the engine present --- .github/workflows/test.yml | 11 +++++++++++ mods/default/init.lua | 16 ++++++++++++++++ utils/test/minetest.conf | 1 + utils/test/run.sh | 19 +++++++++++++++++++ utils/test/world.mt | 7 +++++++ 5 files changed, 54 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 utils/test/minetest.conf create mode 100755 utils/test/run.sh create mode 100644 utils/test/world.mt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..8128ba34 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,11 @@ +name: test +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + + - run: ./utils/test/run.sh diff --git a/mods/default/init.lua b/mods/default/init.lua index 993316b8..878c5261 100644 --- a/mods/default/init.lua +++ b/mods/default/init.lua @@ -77,3 +77,19 @@ dofile(default_path.."/crafting.lua") dofile(default_path.."/mapgen.lua") dofile(default_path.."/aliases.lua") dofile(default_path.."/legacy.lua") + +-- Smoke test that is run via ./util/test/run.sh +if minetest.settings:get_bool("minetest_game_smoke_test") then + minetest.after(0, function() + minetest.emerge_area(vector.new(0, 0, 0), vector.new(32, 32, 32)) + local pos = vector.new(9, 9, 9) + local function check() + if minetest.get_node(pos).name ~= "ignore" then + minetest.request_shutdown() + return + end + minetest.after(0, check) + end + check() + end) +end diff --git a/utils/test/minetest.conf b/utils/test/minetest.conf new file mode 100644 index 00000000..5bbe6e27 --- /dev/null +++ b/utils/test/minetest.conf @@ -0,0 +1 @@ +minetest_game_smoke_test = true diff --git a/utils/test/run.sh b/utils/test/run.sh new file mode 100755 index 00000000..284b2daf --- /dev/null +++ b/utils/test/run.sh @@ -0,0 +1,19 @@ +#!/bin/bash -e +world=$(mktemp -d) +trap 'rm -rf "$world" || :' EXIT + +[ -f game.conf ] || { echo "Must be run in game root folder." >&2; exit 1; } + +cp -v utils/test/world.mt "$world/" +chmod -R a+rwX "$world" # needed because server runs as unprivileged user inside container + +vol=( + -v "$PWD/utils/test/minetest.conf":/etc/minetest/minetest.conf + --tmpfs /var/lib/minetest/.minetest + -v "$PWD":/var/lib/minetest/.minetest/games/minetest_game + -v "$world":/var/lib/minetest/.minetest/world +) +[ -z "$DOCKER_IMAGE" ] && DOCKER_IMAGE="ghcr.io/minetest/minetest:master" +docker run --rm -i "${vol[@]}" "$DOCKER_IMAGE" + +exit 0 diff --git a/utils/test/world.mt b/utils/test/world.mt new file mode 100644 index 00000000..d386d77a --- /dev/null +++ b/utils/test/world.mt @@ -0,0 +1,7 @@ +auth_backend = sqlite3 +backend = sqlite3 +creative_mode = false +enable_damage = true +gameid = minetest +mod_storage_backend = sqlite3 +player_backend = sqlite3