mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Silence failing raycast unit test (#15644)
The cause for the test failure is an edge case bug in the raycast implementation (perfectly diagonal raycasts). This is fixed by switching to a continuous random distribution which makes it extremely unlikely that the buggy edge case occurs. Additionally, devtest unit test failures now print their random seed to be easier to reproduce in the future.
This commit is contained in:
parent
c346612468
commit
7f1316236b
2 changed files with 45 additions and 10 deletions
|
@ -12,6 +12,7 @@ unittests.list = {}
|
|||
-- player = false, -- Does test require a player?
|
||||
-- map = false, -- Does test require map access?
|
||||
-- async = false, -- Does the test run asynchronously? (read notes above!)
|
||||
-- random = false, -- Does the test use math.random directly or indirectly?
|
||||
-- }
|
||||
function unittests.register(name, func, opts)
|
||||
local def = table.copy(opts or {})
|
||||
|
@ -47,8 +48,18 @@ local function await(invoke)
|
|||
return coroutine.yield()
|
||||
end
|
||||
|
||||
local function printf(fmt, ...)
|
||||
print(fmt:format(...))
|
||||
end
|
||||
|
||||
function unittests.run_one(idx, counters, out_callback, player, pos)
|
||||
local def = unittests.list[idx]
|
||||
local seed
|
||||
if def.random then
|
||||
seed = core.get_us_time()
|
||||
math.randomseed(seed)
|
||||
end
|
||||
|
||||
if not def.player then
|
||||
player = nil
|
||||
elseif player == nil then
|
||||
|
@ -70,8 +81,10 @@ function unittests.run_one(idx, counters, out_callback, player, pos)
|
|||
if not status then
|
||||
core.log("error", err)
|
||||
end
|
||||
print(string.format("[%s] %s - %dms",
|
||||
status and "PASS" or "FAIL", def.name, ms_taken))
|
||||
printf("[%s] %s - %dms", status and "PASS" or "FAIL", def.name, ms_taken)
|
||||
if seed and not status then
|
||||
printf("Random was seeded to %d", seed)
|
||||
end
|
||||
counters.time = counters.time + ms_taken
|
||||
counters.total = counters.total + 1
|
||||
if status then
|
||||
|
@ -160,11 +173,11 @@ function unittests.run_all()
|
|||
-- Print stats
|
||||
assert(#unittests.list == counters.total)
|
||||
print(string.rep("+", 80))
|
||||
print(string.format("Devtest Unit Test Results: %s",
|
||||
counters.total == counters.passed and "PASSED" or "FAILED"))
|
||||
print(string.format(" %d / %d failed tests.",
|
||||
counters.total - counters.passed, counters.total))
|
||||
print(string.format(" Testing took %dms total.", counters.time))
|
||||
local passed = counters.total == counters.passed
|
||||
printf("Devtest Unit Test Results: %s", passed and "PASSED" or "FAILED")
|
||||
printf(" %d / %d failed tests.",
|
||||
counters.total - counters.passed, counters.total)
|
||||
printf(" Testing took %dms total.", counters.time)
|
||||
print(string.rep("+", 80))
|
||||
unittests.on_finished(counters.total == counters.passed)
|
||||
return counters.total == counters.passed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue