Skip to content

[5.5] Fix new package XCTest file formatting and include throws keyword #3449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
12 changes: 2 additions & 10 deletions Sources/Workspace/InitPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,19 +356,15 @@ public final class InitPackage {
@testable import \(moduleName)

final class \(moduleName)Tests: XCTestCase {
func testExample() {
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
XCTAssertEqual(\(typeName)().text, "Hello, World!")
}

"""

stream <<< """
}

"""
"""
}
}

Expand Down Expand Up @@ -421,10 +417,6 @@ public final class InitPackage {
return Bundle.main.bundleURL
#endif
}

"""

stream <<< """
}

"""
Expand Down
12 changes: 11 additions & 1 deletion Tests/WorkspaceTests/InitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,20 @@ class InitTests: XCTestCase {
XCTAssertTrue(readmeContents.hasPrefix("# Foo\n"))

XCTAssertEqual(try fs.getDirectoryContents(path.appending(component: "Sources").appending(component: "Foo")), ["Foo.swift"])

let tests = path.appending(component: "Tests")
XCTAssertEqual(
try fs.getDirectoryContents(path.appending(component: "Tests")).sorted(),
try fs.getDirectoryContents(tests).sorted(),
["FooTests"])

let testFile = tests.appending(component: "FooTests").appending(component: "FooTests.swift")
let testFileContents = try localFileSystem.readFileContents(testFile).description
XCTAssertTrue(testFileContents.hasPrefix("import XCTest"), """
Validates formatting of XCTest source file, in particular that it does not contain leading whitespace:
\(testFileContents)
""")
XCTAssertTrue(testFileContents.contains("func testExample() throws"), "Contents:\n\(testFileContents)")

// Try building it
XCTAssertBuilds(path)
let triple = Resources.default.toolchain.triple
Expand Down