Skip to content

Commit cf2afca

Browse files
committed
[TestSupport] Move XCTAssertThrows into test support.
1 parent dc8c63d commit cf2afca

File tree

6 files changed

+25
-26
lines changed

6 files changed

+25
-26
lines changed

Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ let package = Package(
111111

112112
// MARK: Additional Test Dependencies
113113

114+
Target(
115+
name: "BasicTests",
116+
dependencies: ["TestSupport"]),
114117
Target(
115118
name: "BuildTests",
116119
dependencies: ["Build", "TestSupport"]),

Sources/TestSupport/XCTAssertHelpers.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import func XCTest.XCTFail
11+
import XCTest
1212

1313
import Basic
1414
import POSIX
@@ -67,3 +67,15 @@ public func XCTAssertNoSuchPath(_ path: AbsolutePath, file: StaticString = #file
6767
XCTFail("path exists but should not: \(path.asString)", file: file, line: line)
6868
}
6969
}
70+
71+
public func XCTAssertThrows<T: Swift.Error>(_ expectedError: T, file: StaticString = #file, line: UInt = #line, _ body: () throws -> ()) where T: Equatable {
72+
do {
73+
try body()
74+
XCTFail("body completed successfully", file: file, line: line)
75+
} catch let error as T {
76+
XCTAssertEqual(error, expectedError, file: file, line: line)
77+
} catch {
78+
XCTFail("unexpected error thrown", file: file, line: line)
79+
}
80+
}
81+

Tests/BasicTests/FileSystemTests.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,7 @@ import XCTest
1313
import Basic
1414
import POSIX
1515

16-
func XCTAssertThrows<T: Swift.Error>(_ expectedError: T, file: StaticString = #file, line: UInt = #line, _ body: () throws -> ()) where T: Equatable {
17-
do {
18-
try body()
19-
XCTFail("body completed successfully", file: file, line: line)
20-
} catch let error as T {
21-
XCTAssertEqual(error, expectedError, file: file, line: line)
22-
} catch {
23-
XCTFail("unexpected error thrown", file: file, line: line)
24-
}
25-
}
16+
import TestSupport
2617

2718
class FileSystemTests: XCTestCase {
2819

Tests/BasicTests/GraphAlgorithmsTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import XCTest
1212

1313
import Basic
1414

15+
import TestSupport
16+
1517
private func topologicalSort(_ nodes: [Int], _ successors: [Int: [Int]]) throws -> [Int] {
1618
return try topologicalSort(nodes, successors: { successors[$0] ?? [] })
1719
}

Tests/SourceControlTests/GitRepositoryTests.swift

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,13 @@
1010

1111
import XCTest
1212

13-
import TestSupport
1413
import Basic
1514
import SourceControl
1615
import Utility
1716

18-
@testable import class SourceControl.GitRepository
17+
import TestSupport
1918

20-
// FIXME: Move to Utilities.
21-
func XCTAssertThrows<T: Swift.Error>(_ expectedError: T, file: StaticString = #file, line: UInt = #line, _ body: () throws -> ()) where T: Equatable {
22-
do {
23-
try body()
24-
XCTFail("body completed successfully", file: file, line: line)
25-
} catch let error as T {
26-
XCTAssertEqual(error, expectedError, file: file, line: line)
27-
} catch {
28-
XCTFail("unexpected error thrown", file: file, line: line)
29-
}
30-
}
19+
@testable import class SourceControl.GitRepository
3120

3221
class GitRepositoryTests: XCTestCase {
3322
/// Test the basic provider functions.

Utilities/bootstrap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ def parse_manifest():
307307
targets = list(map(convert, pattern.finditer(manifest_data)))
308308

309309
# Remove the targets which should be ignored in stage 1.
310-
targets = [target for target in targets if target.name not in g_ignored_targets]
310+
targets = [target for target in targets
311+
if target.name not in g_ignored_targets and
312+
not target.name.endswith("Tests")]
311313

312314
# substitute strings for Target objects
313315
for target in targets:
@@ -340,7 +342,7 @@ def parse_manifest():
340342
# Hard-coded target definition.
341343
g_project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
342344
g_source_root = os.path.join(g_project_root, "Sources")
343-
g_ignored_targets = ["swiftpm-xctest-helper", "TestSupport", "BuildTests", "CommandsTests", "FunctionalTests", "GetTests", "PackageLoadingTests", "SourceControlTests", "UtilityTests"]
345+
g_ignored_targets = ["swiftpm-xctest-helper", "TestSupport"]
344346
targets = parse_manifest()
345347
target_map = dict((t.name, t) for t in targets)
346348

0 commit comments

Comments
 (0)