Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that everything is evaluated in the same world age inside a @testset. #26220

Open
Ismael-VC opened this issue Feb 27, 2018 · 2 comments
Labels
domain:docs This change adds or pertains to documentation testsystem The unit testing framework and Test stdlib

Comments

@Ismael-VC
Copy link
Contributor

julia> versioninfo()
Julia Version 0.6.3-pre.0
Commit 93168a6826* (2017-12-18 07:11 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-1650 v4 @ 3.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)

This works:

module Foo
export @foo

_foo() = false
macro foo(); :($_foo()); end

end # module

using Foo
using Base.Test

# @testset "Foo" begin

info("Before redefinition.")
@show @test Foo._foo() == false
@show @test @foo() == false

Foo.eval(:(_foo() = true))

info("After redefinition.")
@show @test Foo._foo() == true
@show @test @foo() == true

# end

Output:

INFO: Before redefinition.
@test(Foo._foo() == false) = Test Passed
@test(@foo() == false) = Test Passed
WARNING: Method definition _foo() in module Foo at /usr/local/google/home/vismael/.julia/v0.6/Foo/src/Foo.jl:4 overwritten at /usr/local/google/home/vismael/.julia/v0.6/Foo/src/Foo.jl:18.
INFO: After redefinition.
@test(Foo._foo() == true) = Test Passed
@test(@foo() == true) = Test Passed

If I remove the comments for the testset (enabling the testset block), it doesn't work anymore:

module Foo
export @foo

_foo() = false
macro foo(); :($_foo()); end

end # module

using Foo
using Base.Test

@testset "Foo" begin

info("Before redefinition.")
@show @test Foo._foo() == false
@show @test @foo() == false

Foo.eval(:(_foo() = true))

info("After redefinition.")
@show @test Foo._foo() == true
@show @test @foo() == true

end

Output:

INFO: Before redefinition.
@test(Foo._foo() == false) = Test Passed
@test(@foo() == false) = Test Passed
WARNING: Method definition _foo() in module Foo at /usr/local/google/home/vismael/.julia/v0.6/Foo/src/Foo.jl:4 overwritten at /usr/local/google/home/vismael/.julia/v0.6/Foo/src/Foo.jl:18.
INFO: After redefinition.
Foo: Test Failed
  Expression: Foo._foo() == true
   Evaluated: false == true
Stacktrace:
 [1] macro expansion at ./show.jl:243 [inlined]
 [2] macro expansion at /usr/local/google/home/vismael/.julia/v0.6/Foo/src/Foo.jl:21 [inlined]
 [3] macro expansion at ./test.jl:860 [inlined]
 [4] anonymous at ./<missing>:?
@test(Foo._foo() == true) = (Test Failed
  Expression: Foo._foo() == true
   Evaluated: false == true, Ptr{Void}[Ptr{Void} @0x00007fcea2933bc0, Ptr{Void} @0x00007fce765a8a59, Ptr{Void} @0x00007fce765a8b17, Ptr{Void} @0x00007fcea28f4217, Ptr{Void} @0x00007fce765a65ab, Ptr{Void} @0x00007fce765a65e7, Ptr{Void} @0x00007fcea28f44a2, Ptr{Void} @0x00007fce765a0a21, Ptr{Void} @0x00007fcea2920caa, Ptr{Void} @0x00007fcea28fd0c7, Ptr{Void} @0x00007fcea2920de4, Ptr{Void} @0x00007fce9cecce2f, Ptr{Void} @0x00007fce9cecd00c, Ptr{Void} @0x00007fcea28f4217, Ptr{Void} @0x00007fce9cd63d33, Ptr{Void} @0x00007fce9cd63d9c, Ptr{Void} @0x00007fcea28f4217, Ptr{Void} @0x00007fce9ced8936, Ptr{Void} @0x00007fce9cedaf93, Ptr{Void} @0x00007fce9cedba19, Ptr{Void} @0x00007fcea28f4217, Ptr{Void} @0x00005619b3052de2, Ptr{Void} @0x00005619b30525f3, Ptr{Void} @0x00007fcea1f112b1, Ptr{Void} @0x00005619b30526aa])
Foo: Test Failed
  Expression: @foo() == true
   Evaluated: false == true
Stacktrace:
 [1] macro expansion at ./show.jl:243 [inlined]
 [2] macro expansion at /usr/local/google/home/vismael/.julia/v0.6/Foo/src/Foo.jl:22 [inlined]
 [3] macro expansion at ./test.jl:860 [inlined]
 [4] anonymous at ./<missing>:?
@test(@foo() == true) = (Test Failed
  Expression: @foo() == true
   Evaluated: false == true, Ptr{Void}[Ptr{Void} @0x00007fcea2933bc0, Ptr{Void} @0x00007fce765a8a59, Ptr{Void} @0x00007fce765a8b17, Ptr{Void} @0x00007fcea28f4217, Ptr{Void} @0x00007fce765a65ab, Ptr{Void} @0x00007fce765a65e7, Ptr{Void} @0x00007fcea28f44a2, Ptr{Void} @0x00007fce765a0e73, Ptr{Void} @0x00007fcea2920caa, Ptr{Void} @0x00007fcea28fd0c7, Ptr{Void} @0x00007fcea2920de4, Ptr{Void} @0x00007fce9cecce2f, Ptr{Void} @0x00007fce9cecd00c, Ptr{Void} @0x00007fcea28f4217, Ptr{Void} @0x00007fce9cd63d33, Ptr{Void} @0x00007fce9cd63d9c, Ptr{Void} @0x00007fcea28f4217, Ptr{Void} @0x00007fce9ced8936, Ptr{Void} @0x00007fce9cedaf93, Ptr{Void} @0x00007fce9cedba19, Ptr{Void} @0x00007fcea28f4217, Ptr{Void} @0x00005619b3052de2, Ptr{Void} @0x00005619b30525f3, Ptr{Void} @0x00007fcea1f112b1, Ptr{Void} @0x00005619b30526aa])
Test Summary: | Pass  Fail  Total
Foo           |    2     2      4
ERROR: LoadError: Some tests did not pass: 2 passed, 2 failed, 0 errored, 0 broken.
while loading /usr/local/google/home/vismael/.julia/v0.6/Foo/src/Foo.jl, in expression starting on line 12

I started creating a package, because I thought it was related to Pkg.test, but after playing with it, I became able to reproduce by simply running julia src/Foo.jl and enabling/disabling the @testset block.

@martinholters
Copy link
Member

Inside a @testset, everything is evaluated in the same world age, I believe, so this is expected. (You could use invokelatest or eval for the tests after the redefinition to call the new definition of _foo.)

@Ismael-VC
Copy link
Contributor Author

Thank you Martin!

Could someone please confirm this is intended?

I'll change the title of the issue.

@Ismael-VC Ismael-VC changed the title Test fails only when using @testset Document that everything is evaluated in the same world age inside a @testset. Feb 27, 2018
@JeffBezanson JeffBezanson added domain:docs This change adds or pertains to documentation testsystem The unit testing framework and Test stdlib labels Feb 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:docs This change adds or pertains to documentation testsystem The unit testing framework and Test stdlib
Projects
None yet
Development

No branches or pull requests

3 participants