@@ -30,17 +30,19 @@ func entryPoint(passing args: __CommandLineArguments_v0?, eventHandler: Event.Ha
3030
3131 do {
3232#if !SWT_NO_EXIT_TESTS
33- // If an exit test was specified, run it. `exitTest` returns `Never`.
34- if let exitTest = ExitTest . findInEnvironmentForEntryPoint ( ) {
35- await exitTest ( )
36- }
33+ // If an exit test was specified, run it. `exitTest` returns `Never`.
34+ if let exitTest = ExitTest . findInEnvironmentForEntryPoint ( ) {
35+ await exitTest ( )
36+ }
3737#endif
3838
3939 let args = try args ?? parseCommandLineArguments ( from: CommandLine . arguments)
4040
41- if let library = args. testingLibrary. flatMap ( Library . init ( named: ) ) {
41+ #if !SWT_NO_RUNTIME_LIBRARY_DISCOVERY
42+ if let library = args. testingLibrary. flatMap ( Library . init ( withHint: ) ) {
4243 return await library. callEntryPoint ( passing: args)
4344 }
45+ #endif
4446
4547 // Configure the test runner.
4648 var configuration = try configurationForEntryPoint ( from: args)
@@ -96,7 +98,7 @@ func entryPoint(passing args: __CommandLineArguments_v0?, eventHandler: Event.Ha
9698
9799 // The set of matching tests (or, in the case of `swift test list`, the set
98100 // of all tests.)
99- let tests : [ Test ]
101+ var tests = [ Test] ( )
100102
101103 if args. listTests ?? false {
102104 tests = await Array ( Test . all)
@@ -117,6 +119,28 @@ func entryPoint(passing args: __CommandLineArguments_v0?, eventHandler: Event.Ha
117119 for test in tests {
118120 Event . post ( . testDiscovered, for: ( test, nil ) , configuration: configuration)
119121 }
122+ } else if args. experimentalListLibraries ?? false {
123+ #if !SWT_NO_RUNTIME_LIBRARY_DISCOVERY
124+ let libraries = Library . all
125+ #else
126+ let libraries = [ Library . swiftTesting]
127+ #endif
128+
129+ if args. verbosity > . min {
130+ for library in libraries {
131+ // Print the test ID to stdout (classical CLI behavior.)
132+ #if SWT_TARGET_OS_APPLE && !SWT_NO_FILE_IO
133+ try ? FileHandle . stdout. write ( " \( library. name) ( \( library. canonicalHint) ) \n " )
134+ #else
135+ print ( " \( library. name) ( \( library. canonicalHint) ) " )
136+ #endif
137+ }
138+ }
139+
140+ // Post an event for every discovered library (as with tests above).
141+ for library in libraries {
142+ Event . post ( . libraryDiscovered( library) , for: ( nil , nil ) , configuration: configuration)
143+ }
120144 } else {
121145 // Run the tests.
122146 let runner = await Runner ( configuration: configuration)
@@ -212,6 +236,9 @@ public struct __CommandLineArguments_v0: Sendable {
212236 /// The value of the `--list-tests` argument.
213237 public var listTests : Bool ?
214238
239+ /// The value of the `--experimental-list-libraries` argument.
240+ public var experimentalListLibraries : Bool ?
241+
215242 /// The value of the `--parallel` or `--no-parallel` argument.
216243 public var parallel : Bool ?
217244
@@ -346,6 +373,7 @@ extension __CommandLineArguments_v0: Codable {
346373 // do not end up with leading underscores when encoded.
347374 enum CodingKeys : String , CodingKey {
348375 case listTests
376+ case experimentalListLibraries
349377 case parallel
350378 case experimentalMaximumParallelizationWidth
351379 case symbolicateBacktraces
@@ -476,7 +504,7 @@ func parseCommandLineArguments(from args: [String]) throws -> __CommandLineArgum
476504#endif
477505
478506 // Testing library
479- if let testingLibrary = args. argumentValue ( forLabel: " --testing-library " ) {
507+ if let testingLibrary = Environment . variable ( named : " SWT_EXPERIMENTAL_LIBRARY " ) ?? args. argumentValue ( forLabel: " --testing-library " ) {
480508 result. testingLibrary = testingLibrary
481509 }
482510
@@ -498,6 +526,9 @@ func parseCommandLineArguments(from args: [String]) throws -> __CommandLineArgum
498526 // makes invocation from e.g. Wasmtime a bit more intuitive/idiomatic.
499527 result. listTests = true
500528 }
529+ if Environment . flag ( named: " SWT_EXPERIMENTAL_LIST_LIBRARIES " ) == true || args. contains ( " --experimental-list-libraries " ) {
530+ result. experimentalListLibraries = true
531+ }
501532
502533 // Parallelization (on by default)
503534 if args. contains ( " --no-parallel " ) {
0 commit comments