Skip to content

Commit b546f21

Browse files
committed
Test dynamic scope correctness
1 parent 6aeaac3 commit b546f21

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/test_utils.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ function test_cases()
5757
Testcase(
5858
"foreigncall tester", nothing, (foreigncall_tester, "hi"), [Ptr{UInt8}, Ptr{UInt8}]
5959
),
60+
Testcase("dynamic scope 1", 5, (dynamic_scope_tester_1,), [5]),
61+
Testcase("dynamic scope 2", 6, (dynamic_scope_tester_1,), [6]),
6062

6163
# Failing tests
6264
# Testcase("nested", (nested_outer, ), [true, false]),
@@ -160,4 +162,9 @@ function nested_outer()
160162
return nothing
161163
end
162164

165+
function dynamic_scope_tester_1()
166+
produce(Libtask.get_dynamic_scope())
167+
return nothing
168+
end
169+
163170
end

test/copyable_task.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
for case in Libtask.TestUtils.test_cases()
33
case()
44
end
5+
@testset "set_dynamic_scope" begin
6+
function f()
7+
produce(typeassert(Libtask.get_dynamic_scope(), Int))
8+
produce(typeassert(Libtask.get_dynamic_scope(), Int))
9+
return nothing
10+
end
11+
t = TapedTask(5, f)
12+
@test consume(t) == 5
13+
Libtask.set_dynamic_scope!(t, 6)
14+
@test consume(t) == 6
15+
@test consume(t) === nothing
16+
end
517
@testset "iteration" begin
618
function f()
719
t = 1

0 commit comments

Comments
 (0)