@@ -104,13 +104,13 @@ struct InitTests {
104104 #expect( manifestContents. contains ( " .testTarget( " ) )
105105 }
106106
107- try customVerification ? ( path, packageName)
108-
109107 if let buildSystem = buildSystem {
110108 await expectBuilds ( path, buildSystem: buildSystem, configurations: Set ( [ buildConfiguration] ) )
111109
112110 try verifyBuildProducts ( for: packageType, at: path, name: packageName, buildSystem: buildSystem, buildConfiguration: buildConfiguration)
113111 }
112+
113+ try customVerification ? ( path, packageName)
114114 }
115115 }
116116
@@ -152,28 +152,11 @@ struct InitTests {
152152 if hasSwiftTesting {
153153 #expect( testFileContents. contains ( #"import Testing"# ) )
154154 #expect( testFileContents. contains ( #"@Test func"# ) )
155- } else {
156- #expect( !testFileContents. contains ( #"import Testing"# ) )
157- #expect( !testFileContents. contains ( #"@Test func"# ) )
158155 }
159156
160157 if hasXCTest {
161158 #expect( testFileContents. contains ( #"import XCTest"# ) )
162159 #expect( testFileContents. contains ( " func test " ) )
163-
164- if hasSwiftTesting {
165- // When both are present, ensure XCTest content is properly formatted
166- #expect( testFileContents. contains ( " import XCTest " ) , " XCTest import should be present " )
167- } else {
168- // When only XCTest is present, ensure it's at the beginning of the file
169- #expect( testFileContents. hasPrefix ( " import XCTest " ) , """
170- Validates formatting of XCTest source file, in particular that it does not contain leading whitespace:
171- \( testFileContents)
172- """ )
173- }
174- } else {
175- #expect( !testFileContents. contains ( #"import XCTest"# ) )
176- #expect( !testFileContents. contains ( " func test " ) )
177160 }
178161 }
179162
@@ -274,7 +257,7 @@ struct InitTests {
274257 try await createAndVerifyPackage (
275258 packageType: packageType,
276259 supportedTestingLibraries: [ . xctest] ,
277- buildSystem: buildSystemRespectingTestingDisabled ( data. buildSystem) ,
260+ buildSystem: data. buildSystem,
278261 buildConfiguration: data. config,
279262 customVerification: { path, name in
280263 #expect(
@@ -299,21 +282,17 @@ struct InitTests {
299282 try await createAndVerifyPackage (
300283 packageType: packageType,
301284 supportedTestingLibraries: [ . swiftTesting] ,
302- buildSystem: buildSystemRespectingTestingDisabled ( data. buildSystem) ,
285+ buildSystem: data. buildSystem,
303286 buildConfiguration: data. config,
304287 customVerification: { path, name in
305288 try verifyTestFileContents ( at: path, name: name, hasSwiftTesting: true , hasXCTest: false )
289+ let binPath = try data. buildSystem. binPath ( for: data. config, triple: Self . targetTriple. platformBuildPathComponent)
290+ let swiftModule = " \( name) .swiftmodule "
291+ let expectedPath = path
292+ . appending ( components: binPath)
293+ . appending ( components: data. buildSystem == . native ? [ " Modules " , swiftModule] : [ swiftModule] )
306294
307- #if canImport(TestingDisabled)
308- let expectedPath = path. appending ( components:
309- " .build " ,
310- Self . targetTriple. platformBuildPathComponent,
311- " debug " ,
312- " Modules " ,
313- " \( name) .swiftmodule "
314- )
315- try requireFileExists ( at: expectedPath)
316- #endif
295+ expectFileExists ( at: expectedPath)
317296 }
318297 )
319298 }
@@ -324,21 +303,17 @@ struct InitTests {
324303 try await createAndVerifyPackage (
325304 packageType: packageType,
326305 supportedTestingLibraries: [ . swiftTesting, . xctest] ,
327- buildSystem: buildSystemRespectingTestingDisabled ( data. buildSystem) ,
306+ buildSystem: data. buildSystem,
328307 buildConfiguration: data. config,
329308 customVerification: { path, name in
330309 try verifyTestFileContents ( at: path, name: name, hasSwiftTesting: true , hasXCTest: true )
310+ let binPath = try data. buildSystem. binPath ( for: data. config, triple: Self . targetTriple. platformBuildPathComponent)
311+ let swiftModule = " \( name) .swiftmodule "
312+ let expectedPath = path
313+ . appending ( components: binPath)
314+ . appending ( components: data. buildSystem == . native ? [ " Modules " , swiftModule] : [ swiftModule] )
331315
332- #if canImport(TestingDisabled)
333- let expectedPath = path. appending ( components:
334- " .build " ,
335- Self . targetTriple. platformBuildPathComponent,
336- " debug " ,
337- " Modules " ,
338- " \( name) .swiftmodule "
339- )
340316 expectFileExists ( at: expectedPath)
341- #endif
342317 }
343318 )
344319 }
@@ -349,24 +324,21 @@ struct InitTests {
349324 try await createAndVerifyPackage (
350325 packageType: packageType,
351326 supportedTestingLibraries: [ ] ,
352- buildSystem: buildSystemRespectingTestingDisabled ( data. buildSystem) ,
327+ buildSystem: data. buildSystem,
353328 buildConfiguration: data. config,
354329 customVerification: { path, name in
355330 let manifestContents : String = try localFileSystem. readFileContents ( path. appending ( " Package.swift " ) )
356331 #expect( !manifestContents. contains ( #".testTarget"# ) )
357332
358333 expectDirectoryDoesNotExist ( at: path. appending ( " Tests " ) )
359334
360- #if canImport(TestingDisabled)
361- let expectedPath = path. appending ( components:
362- " .build " ,
363- Self . targetTriple. platformBuildPathComponent,
364- " debug " ,
365- " Modules " ,
366- " \( name) .swiftmodule "
367- )
335+ let binPath = try data. buildSystem. binPath ( for: data. config, triple: Self . targetTriple. platformBuildPathComponent)
336+ let swiftModule = " \( name) .swiftmodule "
337+ let expectedPath = path
338+ . appending ( components: binPath)
339+ . appending ( components: data. buildSystem == . native ? [ " Modules " , swiftModule] : [ swiftModule] )
340+
368341 expectFileExists ( at: expectedPath)
369- #endif
370342 }
371343 )
372344 }
@@ -434,7 +406,7 @@ struct InitTests {
434406 }
435407
436408 /// Tests creating a package with a non-C99 compliant name.
437- @Test ( arguments: [ BuildSystemProvider . Kind. native , . swiftbuild ] )
409+ @Test ( arguments: BuildSystemProvider . Kind. allCases )
438410 func nonC99NameExecutablePackage( buildSystem: BuildSystemProvider . Kind ) async throws {
439411 try await withTemporaryDirectory ( removeTreeOnDeinit: true ) { tempDirPath in
440412 let packageRoot = tempDirPath. appending ( " Foo " )
@@ -486,7 +458,8 @@ struct InitTests {
486458 }
487459 }
488460
489- @Test func includesSwiftLanguageMode( ) throws {
461+ @Test ( arguments: [ InitPackage . PackageType. library, . executable, . tool] )
462+ func includesSwiftLanguageMode( packageType: InitPackage . PackageType ) throws {
490463 try testWithTemporaryDirectory { tmpPath in
491464 let fs = localFileSystem
492465 let path = tmpPath. appending ( " testInitPackageIncludesSwiftLanguageMode " )
@@ -496,7 +469,7 @@ struct InitTests {
496469 // Create a library package
497470 let initPackage = try InitPackage (
498471 name: name,
499- packageType: . library ,
472+ packageType: packageType ,
500473 supportedTestingLibraries: [ ] ,
501474 destinationPath: path,
502475 installedSwiftPMConfiguration: . default,
@@ -538,14 +511,4 @@ let package = Package(
538511)
539512"""
540513 }
541-
542- /// Returns the build system to use, respecting whether TestingDisabled is imported.
543- func buildSystemRespectingTestingDisabled( _ buildSystem: BuildSystemProvider . Kind ? ) -> BuildSystemProvider . Kind ? {
544- #if canImport(TestingDisabled)
545- return buildSystem
546- #else
547- return nil
548- #endif
549- }
550-
551514}
0 commit comments