@@ -10,6 +10,13 @@ All tests belong to a *test set*. There is a default, task-level
10
10
test set that throws on the first failure. Users can choose to wrap
11
11
their tests in (possibly nested) test sets that will store results
12
12
and summarize them at the end of the test set with `@testset`.
13
+
14
+ Environment variables:
15
+
16
+ * `JULIA_TEST_VERBOSE`: Set to `true` to enable verbose test output, including
17
+ testset entry/exit messages and detailed hierarchical test summaries.
18
+ * `JULIA_TEST_FAILFAST`: Set to `true` to stop testing on the first failure.
19
+ * `JULIA_TEST_RECORD_PASSES`: Set to `true` to record passed tests (for debugging).
13
20
"""
14
21
module Test
15
22
@@ -1226,7 +1233,7 @@ mutable struct DefaultTestSet <: AbstractTestSet
1226
1233
results_lock:: ReentrantLock
1227
1234
results:: Vector{Any}
1228
1235
end
1229
- function DefaultTestSet (desc:: AbstractString ; verbose:: Bool = false , showtiming:: Bool = true , failfast:: Union{Nothing,Bool} = nothing , source = nothing , rng = nothing )
1236
+ function DefaultTestSet (desc:: AbstractString ; verbose:: Bool = something (Base . ScopedValues . get (VERBOSE_TESTSETS)) , showtiming:: Bool = true , failfast:: Union{Nothing,Bool} = nothing , source = nothing , rng = nothing )
1230
1237
if isnothing (failfast)
1231
1238
# pass failfast state into child testsets
1232
1239
parent_ts = get_testset ()
@@ -2103,9 +2110,19 @@ const TESTSET_PRINT_ENABLE = ScopedValue{Bool}(true)
2103
2110
const TEST_RECORD_PASSES = LazyScopedValue {Bool} (OncePerProcess {Bool} () do
2104
2111
return Base. get_bool_env (" JULIA_TEST_RECORD_PASSES" , false )
2105
2112
end )
2113
+ const VERBOSE_TESTSETS = LazyScopedValue {Bool} (OncePerProcess {Bool} () do
2114
+ return Base. get_bool_env (" JULIA_TEST_VERBOSE" , false )
2115
+ end )
2106
2116
2107
2117
macro with_testset (ts, expr)
2108
- :(@with (CURRENT_TESTSET => $ (esc (ts)), TESTSET_DEPTH => get_testset_depth () + 1 , $ (esc (expr))))
2118
+ quote
2119
+ print_testset_verbose (:enter , $ (esc (ts)))
2120
+ try
2121
+ @with (CURRENT_TESTSET => $ (esc (ts)), TESTSET_DEPTH => get_testset_depth () + 1 , $ (esc (expr)))
2122
+ finally
2123
+ print_testset_verbose (:exit , $ (esc (ts)))
2124
+ end
2125
+ end
2109
2126
end
2110
2127
2111
2128
"""
@@ -2127,6 +2144,41 @@ function get_testset_depth()
2127
2144
something (Base. ScopedValues. get (TESTSET_DEPTH))
2128
2145
end
2129
2146
2147
+ """
2148
+ Print testset entry/exit messages when JULIA_TEST_VERBOSE is set
2149
+ """
2150
+ function print_testset_verbose (action:: Symbol , ts:: AbstractTestSet )
2151
+ something (Base. ScopedValues. get (VERBOSE_TESTSETS)) || return
2152
+ indent = " " ^ get_testset_depth ()
2153
+ desc = if hasfield (typeof (ts), :description )
2154
+ ts. description
2155
+ elseif isa (ts, ContextTestSet)
2156
+ string (ts. context_name, " = " , ts. context)
2157
+ else
2158
+ string (typeof (ts))
2159
+ end
2160
+ if action === :enter
2161
+ println (" $(indent) Starting testset: $desc " )
2162
+ elseif action === :exit
2163
+ duration_str = " "
2164
+ # Calculate duration for testsets that have timing information
2165
+ if hasfield (typeof (ts), :time_start ) && hasfield (typeof (ts), :showtiming )
2166
+ if ts. showtiming
2167
+ current_time = time ()
2168
+ dur_s = current_time - ts. time_start
2169
+ if dur_s < 60
2170
+ duration_str = " ($(round (dur_s, digits = 1 )) s)"
2171
+ else
2172
+ m, s = divrem (dur_s, 60 )
2173
+ s = lpad (string (round (s, digits = 1 )), 4 , " 0" )
2174
+ duration_str = " ($(round (Int, m)) m$(s) s)"
2175
+ end
2176
+ end
2177
+ end
2178
+ println (" $(indent) Finished testset: $desc$duration_str " )
2179
+ end
2180
+ end
2181
+
2130
2182
_args_and_call ((args... , f). .. ; kwargs... ) = (args, kwargs, f (args... ; kwargs... ))
2131
2183
_materialize_broadcasted (f, args... ) = Broadcast. materialize (Broadcast. broadcasted (f, args... ))
2132
2184
0 commit comments