mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Make tests lazily evaluated
This commit is contained in:
parent
e6039caaaf
commit
b81bd6eea8
2 changed files with 67 additions and 79 deletions
|
@ -145,13 +145,13 @@ TEST("#repro2", function()
|
|||
world:set(entity, pair(4, 5), 6) -- noise
|
||||
|
||||
local entity_visualizer = require("@tools/entity_visualiser")
|
||||
entity_visualizer.components(world, entity)
|
||||
-- entity_visualizer.components(world, entity)
|
||||
|
||||
for e in world:each(pair(Lifetime, __)) do
|
||||
local i = 0
|
||||
local nth = world:target(e, Lifetime, i)
|
||||
while nth do
|
||||
entity_visualizer.components(world, e)
|
||||
-- entity_visualizer.components(world, e)
|
||||
|
||||
local data = world:get(e, pair(Lifetime, nth))
|
||||
data -= 1
|
||||
|
@ -173,14 +173,11 @@ local lifetime_tracker_add = require("@tools/lifetime_tracker")
|
|||
|
||||
TEST("another", function()
|
||||
local world = world_new()
|
||||
world = lifetime_tracker_add(world, {padding_enabled=false})
|
||||
-- world = lifetime_tracker_add(world, {padding_enabled=false})
|
||||
local e1 = world:entity()
|
||||
local e2 = world:entity()
|
||||
local e3 = world:entity()
|
||||
world:delete(e2)
|
||||
world:print_entity_index()
|
||||
print(pair(e1, e2))
|
||||
print(pair(e2, e3))
|
||||
local e2_e3 = pair(e2, e3)
|
||||
CHECK(jecs.pair_first(world, e2_e3) == 0)
|
||||
CHECK(jecs.pair_second(world, e2_e3) == e3)
|
||||
|
@ -945,10 +942,8 @@ TEST("world:query()", function()
|
|||
CHECK(count == 2)
|
||||
end
|
||||
|
||||
do
|
||||
CASE("iterator invalidation")
|
||||
do
|
||||
CASE("adding")
|
||||
do CASE("iterator invalidation")
|
||||
do CASE("adding")
|
||||
SKIP()
|
||||
local world = jecs.World.new()
|
||||
local A = world:component()
|
||||
|
@ -970,8 +965,7 @@ TEST("world:query()", function()
|
|||
CHECK(count == 2)
|
||||
end
|
||||
|
||||
do
|
||||
CASE("spawning")
|
||||
do CASE("spawning")
|
||||
local world = jecs.World.new()
|
||||
local A = world:component()
|
||||
local B = world:component()
|
||||
|
@ -992,8 +986,7 @@ TEST("world:query()", function()
|
|||
end
|
||||
end
|
||||
|
||||
do
|
||||
CASE("should not find any entities")
|
||||
do CASE("should not find any entities")
|
||||
local world = jecs.World.new()
|
||||
|
||||
local Hello = world:component()
|
||||
|
@ -1011,9 +1004,7 @@ TEST("world:query()", function()
|
|||
CHECK(withoutCount == 0)
|
||||
end
|
||||
|
||||
do
|
||||
CASE("without")
|
||||
do
|
||||
do CASE("without")
|
||||
-- REGRESSION TEST
|
||||
local world = jecs.World.new()
|
||||
local _1, _2, _3 = world:component(), world:component(), world:component()
|
||||
|
@ -1024,7 +1015,6 @@ TEST("world:query()", function()
|
|||
end
|
||||
CHECK(counter == 0)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
TEST("world:each", function()
|
||||
|
@ -1093,8 +1083,7 @@ TEST("world:children", function()
|
|||
end)
|
||||
|
||||
TEST("world:clear()", function()
|
||||
do
|
||||
CASE("should remove its components")
|
||||
do CASE("should remove its components")
|
||||
local world = jecs.World.new() :: World
|
||||
local A = world:component()
|
||||
local B = world:component()
|
||||
|
@ -1120,8 +1109,7 @@ TEST("world:clear()", function()
|
|||
CHECK(world:get(e1, A) == nil)
|
||||
CHECK(world:get(e1, B))
|
||||
end
|
||||
do
|
||||
CASE("should remove its components")
|
||||
do CASE("should remove its components")
|
||||
local world = jecs.World.new() :: World
|
||||
local A = world:component()
|
||||
local B = world:component()
|
||||
|
@ -1139,8 +1127,7 @@ TEST("world:clear()", function()
|
|||
CHECK(world:get(e, B) == nil)
|
||||
end
|
||||
|
||||
do
|
||||
CASE("should move last record")
|
||||
do CASE("should move last record")
|
||||
local world = world_new()
|
||||
local A = world:component()
|
||||
|
||||
|
@ -1185,8 +1172,7 @@ TEST("world:clear()", function()
|
|||
end)
|
||||
|
||||
TEST("world:has()", function()
|
||||
do
|
||||
CASE("should find Tag on entity")
|
||||
do CASE("should find Tag on entity")
|
||||
local world = jecs.World.new()
|
||||
|
||||
local Tag = world:entity()
|
||||
|
@ -1197,8 +1183,7 @@ TEST("world:has()", function()
|
|||
CHECK(world:has(e, Tag))
|
||||
end
|
||||
|
||||
do
|
||||
CASE("should return false when missing one tag")
|
||||
do CASE("should return false when missing one tag")
|
||||
local world = jecs.World.new()
|
||||
|
||||
local A = world:entity()
|
||||
|
@ -1216,8 +1201,7 @@ TEST("world:has()", function()
|
|||
end)
|
||||
|
||||
TEST("world:component()", function()
|
||||
do
|
||||
CASE("only components should have EcsComponent trait")
|
||||
do CASE("only components should have EcsComponent trait")
|
||||
local world = jecs.World.new() :: World
|
||||
local A = world:component()
|
||||
local e = world:entity()
|
||||
|
|
|
@ -222,37 +222,16 @@ local function CHECK<T>(value: T, stack: number?): T?
|
|||
end
|
||||
|
||||
local function TEST(name: string, fn: () -> ())
|
||||
local active = test
|
||||
assert(not active, "cannot start test while another test is in progress")
|
||||
|
||||
test = {
|
||||
name = name,
|
||||
cases = {},
|
||||
duration = 0,
|
||||
focus = false,
|
||||
fn = fn
|
||||
}
|
||||
assert(test)
|
||||
|
||||
table.insert(tests, test)
|
||||
|
||||
local start = os.clock()
|
||||
local err
|
||||
local success = xpcall(fn, function(m: string)
|
||||
err = { message = m, trace = debug.traceback(nil, 2) }
|
||||
end)
|
||||
test.duration = os.clock() - start
|
||||
|
||||
if not test.case then
|
||||
CASE("")
|
||||
end
|
||||
assert(test.case, "no active case")
|
||||
|
||||
if not success then
|
||||
test.case.result = ERROR
|
||||
test.error = err
|
||||
end
|
||||
|
||||
test = nil
|
||||
end
|
||||
|
||||
local function FOCUS()
|
||||
|
@ -274,6 +253,31 @@ local function FINISH(): boolean
|
|||
local total_focus_cases = 0
|
||||
local duration = 0
|
||||
|
||||
for _, t in tests do
|
||||
if check_for_focused and not t.focus then
|
||||
continue
|
||||
end
|
||||
test = t
|
||||
fn = t.fn
|
||||
local start = os.clock()
|
||||
local err
|
||||
local success = xpcall(fn, function(m: string)
|
||||
err = { message = m, trace = debug.traceback(nil, 2) }
|
||||
end)
|
||||
test.duration = os.clock() - start
|
||||
|
||||
if not test.case then
|
||||
CASE("")
|
||||
end
|
||||
assert(test.case, "no active case")
|
||||
|
||||
if not success then
|
||||
test.case.result = ERROR
|
||||
test.error = err
|
||||
end
|
||||
collectgarbage()
|
||||
end
|
||||
|
||||
for _, test in tests do
|
||||
duration += test.duration
|
||||
for _, case in test.cases do
|
||||
|
|
Loading…
Reference in a new issue