Skip to content

Commit 3e93f7a

Browse files
committed
Use function reference instead of another module
1 parent b27694f commit 3e93f7a

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

test/copyable_task.jl

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
module Functions
2-
using Libtask: produce
3-
@noinline g3(x) = produce(x)
4-
@noinline g3(x, y; z) = produce(x + y + z)
5-
@noinline g3(x, y, z; p, q) = produce(x + y + z + p + q)
6-
function f3(x)
7-
g3(x)
8-
g3(x, 1; z=2)
9-
return g3(x, 1, 2; p=3, q=4)
10-
end
11-
end
12-
131
@testset "copyable_task" begin
142
for case in Libtask.TestUtils.test_cases()
153
case()
@@ -290,16 +278,23 @@ end
290278
@test Libtask.consume(tt) === nothing
291279

292280
# A function with multiple methods.
293-
# Note: f3 and g3 are defined in the module at the top of this file. If
294-
# they are defined directly in this testset, for reasons that are
295-
# unclear, the `produce` calls are picked up even without using the
296-
# `@might_produce` macro, meaning that it's impossible to test that the
297-
# macro is having the intended behaviour.
298-
tt = Libtask.TapedTask(nothing, Functions.f3, 0)
281+
# The function reference is used to ensure that it really doesn't get inlined
282+
# (otherwise, for reasons that are yet unknown, these functions do get inlined when
283+
# inside a testset)
284+
@noinline g3(x) = produce(x)
285+
@noinline g3(x, y; z) = produce(x + y + z)
286+
@noinline g3(x, y, z; p, q) = produce(x + y + z + p + q)
287+
function f3(x, fref)
288+
fref[](x)
289+
fref[](x, 1; z=2)
290+
fref[](x, 1, 2; p=3, q=4)
291+
return nothing
292+
end
293+
tt = Libtask.TapedTask(nothing, f3, 0, Ref(g3))
299294
@test Libtask.consume(tt) === nothing
300295
# Now marking it
301-
Libtask.@might_produce(Functions.g3)
302-
tt = Libtask.TapedTask(nothing, Functions.f3, 0)
296+
Libtask.@might_produce(g3)
297+
tt = Libtask.TapedTask(nothing, f3, 0, Ref(g3))
303298
@test Libtask.consume(tt) === 0
304299
@test Libtask.consume(tt) === 3
305300
@test Libtask.consume(tt) === 10

0 commit comments

Comments
 (0)