Skip to content

Commit d044391

Browse files
committed
[Tests] Convert InitTests to Swift Testing
1 parent 7dfca5a commit d044391

File tree

2 files changed

+388
-381
lines changed

2 files changed

+388
-381
lines changed

Sources/_InternalTestSupport/SwiftTesting+Helpers.swift

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,32 @@
1111
import Basics
1212
import Testing
1313

14+
// MARK: File System Helpers
15+
16+
/// Verifies that a file exists at the specified path.
17+
///
18+
/// - Parameters:
19+
/// - path: The absolute path to check for file existence.
20+
/// - sourceLocation: The source location where the expectation is made.
1421
public func expectFileExists(
1522
at path: AbsolutePath,
23+
sourceLocation: SourceLocation = #_sourceLocation,
24+
) {
25+
#expect(
26+
localFileSystem.exists(path),
27+
"Files '\(path)' does not exist.",
28+
sourceLocation: sourceLocation,
29+
)
30+
}
31+
32+
/// Verifies that a file does not exist at the specified path.
33+
///
34+
/// - Parameters:
35+
/// - fixturePath: The absolute path to check for file non-existence.
36+
/// - comment: An optional comment to include in the failure message.
37+
/// - sourceLocation: The source location where the expectation is made.
38+
public func expectFileDoesNotExists(
39+
at fixturePath: AbsolutePath,
1640
_ comment: Comment? = nil,
1741
sourceLocation: SourceLocation = #_sourceLocation,
1842
) {
@@ -59,6 +83,12 @@ public func expectFileDoesNotExists(
5983
)
6084
}
6185

86+
/// Verifies that a file exists and is executable at the specified path.
87+
///
88+
/// - Parameters:
89+
/// - fixturePath: The absolute path to check for executable file existence.
90+
/// - comment: An optional comment to include in the failure message.
91+
/// - sourceLocation: The source location where the expectation is made.
6292
public func expectFileIsExecutable(
6393
at fixturePath: AbsolutePath,
6494
_ comment: Comment? = nil,
@@ -77,6 +107,11 @@ public func expectFileIsExecutable(
77107
)
78108
}
79109

110+
/// Verifies that a directory exists at the specified path.
111+
///
112+
/// - Parameters:
113+
/// - path: The absolute path to check for directory existence.
114+
/// - sourceLocation: The source location where the expectation is made.
80115
public func expectDirectoryExists(
81116
at path: AbsolutePath,
82117
sourceLocation: SourceLocation = #_sourceLocation,
@@ -94,6 +129,11 @@ let msgSuffix: String
94129
)
95130
}
96131

132+
/// Verifies that a directory does not exist at the specified path.
133+
///
134+
/// - Parameters:
135+
/// - path: The absolute path to check for directory non-existence.
136+
/// - sourceLocation: The source location where the expectation is made.
97137
public func expectDirectoryDoesNotExist(
98138
at path: AbsolutePath,
99139
sourceLocation: SourceLocation = #_sourceLocation,
@@ -111,6 +151,15 @@ public func expectDirectoryDoesNotExist(
111151
)
112152
}
113153

154+
// MARK: Error Helpers
155+
156+
/// Verifies that an expression throws a `CommandExecutionError`.
157+
///
158+
/// - Parameters:
159+
/// - expression: The expression to evaluate.
160+
/// - message: An optional description of the failure.
161+
/// - sourceLocation: The source location where the expectation is made.
162+
/// - errorHandler: A closure that's called with the error if the expression throws.
114163
public func expectThrowsCommandExecutionError<T>(
115164
_ expression: @autoclosure () async throws -> T,
116165
_ message: @autoclosure () -> Comment = "",
@@ -129,7 +178,13 @@ public func expectThrowsCommandExecutionError<T>(
129178
}
130179
}
131180

132-
/// An `async`-friendly replacement for `XCTAssertThrowsError`.
181+
/// An async-friendly replacement for `XCTAssertThrowsError` that verifies an expression throws an error.
182+
///
183+
/// - Parameters:
184+
/// - expression: The expression to evaluate that should throw an error.
185+
/// - message: An optional failure message to display if the expression doesn't throw.
186+
/// - sourceLocation: The source location where the expectation is made.
187+
/// - errorHandler: A closure that's called with the error if the expression throws.
133188
public func expectAsyncThrowsError<T>(
134189
_ expression: @autoclosure () async throws -> T,
135190
_ message: @autoclosure () -> Comment? = nil,

0 commit comments

Comments
 (0)