@@ -2235,12 +2235,30 @@ function free(ctx::Context, pkgs::Vector{PackageSpec}; err_if_free = true)
22352235 end
22362236end
22372237
2238- function gen_test_code (source_path:: String ; test_args:: Cmd )
2238+ function gen_test_code (source_path:: String ; test_args:: Cmd , testsets :: Union{Nothing, AbstractVector{<:AbstractString}} = nothing )
22392239 test_file = testfile (source_path)
2240+
2241+ # Generate testset filtering setup if testsets are specified
2242+ testset_setup = if testsets != = nothing && ! isempty (testsets)
2243+ """
2244+ # Set up testset filtering
2245+ using Test
2246+ testsets_discovered = Test.discover_testsets($(repr (test_file)) )
2247+ testset_filter = Test.create_testset_filter(testsets_discovered, $(repr (collect (testsets))) )
2248+ Test.TESTSET_FILTER[] = testset_filter
2249+ println("Testset filtering active: \$ (length(testset_filter.enabled_testset_ids)) testsets enabled from patterns \$ (testset_filter.enabled_patterns)")
2250+ println("Enabled testsets:")
2251+ Test.show_tree(testsets_discovered, enabled_only=true)
2252+ """
2253+ else
2254+ " "
2255+ end
2256+
22402257 return """
22412258 $(Base. load_path_setup_code (false ))
22422259 cd($(repr (dirname (test_file))) )
22432260 append!(empty!(ARGS), $(repr (test_args. exec)) )
2261+ $testset_setup
22442262 include($(repr (test_file)) )
22452263 """
22462264end
@@ -2523,6 +2541,7 @@ function test(
25232541 ctx:: Context , pkgs:: Vector{PackageSpec} ;
25242542 coverage = false , julia_args:: Cmd = ` ` , test_args:: Cmd = ` ` ,
25252543 test_fn = nothing ,
2544+ testsets:: Union{Nothing, AbstractVector{<:AbstractString}} = nothing ,
25262545 force_latest_compatible_version:: Bool = false ,
25272546 allow_earlier_backwards_compatible_versions:: Bool = true ,
25282547 allow_reresolve:: Bool = true
@@ -2583,7 +2602,7 @@ function test(
25832602
25842603 printpkgstyle (ctx. io, :Testing , " Running tests..." )
25852604 flush (ctx. io)
2586- code = gen_test_code (source_path; test_args)
2605+ code = gen_test_code (source_path; test_args, testsets )
25872606 cmd = ` $(Base. julia_cmd ()) $(flags) --eval $code `
25882607
25892608 path_sep = Sys. iswindows () ? ' ;' : ' :'
@@ -2626,7 +2645,7 @@ function test(
26262645
26272646 printpkgstyle (ctx. io, :Testing , " Running tests..." )
26282647 flush (ctx. io)
2629- code = gen_test_code (source_path; test_args)
2648+ code = gen_test_code (source_path; test_args, testsets )
26302649 cmd = ` $(Base. julia_cmd ()) --threads=$(get_threads_spec ()) $(flags) --eval $code `
26312650 p, interrupted = subprocess_handler (cmd, ctx. io, " Tests interrupted. Exiting the test process" )
26322651 if success (p)
0 commit comments