@@ -25,30 +25,24 @@ class TestEntryPointGenerationTaskAction: TaskAction {
2525 let options = try Options . parse ( Array ( task. commandLineAsStrings. dropFirst ( ) ) )
2626
2727 var tests : [ IndexStore . TestCaseClass ] = [ ]
28- if options. discoverTests {
29- var objects : [ Path ] = [ ]
30- for linkerFilelist in options. linkerFilelist {
31- let filelistContents = String ( String ( decoding: try executionDelegate. fs. read ( linkerFilelist) , as: UTF8 . self) )
32- let entries = filelistContents. split ( separator: " \n " , omittingEmptySubsequences: true ) . map { Path ( $0) } . map {
33- for indexUnitBasePath in options. indexUnitBasePath {
34- if let remappedPath = generateIndexOutputPath ( from: $0, basePath: indexUnitBasePath) {
35- return remappedPath
36- }
28+ var objects : [ Path ] = [ ]
29+ for linkerFilelist in options. linkerFilelist {
30+ let filelistContents = String ( String ( decoding: try executionDelegate. fs. read ( linkerFilelist) , as: UTF8 . self) )
31+ let entries = filelistContents. split ( separator: " \n " , omittingEmptySubsequences: true ) . map { Path ( $0) } . map {
32+ for indexUnitBasePath in options. indexUnitBasePath {
33+ if let remappedPath = generateIndexOutputPath ( from: $0, basePath: indexUnitBasePath) {
34+ return remappedPath
3735 }
38- return $0
3936 }
40- objects. append ( contentsOf: entries)
41- }
42- guard let indexStoreLibraryPath = options. indexStoreLibraryPath else {
43- outputDelegate. emitError ( " Test discovery was requested, but failed to lookup index store library in toolchain " )
44- return . failed
45- }
46- let indexStoreAPI = try IndexStoreAPI ( dylib: indexStoreLibraryPath)
47- for indexStore in options. indexStore {
48- let store = try IndexStore . open ( store: indexStore, api: indexStoreAPI)
49- let testInfo = try store. listTests ( in: objects)
50- tests. append ( contentsOf: testInfo)
37+ return $0
5138 }
39+ objects. append ( contentsOf: entries)
40+ }
41+ let indexStoreAPI = try IndexStoreAPI ( dylib: options. indexStoreLibraryPath)
42+ for indexStore in options. indexStore {
43+ let store = try IndexStore . open ( store: indexStore, api: indexStoreAPI)
44+ let testInfo = try store. listTests ( in: objects)
45+ tests. append ( contentsOf: testInfo)
5246 }
5347
5448 try executionDelegate. fs. write ( options. output, contents: ByteString ( encodingAsUTF8: """
@@ -58,7 +52,7 @@ class TestEntryPointGenerationTaskAction: TaskAction {
5852
5953 \( testObservationFragment)
6054
61- public import XCTest
55+ import XCTest
6256 \( discoveredTestsFragment ( tests: tests) )
6357
6458 @main
@@ -100,7 +94,16 @@ class TestEntryPointGenerationTaskAction: TaskAction {
10094 }
10195 }
10296 #endif
103- \( xctestFragment ( enableExperimentalTestOutput: options. enableExperimentalTestOutput, disable: !options. discoverTests) )
97+ if testingLibrary == " xctest " {
98+ #if !os(Windows) && \( options. enableExperimentalTestOutput)
99+ _ = Self.testOutputPath().map { SwiftPMXCTestObserver(testOutputPath: testOutputPath) }
100+ #endif
101+ #if os(WASI)
102+ await XCTMain(__allDiscoveredTests()) as Never
103+ #else
104+ XCTMain(__allDiscoveredTests()) as Never
105+ #endif
106+ }
104107 }
105108 #else
106109 static func main() async {
@@ -110,7 +113,16 @@ class TestEntryPointGenerationTaskAction: TaskAction {
110113 await Testing.__swiftPMEntryPoint() as Never
111114 }
112115 #endif
113- \( xctestFragment ( enableExperimentalTestOutput: options. enableExperimentalTestOutput, disable: !options. discoverTests) )
116+ if testingLibrary == " xctest " {
117+ #if !os(Windows) && \( options. enableExperimentalTestOutput)
118+ _ = Self.testOutputPath().map { SwiftPMXCTestObserver(testOutputPath: testOutputPath) }
119+ #endif
120+ #if os(WASI)
121+ await XCTMain(__allDiscoveredTests()) as Never
122+ #else
123+ XCTMain(__allDiscoveredTests()) as Never
124+ #endif
125+ }
114126 }
115127 #endif
116128 }
@@ -125,18 +137,14 @@ class TestEntryPointGenerationTaskAction: TaskAction {
125137
126138 private struct Options : ParsableArguments {
127139 @Option var output : Path
128- @Option var indexStoreLibraryPath : Path ? = nil
129- @Option ( ) var linkerFilelist : [ Path ] = [ ]
130- @Option var indexStore : [ Path ] = [ ]
131- @Option var indexUnitBasePath : [ Path ] = [ ]
140+ @Option var indexStoreLibraryPath : Path
141+ @Option var linkerFilelist : [ Path ]
142+ @Option var indexStore : [ Path ]
143+ @Option var indexUnitBasePath : [ Path ]
132144 @Flag var enableExperimentalTestOutput : Bool = false
133- @Flag var discoverTests : Bool = false
134145 }
135146
136147 private func discoveredTestsFragment( tests: [ IndexStore . TestCaseClass ] ) -> String {
137- guard !tests. isEmpty else {
138- return " "
139- }
140148 var fragment = " "
141149 for moduleName in Set ( tests. map { $0. module } ) . sorted ( ) {
142150 fragment += " @testable import \( moduleName) \n "
@@ -166,29 +174,11 @@ class TestEntryPointGenerationTaskAction: TaskAction {
166174 return fragment
167175 }
168176
169- private func xctestFragment( enableExperimentalTestOutput: Bool , disable: Bool ) -> String {
170- guard !disable else {
171- return " "
172- }
173- return """
174- if testingLibrary == " xctest " {
175- #if !os(Windows) && \( enableExperimentalTestOutput)
176- _ = Self.testOutputPath().map { SwiftPMXCTestObserver(testOutputPath: testOutputPath) }
177- #endif
178- #if os(WASI)
179- await XCTMain(__allDiscoveredTests()) as Never
180- #else
181- XCTMain(__allDiscoveredTests()) as Never
182- #endif
183- }
184- """
185- }
186-
187177 private var testObservationFragment : String =
188178 """
189179 #if !os(Windows) // Test observation is not supported on Windows
190- public import Foundation
191- public import XCTest
180+ import Foundation
181+ import XCTest
192182
193183 public final class SwiftPMXCTestObserver: NSObject {
194184 let testOutputPath: String
@@ -572,7 +562,7 @@ class TestEntryPointGenerationTaskAction: TaskAction {
572562 }
573563 }
574564
575- public import XCTest
565+ import XCTest
576566
577567 #if canImport(Darwin) // XCTAttachment is unavailable in swift-corelibs-xctest.
578568 extension TestAttachment {
0 commit comments