@@ -10,6 +10,13 @@ All tests belong to a *test set*. There is a default, task-level
1010test set that throws on the first failure. Users can choose to wrap 
1111their tests in (possibly nested) test sets that will store results 
1212and 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). 
1320""" 
1421module  Test
1522
@@ -1226,7 +1233,7 @@ mutable struct DefaultTestSet <: AbstractTestSet
12261233    results_lock:: ReentrantLock 
12271234    results:: Vector{Any} 
12281235end 
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 )
12301237    if  isnothing (failfast)
12311238        #  pass failfast state into child testsets
12321239        parent_ts =  get_testset ()
@@ -2103,9 +2110,19 @@ const TESTSET_PRINT_ENABLE = ScopedValue{Bool}(true)
21032110const  TEST_RECORD_PASSES =  LazyScopedValue {Bool} (OncePerProcess {Bool} () do 
21042111    return  Base. get_bool_env (" JULIA_TEST_RECORD_PASSES" false )
21052112end )
2113+ const  VERBOSE_TESTSETS =  LazyScopedValue {Bool} (OncePerProcess {Bool} () do 
2114+     return  Base. get_bool_env (" JULIA_TEST_VERBOSE" false )
2115+ end )
21062116
21072117macro  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 
21092126end 
21102127
21112128""" 
@@ -2127,6 +2144,41 @@ function get_testset_depth()
21272144    something (Base. ScopedValues. get (TESTSET_DEPTH))
21282145end 
21292146
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, "  = " . 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+ 
21302182_args_and_call ((args... , f). .. ; kwargs... ) =  (args, kwargs, f (args... ; kwargs... ))
21312183_materialize_broadcasted (f, args... ) =  Broadcast. materialize (Broadcast. broadcasted (f, args... ))
21322184
0 commit comments