mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2025-10-16 07:35:27 +02:00
Add some basic testing to worldedit_commands
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
tempdir=$(mktemp -d)
|
tempdir=$(mktemp -d)
|
||||||
confpath=$tempdir/minetest.conf
|
confpath=$tempdir/minetest.conf
|
||||||
worldpath=$tempdir/world
|
worldpath=$tempdir/world
|
||||||
|
modlist=(
|
||||||
|
worldedit
|
||||||
|
worldedit_commands
|
||||||
|
)
|
||||||
trap 'rm -rf "$tempdir"' EXIT
|
trap 'rm -rf "$tempdir"' EXIT
|
||||||
|
|
||||||
[ -f worldedit/mod.conf ] || { echo "Must be run in modpack root folder." >&2; exit 1; }
|
[ -f worldedit/mod.conf ] || { echo "Must be run in modpack root folder." >&2; exit 1; }
|
||||||
@@ -26,15 +30,19 @@ if [ -z "$mtserver" ]; then
|
|||||||
vol=(
|
vol=(
|
||||||
-v "$confpath":/etc/minetest/minetest.conf
|
-v "$confpath":/etc/minetest/minetest.conf
|
||||||
-v "$tempdir":/var/lib/minetest/.minetest
|
-v "$tempdir":/var/lib/minetest/.minetest
|
||||||
-v "$PWD/worldedit":/var/lib/minetest/.minetest/world/worldmods/worldedit
|
|
||||||
)
|
)
|
||||||
|
for mod in "${modlist[@]}"; do
|
||||||
|
vol+=(-v "$PWD/$mod":/var/lib/minetest/.minetest/world/worldmods/$mod)
|
||||||
|
done
|
||||||
[ -d minetest_game ] && vol+=(
|
[ -d minetest_game ] && vol+=(
|
||||||
-v "$PWD/minetest_game":/var/lib/minetest/.minetest/games/minetest_game
|
-v "$PWD/minetest_game":/var/lib/minetest/.minetest/games/minetest_game
|
||||||
)
|
)
|
||||||
docker run --rm -i "${vol[@]}" "$DOCKER_IMAGE"
|
docker run --rm -i "${vol[@]}" "$DOCKER_IMAGE"
|
||||||
else
|
else
|
||||||
mkdir $worldpath/worldmods
|
mkdir $worldpath/worldmods
|
||||||
ln -s "$PWD/worldedit" $worldpath/worldmods/worldedit
|
for mod in "${modlist[@]}"; do
|
||||||
|
ln -s "$PWD/$mod" $worldpath/worldmods/$mod
|
||||||
|
done
|
||||||
$mtserver --config "$confpath" --world "$worldpath" --logfile /dev/null
|
$mtserver --config "$confpath" --world "$worldpath" --logfile /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@@ -152,6 +152,10 @@ do
|
|||||||
}) do
|
}) do
|
||||||
dofile(modpath .. "/" .. name .. ".lua")
|
dofile(modpath .. "/" .. name .. ".lua")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if worldedit.register_test then
|
||||||
|
dofile(modpath .. "/test/init.lua")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -344,4 +348,3 @@ worldedit.register_command("reset", {
|
|||||||
return true, S("region reset")
|
return true, S("region reset")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
86
worldedit_commands/test/init.lua
Normal file
86
worldedit_commands/test/init.lua
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
local register_test = worldedit.register_test
|
||||||
|
|
||||||
|
-- Basic test that just checks if certain parameter combinations
|
||||||
|
-- parse correctly (valid or invalid)
|
||||||
|
local make_parsing_test = function(cmd, valid, invalid)
|
||||||
|
return function()
|
||||||
|
local def = worldedit.registered_commands[cmd]
|
||||||
|
assert(def, "Command not defined")
|
||||||
|
for _, param in ipairs(valid or {}) do
|
||||||
|
local parsed = {def.parse(param)}
|
||||||
|
assert(parsed[1], string.format("Did not parse: %q", param))
|
||||||
|
end
|
||||||
|
for _, param in ipairs(invalid or {}) do
|
||||||
|
local parsed = {def.parse(param)}
|
||||||
|
assert(not parsed[1], string.format("Did parse: %q", param))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
register_test("Command parsing")
|
||||||
|
register_test("//set", make_parsing_test("set", {
|
||||||
|
"air",
|
||||||
|
"mapgen_stone",
|
||||||
|
minetest.registered_aliases["mapgen_dirt"],
|
||||||
|
}, {
|
||||||
|
"this long text could not possibly ever match a node",
|
||||||
|
"",
|
||||||
|
}))
|
||||||
|
|
||||||
|
register_test("//mix", make_parsing_test("mix", {
|
||||||
|
"air",
|
||||||
|
"air 2",
|
||||||
|
"air mapgen_stone",
|
||||||
|
"air 2 air 1 mapgen_stone 1",
|
||||||
|
}, {
|
||||||
|
"this_will_never_match_any_node",
|
||||||
|
"air 1 this_will_never_match_any_node",
|
||||||
|
"air this_will_never_match_any_node",
|
||||||
|
"",
|
||||||
|
}))
|
||||||
|
|
||||||
|
register_test("//fixedpos", make_parsing_test("fixedpos", {
|
||||||
|
"set1 0 0 0",
|
||||||
|
"set2 -10 20 31000",
|
||||||
|
"set1 ~0 ~0 ~0",
|
||||||
|
"set2 ~-5 2 ~+2",
|
||||||
|
}, {
|
||||||
|
"set1 0 0",
|
||||||
|
"set 1 2 3",
|
||||||
|
"set2 ~ ~ ~",
|
||||||
|
"set2 + 0 0",
|
||||||
|
"",
|
||||||
|
}))
|
||||||
|
|
||||||
|
register_test("//inset", make_parsing_test("inset", {
|
||||||
|
"h 1",
|
||||||
|
"v 0",
|
||||||
|
"hv 2",
|
||||||
|
"vh 3",
|
||||||
|
}, {
|
||||||
|
"x 4",
|
||||||
|
"xyz 5",
|
||||||
|
"v foo",
|
||||||
|
}))
|
||||||
|
|
||||||
|
register_test("//cubeapply", make_parsing_test("cubeapply", {
|
||||||
|
"2 orient 90",
|
||||||
|
"2 3 4 orient 90",
|
||||||
|
"1 1 1 drain",
|
||||||
|
"4 stack z 1",
|
||||||
|
}, {
|
||||||
|
"1 1 1 orient",
|
||||||
|
"0 drain",
|
||||||
|
"4 stack z",
|
||||||
|
"2 2 2 asasasasasas",
|
||||||
|
"",
|
||||||
|
}))
|
||||||
|
|
||||||
|
register_test("//save", make_parsing_test("save", {
|
||||||
|
"filename",
|
||||||
|
"filename.abc",
|
||||||
|
}, {
|
||||||
|
"\"hmm",
|
||||||
|
"../../oops",
|
||||||
|
"",
|
||||||
|
}))
|
Reference in New Issue
Block a user