lunatest for unit-testing, luacov for coverage
parent
761f9512ba
commit
a9dc4328ec
|
@ -0,0 +1,3 @@
|
|||
Stress.config = {
|
||||
debug = false
|
||||
}
|
11
stress.lua
11
stress.lua
|
@ -4,12 +4,21 @@ Stress for Minetest
|
|||
|
||||
]]
|
||||
|
||||
Stress = {}
|
||||
|
||||
stressEvents = {
|
||||
place = {}
|
||||
}
|
||||
|
||||
local myPath = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
dofile(myPath .. "/config.lua")
|
||||
|
||||
if Stress.config.debug then
|
||||
print("Stress.config.debug is enabled. *Never* use this in production!")
|
||||
dofile(myPath .. "/tests.lua")
|
||||
end
|
||||
|
||||
dofile(myPath .. "/stressedPosition.lua")
|
||||
dofile(myPath .. "/stressedArea.lua")
|
||||
dofile(myPath .. "/stressedNodeDef.lua")
|
||||
|
@ -17,8 +26,6 @@ dofile(myPath .. "/stressedNode.lua")
|
|||
dofile(myPath .. "/stressedStack.lua")
|
||||
dofile(myPath .. "/stressedInventory.lua")
|
||||
|
||||
Stress = {}
|
||||
|
||||
function Stress.__call(self, first, second)
|
||||
if stressedPosition.__valid(first) and stressedPosition.__valid(second) then
|
||||
return stressedArea(stressedPosition(first), stressedPosition(second))
|
||||
|
|
|
@ -56,3 +56,12 @@ stressedPosition.__meta = {
|
|||
}
|
||||
|
||||
setmetatable(stressedPosition, { __call = stressedPosition.__call })
|
||||
|
||||
function stressedPosition.test()
|
||||
assert_equal(stressedPosition({1, 2, 3}), stressedPosition({x=1,y=2,z=3}))
|
||||
assert_equal(stressedPosition({1, 2, 3}), -stressedPosition({-1, -2, -3}))
|
||||
assert_equal(stressedPosition({1, 2, 3}) + stressedPosition({4, 5, 6}), stressedPosition({5, 7, 9}))
|
||||
assert_equal(stressedPosition({1, 2, 3}) - stressedPosition({3, 2, 1}), stressedPosition({-2, 0, 2}))
|
||||
assert_false(stressedPosition.__valid(nil))
|
||||
assert_true(stressedPosition.__valid({1, 2, 3}))
|
||||
end
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
--[[
|
||||
|
||||
To be able to run tests and see coverage:
|
||||
download luacov from https://github.com/norman/luacov
|
||||
download lunatest from https://github.com/silentbicycle/lunatest
|
||||
place them into your minetest directory
|
||||
Copy luacov from luacov/src/bin/luacov to minetest/luacov_s
|
||||
Your directory structure should look like
|
||||
luacov
|
||||
├── defaults.lua
|
||||
├── reporter.lua
|
||||
├── runner.lua
|
||||
├── stats.lua
|
||||
└── tick.lua
|
||||
luacov_s
|
||||
lunatest.lua
|
||||
report.sh
|
||||
|
||||
report.sh:
|
||||
if [ -f luacov.stats.out ]; then
|
||||
lua luacov_s
|
||||
rm luacov.stats.out
|
||||
fi
|
||||
vim luacov.report.out
|
||||
|
||||
]]
|
||||
|
||||
require "luacov"
|
||||
require "lunatest"
|
||||
|
||||
function Stress.test()
|
||||
stressedPosition.test()
|
||||
end
|
||||
|
||||
minetest.after(0, Stress.test)
|
Loading…
Reference in New Issue