|
| 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 | + g3(x, 1, 2; p=3, q=4) |
| 10 | +end |
| 11 | +end |
| 12 | + |
1 | 13 | @testset "copyable_task" begin
|
2 | 14 | for case in Libtask.TestUtils.test_cases()
|
3 | 15 | case()
|
|
251 | 263 | @test Libtask.consume(tt) === :a
|
252 | 264 | @test Libtask.consume(tt) === nothing
|
253 | 265 | end
|
| 266 | + |
| 267 | + @testset "@might_produce macro" begin |
| 268 | + # Positional arguments only |
| 269 | + @noinline g1(x) = produce(x) |
| 270 | + f1(x) = g1(x) |
| 271 | + # Without marking it as might_produce |
| 272 | + tt = Libtask.TapedTask(nothing, f1, 0) |
| 273 | + @test Libtask.consume(tt) === nothing |
| 274 | + # Now marking it |
| 275 | + Libtask.@might_produce(g1) |
| 276 | + tt = Libtask.TapedTask(nothing, f1, 0) |
| 277 | + @test Libtask.consume(tt) === 0 |
| 278 | + @test Libtask.consume(tt) === nothing |
| 279 | + |
| 280 | + # Keyword arguments only |
| 281 | + @noinline g2(x; y=1, z=2) = produce(x + y + z) |
| 282 | + f2(x) = g2(x) |
| 283 | + # Without marking it as might_produce |
| 284 | + tt = Libtask.TapedTask(nothing, f2, 0) |
| 285 | + @test Libtask.consume(tt) === nothing |
| 286 | + # Now marking it |
| 287 | + Libtask.@might_produce(g2) |
| 288 | + tt = Libtask.TapedTask(nothing, f2, 0) |
| 289 | + @test Libtask.consume(tt) === 3 |
| 290 | + @test Libtask.consume(tt) === nothing |
| 291 | + |
| 292 | + # 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) |
| 299 | + @test Libtask.consume(tt) === nothing |
| 300 | + # Now marking it |
| 301 | + Libtask.@might_produce(Functions.g3) |
| 302 | + tt = Libtask.TapedTask(nothing, Functions.f3, 0) |
| 303 | + @test Libtask.consume(tt) === 0 |
| 304 | + @test Libtask.consume(tt) === 3 |
| 305 | + @test Libtask.consume(tt) === 10 |
| 306 | + @test Libtask.consume(tt) === nothing |
| 307 | + end |
254 | 308 | end
|
0 commit comments