I have a testset for some code generation code which used to work in 1.11 but now fails in 1.12. I realize it might have worked for the wrong reasons before, but I guess now is as good a time to fix it as ever.
The overall structure of the test is like this
@testset "Test Concept XX" begin
# Do some setup
@eval module TestModule end # Code will be generated into this module to not mess up other modules (eg Main)
@testset "Test generation of $x" for x in (....)
try
# Test that user gets a nice warning if they ever end up doing this
function badfun()
generate_code!(TestModule, x)
# Call code which uses result of the above
make_use_of_generated_stuff(TestModule)
end
@test_logs (:warn, "Warning about generated code") badfun()
# In Julia 1.11 it seems the world age had advanced here, but in 1.12 it hasn't
@test make_use_of_generated_stuff(TestModule) == expected_result
finally
clear_some_global_caches_in_tested_package()
end
end
end
The above is in a file which is included from runtests.jl inside another testcase:
@testset "Test Concepts" begin
include("the/above/file.jl")
end
Is there any place in this where it is safe to assume that the world age has advanced in 1.12?
https://docs.julialang.org/en/v1/base/base/#include mentions Core.@latestworld, but Core.@latestworld itself doesn't have docs. But it sounds like placing that where you want the world age to advance might work?
You can just use invokelatest too, right?
Thanks alot. Both Core.@latestworld and invokelatest worked. I guess invokelatest will also work on earlier versions and I think it is enough for the test to be valid (or else it was not a good test to begin with).
DrChainsaw has marked this topic as resolved.
Last updated: Nov 27 2025 at 04:44 UTC