From f623e9fa10ecaa0afe557d54ede05f8cd8cb0a80 Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Mon, 2 Nov 2020 13:59:09 +0100 Subject: [PATCH] runtests: uniquify modules in Base.loaded_modules + TESTED_MODULES --- src/ReTest.jl | 16 +++++++--------- test/runtests.jl | 11 +++++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/ReTest.jl b/src/ReTest.jl index 962a8e1..6b31386 100644 --- a/src/ReTest.jl +++ b/src/ReTest.jl @@ -221,15 +221,13 @@ function wrap_ts(partial, regex, ts::TestsetExpr, loopvals=nothing) end function runtests(pattern::Union{AbstractString,Regex} = r""; wrap::Bool=true) - for mods in (values(Base.loaded_modules), TESTED_MODULES) - # TESTED_MODULES is not up-to-date w.r.t. package modules which have - # precompilation, so we have to also look in Base.loaded_modules - # TODO: look recursively in "loaded modules" which use ReTest for sub-modules - foreach(mods) do m - if isdefined(m, INLINE_TEST[]) - # will automatically skip ReTest and ReTest.ReTestTest - runtests(m, pattern, wrap=wrap) - end + # TESTED_MODULES is not up-to-date w.r.t. package modules which have + # precompilation, so we have to also look in Base.loaded_modules + # TODO: look recursively in "loaded modules" which use ReTest for sub-modules + for m in unique(Iterators.flatten((values(Base.loaded_modules), TESTED_MODULES))) + if isdefined(m, INLINE_TEST[]) + # will automatically skip ReTest and ReTest.ReTestTest + runtests(m, pattern, wrap=wrap) end end end diff --git a/test/runtests.jl b/test/runtests.jl index bcca3ec..f49fd0d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -156,5 +156,16 @@ if VERSION >= v"1.3" P.check("b|c", ["a", "b|c"]) # "b" is not matched end +RUN = [] +@testset "toplevel" begin + # this tests that the testset is run exactly once + # Main is special here, as it's both in Base.loaded_modules + # and it gets registered automatically in ReTest.TESTED_MODULES + push!(RUN, "toplevel") + @test true +end + runtests() +@test RUN == ["toplevel"] + runtests(r"^/f1") # just test that a regex can be passed