Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Sources/Workspace/InitPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,12 @@ public final class InitPackage {
}

switch packageType {
case .empty, .executable, .tool, .buildToolPlugin, .commandPlugin: return
default: break
case .empty, .buildToolPlugin, .commandPlugin:
return
case .library, .executable, .tool, .macro:
break
}

let tests = destinationPath.appending("Tests")
guard self.fileSystem.exists(tests) == false else {
return
Expand Down Expand Up @@ -873,9 +876,11 @@ public final class InitPackage {
try makeDirectories(testModule)

let testClassFile = try AbsolutePath(validating: "\(moduleName)Tests.swift", relativeTo: testModule)

switch packageType {
case .empty, .buildToolPlugin, .commandPlugin, .executable, .tool: break
case .library:
case .empty, .buildToolPlugin, .commandPlugin:
break
case .library, .executable, .tool:
try writeLibraryTestsFile(testClassFile)
case .macro:
try writeMacroTestsFile(testClassFile)
Expand Down
56 changes: 56 additions & 0 deletions Tests/WorkspaceTests/InitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,62 @@ final class InitTests: XCTestCase {
}
}

func testInitPackageExecutableWithSwiftTesting() async throws {
try testWithTemporaryDirectory { tmpPath in
let fs = localFileSystem
let path = tmpPath.appending("Foo")
let name = path.basename
try fs.createDirectory(path)
// Create the package
let initPackage = try InitPackage(
name: name,
packageType: .executable,
supportedTestingLibraries: [.swiftTesting],
destinationPath: path,
fileSystem: localFileSystem
)

try initPackage.writePackageStructure()
// Verify basic file system content that we expect in the package
let manifest = path.appending("Package.swift")
XCTAssertFileExists(manifest)
let testFile = path.appending("Tests").appending("FooTests").appending("FooTests.swift")
let testFileContents: String = try localFileSystem.readFileContents(testFile)
XCTAssertMatch(testFileContents, .contains(#"import Testing"#))
XCTAssertNoMatch(testFileContents, .contains(#"import XCTest"#))
XCTAssertMatch(testFileContents, .contains(#"@Test func example() async throws"#))
XCTAssertNoMatch(testFileContents, .contains("func testExample() throws"))
}
}

func testInitPackageToolWithSwiftTesting() async throws {
try testWithTemporaryDirectory { tmpPath in
let fs = localFileSystem
let path = tmpPath.appending("Foo")
let name = path.basename
try fs.createDirectory(path)
// Create the package
let initPackage = try InitPackage(
name: name,
packageType: .tool,
supportedTestingLibraries: [.swiftTesting],
destinationPath: path,
fileSystem: localFileSystem
)

try initPackage.writePackageStructure()
// Verify basic file system content that we expect in the package
let manifest = path.appending("Package.swift")
XCTAssertFileExists(manifest)
let testFile = path.appending("Tests").appending("FooTests").appending("FooTests.swift")
let testFileContents: String = try localFileSystem.readFileContents(testFile)
XCTAssertMatch(testFileContents, .contains(#"import Testing"#))
XCTAssertNoMatch(testFileContents, .contains(#"import XCTest"#))
XCTAssertMatch(testFileContents, .contains(#"@Test func example() async throws"#))
XCTAssertNoMatch(testFileContents, .contains("func testExample() throws"))
}
}

func testInitPackageCommandPlugin() throws {
try testWithTemporaryDirectory { tmpPath in
let fs = localFileSystem
Expand Down