Skip to content

Commit

Permalink
use mtt for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Aug 11, 2022
1 parent 58935a2 commit e3f7713
Show file tree
Hide file tree
Showing 27 changed files with 373 additions and 413 deletions.
15 changes: 0 additions & 15 deletions .github/workflows.disabled/integration-test.yml

This file was deleted.

17 changes: 0 additions & 17 deletions .github/workflows/busted.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/test.yml
@@ -0,0 +1,17 @@
name: test

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
ENGINE_VERSION: [5.3.0, 5.4.0, 5.5.0, 5.6.0, latest]

steps:
- uses: actions/checkout@v2
- name: test
run: docker-compose up --exit-code-from sut
14 changes: 4 additions & 10 deletions .luacheckrc
@@ -1,11 +1,8 @@
globals = {
"blockexchange",
"worldedit",
["minetest"] = {
["request_http_api"] = true
},
"AreaStore",
"Promise"
"Promise",
"minetest"
}

read_globals = {
Expand All @@ -14,14 +11,11 @@ read_globals = {
table = {fields = {"copy", "getn"}},

-- Minetest
"minetest",
"vector", "ItemStack",
"dump", "dump2",
"AreaStore",
"VoxelArea",

-- opt deps
"areas", "monitoring",

-- testing
"mineunit", "sourcefile", "assert", "describe", "it"
"areas", "monitoring", "mtt"
}
19 changes: 19 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,19 @@
version: "3.6"

services:
sut:
build:
context: ./test
args:
ENGINE_VERSION: ${ENGINE_VERSION:-5.6.0}
user: root
volumes:
- "./:/root/.minetest/worlds/world/worldmods/blockexchange/"
- "world_data:/root/.minetest/worlds/world"
- "./test/world.mt:/root/.minetest/worlds/world/world.mt"
- "./test/minetest.conf:/minetest.conf"
ports:
- "30000:30000/udp"

volumes:
world_data: {}
10 changes: 10 additions & 0 deletions init.lua
Expand Up @@ -104,3 +104,13 @@ dofile(MP.."/worker/save_worker.lua")
dofile(MP.."/worker/save_update_worker.lua")
dofile(MP.."/worker/emerge_worker.lua")
dofile(MP.."/worker/protectioncheck_worker.lua")

if minetest.get_modpath("mtt") then
dofile(MP .. "/mtt/clip_area_spec.lua")
dofile(MP .. "/mtt/get_base_pos_spec.lua")
dofile(MP .. "/mtt/iterator_spec.lua")
dofile(MP .. "/mtt/promise_spec.lua")
dofile(MP .. "/mtt/schemapart_offset_spec.lua")
dofile(MP .. "/mtt/sort_pos_spec.lua")
dofile(MP .. "/mtt/validate_name_spec.lua")
end
2 changes: 1 addition & 1 deletion mod.conf
@@ -1,3 +1,3 @@
name = blockexchange
optional_depends = worldedit,areas,monitoring,vacuum
optional_depends = worldedit,areas,monitoring,vacuum,mtt
min_protocol = 37
18 changes: 18 additions & 0 deletions mtt/clip_area_spec.lua
@@ -0,0 +1,18 @@


mtt.register("clip_area test", function(callback)
local clip_pos1 = { x=10, y=10, z=10 }
local clip_pos2 = { x=20, y=30, z=40 }
local pos1 = { x=9, y=11, z=20 }
local pos2 = { x=21, y=30, z=40 }

local clipped_pos1, clipped_pos2 = blockexchange.clip_area(clip_pos1, clip_pos2, pos1, pos2)
assert(10 == clipped_pos1.x)
assert(11 == clipped_pos1.y)
assert(20 == clipped_pos1.z)
assert(20 == clipped_pos2.x)
assert(30 == clipped_pos2.y)
assert(40 == clipped_pos2.z)

callback()
end)
30 changes: 30 additions & 0 deletions mtt/get_base_pos_spec.lua
@@ -0,0 +1,30 @@
mtt.register("blockexchange.get_base_pos, returns proper positive coordinates", function(callback)
local pos = blockexchange.get_base_pos({x=0, y=0, z=0}, {x=5, y=1, z=0})
assert(pos)
assert(0 == pos.x)
assert(0 == pos.y)
assert(0 == pos.z)

pos = blockexchange.get_base_pos({x=0, y=0, z=0}, {x=5, y=16, z=0})
assert(pos)
assert(0 == pos.x)
assert(16 == pos.y)
assert(0 == pos.z)

callback()
end)

mtt.register("blockexchange.get_base_pos, returns proper negative coordinates", function(callback)
local pos = blockexchange.get_base_pos({x=0, y=0, z=0}, {x=-5, y=0, z=0})
assert(pos)
assert(-16 == pos.x)
assert(0 == pos.y)
assert(0 == pos.z)

pos = blockexchange.get_base_pos({x=0, y=0, z=0}, {x=-5, y=-17, z=0})
assert(pos)
assert(-16 == pos.x)
assert(-32 == pos.y)
assert(0 == pos.z)
callback()
end)
137 changes: 137 additions & 0 deletions mtt/iterator_spec.lua
@@ -0,0 +1,137 @@
mtt.register("blockexchange.iterator, returns proper positive coordinates", function(callback)
local origin = { x=0, y=0, z=0 }
local pos1 = { x=0, y=0, z=0 }
local pos2 = { x=17, y=0, z=0 }

local it = blockexchange.iterator(origin, pos1, pos2)
local abs_pos, pos, progress = it()
assert(pos)
assert(0 == pos.x)
assert(0 == pos.y)
assert(0 == pos.z)
assert(0.5 == progress)

assert(abs_pos)
assert(0 == abs_pos.x)
assert(0 == abs_pos.y)
assert(0 == abs_pos.z)

abs_pos, pos, progress = it()
assert(pos)
assert(16 == pos.x)
assert(0 == pos.y)
assert(0 == pos.z)
assert(1 == progress)

assert(pos)
assert(16 == abs_pos.x)
assert(0 == abs_pos.y)
assert(0 == abs_pos.z)

abs_pos, pos = it()
assert(not pos)
assert(not abs_pos)
callback()
end)

mtt.register("blockexchange.iterator, returns proper positive coordinates with modified origin", function(callback)
local origin = { x=10, y=0, z=0 }
local pos1 = { x=11, y=0, z=0 }
local pos2 = { x=27, y=0, z=0 }

local it = blockexchange.iterator(origin, pos1, pos2)
local abs_pos, pos = it()
assert(pos)
assert(0 == pos.x)
assert(0 == pos.y)
assert(0 == pos.z)

assert(abs_pos)
assert(10 == abs_pos.x)
assert(0 == abs_pos.y)
assert(0 == abs_pos.z)

abs_pos, pos = it()
assert(pos)
assert(16 == pos.x)
assert(0 == pos.y)
assert(0 == pos.z)

assert(abs_pos)
assert(26 == abs_pos.x)
assert(0 == abs_pos.y)
assert(0 == abs_pos.z)

abs_pos, pos = it()
assert(not pos)
assert(not abs_pos)
callback()
end)

mtt.register("blockexchange.iterator, returns proper negative coordinates", function(callback)
local origin = { x=0, y=0, z=0 }
local pos1 = { x=-5, y=0, z=0 }
local pos2 = { x=5, y=0, z=0 }

local it = blockexchange.iterator(origin, pos1, pos2)
local abs_pos, pos = it()
assert(pos)
assert(-16 == pos.x)
assert(0 == pos.y)
assert(0 == pos.z)

assert(abs_pos)
assert(-16 == abs_pos.x)
assert(0 == abs_pos.y)
assert(0 == abs_pos.z)

abs_pos, pos = it()
assert(pos)
assert(0 == pos.x)
assert(0 == pos.y)
assert(0 == pos.z)

assert(abs_pos)
assert(0 == abs_pos.x)
assert(0 == abs_pos.y)
assert(0 == abs_pos.z)

abs_pos, pos = it()
assert(not pos)
assert(not abs_pos)
callback()
end)

mtt.register("blockexchange.iterator, returns proper negative coordinates with modified origin", function(callback)
local origin = { x=-1, y=0, z=0 }
local pos1 = { x=-5, y=0, z=0 }
local pos2 = { x=5, y=0, z=0 }

local it = blockexchange.iterator(origin, pos1, pos2)
local abs_pos, pos = it()
assert(pos)
assert(-16 == pos.x)
assert(0 == pos.y)
assert(0 == pos.z)

assert(abs_pos)
assert(-17 == abs_pos.x)
assert(0 == abs_pos.y)
assert(0 == abs_pos.z)

abs_pos, pos = it()
assert(pos)
assert(0 == pos.x)
assert(0 == pos.y)
assert(0 == pos.z)

assert(abs_pos)
assert(-1 == abs_pos.x)
assert(0 == abs_pos.y)
assert(0 == abs_pos.z)

abs_pos, pos = it()
assert(not pos)
assert(not abs_pos)
callback()
end)
29 changes: 29 additions & 0 deletions mtt/promise_spec.lua
@@ -0,0 +1,29 @@

mtt.register("promise test, smoke test", function(callback)
assert(Promise)

local p = Promise.new(function(resolve)
resolve(1)
end)

p:next(function(v)
return Promise.new(function(resolve)
resolve(v + 1)
end)
end):next(function(v)
assert(v == 2)
callback()
end)
end)


mtt.register("promise test, bool value test", function(callback)
local p = Promise.new(function(resolve)
resolve(false)
end)

p:next(function(v)
assert(not v)
callback()
end)
end)

0 comments on commit e3f7713

Please sign in to comment.