Stream: helpdesk (published)

Topic: ✔ World age advance in tests


view this post on Zulip DrChainsaw (Nov 21 2025 at 16:25):

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?

view this post on Zulip Eric Hanson (Nov 21 2025 at 16:29):

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?

view this post on Zulip Mason Protter (Nov 21 2025 at 17:05):

You can just use invokelatest too, right?

view this post on Zulip DrChainsaw (Nov 21 2025 at 17:23):

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).

view this post on Zulip Notification Bot (Nov 21 2025 at 17:23):

DrChainsaw has marked this topic as resolved.


Last updated: Nov 27 2025 at 04:44 UTC