@@ -9,6 +9,7 @@ using TestEnv
99using Logging: current_logger, with_logger
1010
1111export runtests, runtestitem
12+ export print_tests
1213export @testsetup , @testitem
1314export TestSetup, TestItem, TestItemResult
1415
@@ -231,15 +232,18 @@ will be run.
231232"""
232233function runtests end
233234
234- runtests (; kw... ) = runtests (Returns (true ), dirname (Base. active_project ()); kw... )
235- runtests (shouldrun; kw... ) = runtests (shouldrun, dirname (Base. active_project ()); kw... )
236- runtests (paths:: AbstractString... ; kw... ) = runtests (Returns (true ), paths... ; kw... )
237-
238- runtests (pkg:: Module ; kw... ) = runtests (Returns (true ), pkg; kw... )
239- function runtests (shouldrun, pkg:: Module ; kw... )
240- dir = pkgdir (pkg)
241- isnothing (dir) && error (" Could not find directory for `$pkg `" )
242- return runtests (shouldrun, dir; kw... )
235+ for func in (:runtests , :print_tests )
236+ @eval begin
237+ $ func (; kw... ) = $ func (Returns (true ), dirname (Base. active_project ()); kw... )
238+ $ func (shouldrun; kw... ) = $ func (shouldrun, dirname (Base. active_project ()); kw... )
239+ $ func (paths:: AbstractString... ; kw... ) = $ func (Returns (true ), paths... ; kw... )
240+ $ func (pkg:: Module ; kw... ) = $ func (Returns (true ), pkg; kw... )
241+ function $func (shouldrun, pkg:: Module ; kw... )
242+ dir = pkgdir (pkg)
243+ isnothing (dir) && error (" Could not find directory for `$pkg `" )
244+ return $ func (shouldrun, dir; kw... )
245+ end
246+ end
243247end
244248
245249@kwdef struct _Config
257261 timeout_profile_wait:: Int
258262 memory_threshold:: Float64
259263 gc_between_testitems:: Bool
264+ dryrun:: Bool
260265end
261266
267+ default_validate_paths () = parse (Bool, get (ENV , " RETESTITEMS_VALIDATE_PATHS" , " false" ))
262268
263269function runtests (
264270 shouldrun,
@@ -276,11 +282,12 @@ function runtests(
276282 logs:: Symbol = Symbol (get (ENV , " RETESTITEMS_LOGS" , default_log_display_mode (report, nworkers))),
277283 verbose_results:: Bool = (logs != = :issues && isinteractive ()),
278284 test_end_expr:: Expr = Expr (:block ),
279- validate_paths:: Bool = parse (Bool, get ( ENV , " RETESTITEMS_VALIDATE_PATHS " , " false " ) ),
285+ validate_paths:: Bool = default_validate_paths ( ),
280286 timeout_profile_wait:: Real = parse (Int, get (ENV , " RETESTITEMS_TIMEOUT_PROFILE_WAIT" , " 0" )),
281287 gc_between_testitems:: Bool = parse (Bool, get (ENV , " RETESTITEMS_GC_BETWEEN_TESTITEMS" , string (nworkers > 1 ))),
282288 failfast:: Bool = parse (Bool, get (ENV , " RETESTITEMS_FAILFAST" , " false" )),
283289 testitem_failfast:: Bool = parse (Bool, get (ENV , " RETESTITEMS_TESTITEM_FAILFAST" , string (failfast))),
290+ dryrun:: Bool = parse (Bool, get (ENV , " RETESTITEMS_DRYRUN" , " false" )),
284291)
285292 nworker_threads = _validated_nworker_threads (nworker_threads)
286293 paths′ = _validated_paths (paths, validate_paths)
@@ -301,7 +308,7 @@ function runtests(
301308 (timeout_profile_wait > 0 && Sys. iswindows ()) && @warn " CPU profiles on timeout is not supported on Windows, ignoring `timeout_profile_wait`"
302309 mkpath (RETESTITEMS_TEMP_FOLDER[]) # ensure our folder wasn't removed
303310 save_current_stdio ()
304- cfg = _Config (; nworkers, nworker_threads, worker_init_expr, test_end_expr, testitem_timeout, testitem_failfast, failfast, retries, logs, report, verbose_results, timeout_profile_wait, memory_threshold, gc_between_testitems)
311+ cfg = _Config (; nworkers, nworker_threads, worker_init_expr, test_end_expr, testitem_timeout, testitem_failfast, failfast, retries, logs, report, verbose_results, timeout_profile_wait, memory_threshold, gc_between_testitems, dryrun )
305312 debuglvl = Int (debug)
306313 if debuglvl > 0
307314 withdebug (debuglvl) do
@@ -312,6 +319,21 @@ function runtests(
312319 end
313320end
314321
322+ """
323+ ReTestItems.print_tests()
324+ ReTestItems.print_tests(mod::Module)
325+ ReTestItems.print_tests(paths::AbstractString...)
326+
327+ Print the tests that would be run by `runtests`.
328+ Also available via `runtests(args...; dryrun=true, kw...)`.
329+ """
330+ function print_tests (
331+ shouldrun, paths:: AbstractString... ;
332+ name= nothing , tags= nothing , validate_paths= default_validate_paths (),
333+ )
334+ runtests (shouldrun, paths... ; dryrun= true , name, tags, validate_paths)
335+ end
336+
315337# keep track of temporary test environments we create in case we can reuse them
316338# on repeated runs of `runtests` in the same Project
317339# in https://relationalai.atlassian.net/browse/RAI-11599, it was noted that when
@@ -339,8 +361,9 @@ function _runtests(ti_filter, paths, cfg::_Config)
339361 # Wrapping with the logger that was set before eval'ing any user code to
340362 # avoid world age issues when logging https://github.com/JuliaLang/julia/issues/33865
341363 with_logger (current_logger ()) do
342- if is_running_test_runtests_jl (proj_file)
364+ if is_running_test_runtests_jl (proj_file) || cfg . dryrun
343365 # Assume this is `Pkg.test`, so test env already active.
366+ # Or if `dryrun`, we don't need the env as we won't run the tests.
344367 @debugv 2 " Running in current environment `$(Base. active_project ()) `"
345368 return _runtests_in_current_env (ti_filter, paths, proj_file, cfg)
346369 else
@@ -377,10 +400,8 @@ function _runtests_in_current_env(
377400 ntestitems = length (testitems. testitems)
378401 @debugv 1 " Done including tests in $paths "
379402 @info " Finished scanning for test items in $(round (time () - inc_time, digits= 2 )) seconds."
380- # TODO : make this a keyword to `runtests` that gets passed to `_runtests_in_current_env`
381- dryrun = parse (Bool, get (ENV , " RETESTITEMS_DRYRUN" , " false" )):: Bool
382- if dryrun
383- print_testitems (testitems)
403+ if cfg. dryrun
404+ _print_testitems (testitems)
384405 return nothing
385406 end
386407 @info " Scheduling $ntestitems tests on pid $(Libc. getpid ()) " *
0 commit comments