Skip to content

Commit eb1b680

Browse files
committed
Add Swift Testing helper functions
In the process of converted XCTests to Swift Testing, add a few Swift Testing helper functions equivalent to the XCTest equivalents. Unfortunately, I'm unable to write automated tests that verify the new helpers behave as expected as the Swift Testing framework does not currently allow writing tests that verify an issue was recorded. This is tracked under swiftlang/swift-testing#155
1 parent ad2fc22 commit eb1b680

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import Testing
12+
13+
import TSCBasic
14+
15+
public func assertFileExists(
16+
_ path: AbsolutePath,
17+
sourceLocation: SourceLocation = #_sourceLocation
18+
) {
19+
print("localFileSystem.isFile(path) ==> \(localFileSystem.isFile(path))")
20+
#expect(
21+
localFileSystem.isFile(path),
22+
"Expected file doesn't exist: \(path)",
23+
sourceLocation: sourceLocation
24+
)
25+
}
26+
public func assertDirectoryExists(
27+
_ path: AbsolutePath,
28+
sourceLocation: SourceLocation = #_sourceLocation
29+
) {
30+
#expect(
31+
localFileSystem.isDirectory(path),
32+
"Expected directory doesn't exist: \(path)",
33+
sourceLocation: sourceLocation
34+
)
35+
}
36+
37+
public func assertNoDiagnostics(
38+
_ engine: DiagnosticsEngine,
39+
sourceLocation: SourceLocation = #_sourceLocation
40+
) {
41+
let diagnostics = engine.diagnostics
42+
let diags = diagnostics.map({ "- " + $0.description }).joined(separator: "\n")
43+
#expect(
44+
diagnostics.isEmpty,
45+
"Found unexpected diagnostics: \n\(diags)",
46+
sourceLocation: sourceLocation
47+
)
48+
}

0 commit comments

Comments
 (0)