11
11
import Basics
12
12
import Testing
13
13
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.
14
21
public func expectFileExists(
15
22
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,
16
40
_ comment: Comment? = nil ,
17
41
sourceLocation: SourceLocation = #_sourceLocation,
18
42
) {
@@ -59,6 +83,12 @@ public func expectFileDoesNotExists(
59
83
)
60
84
}
61
85
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.
62
92
public func expectFileIsExecutable(
63
93
at fixturePath: AbsolutePath,
64
94
_ comment: Comment? = nil ,
@@ -77,6 +107,11 @@ public func expectFileIsExecutable(
77
107
)
78
108
}
79
109
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.
80
115
public func expectDirectoryExists (
81
116
at path: AbsolutePath,
82
117
sourceLocation: SourceLocation = #_sourceLocation,
@@ -94,6 +129,11 @@ let msgSuffix: String
94
129
)
95
130
}
96
131
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.
97
137
public func expectDirectoryDoesNotExist (
98
138
at path: AbsolutePath,
99
139
sourceLocation: SourceLocation = #_sourceLocation,
@@ -111,6 +151,15 @@ public func expectDirectoryDoesNotExist(
111
151
)
112
152
}
113
153
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.
114
163
public func expectThrowsCommandExecutionError< T> (
115
164
_ expression: @autoclosure ( ) async throws -> T,
116
165
_ message: @autoclosure ( ) - > Comment = " " ,
@@ -129,7 +178,13 @@ public func expectThrowsCommandExecutionError<T>(
129
178
}
130
179
}
131
180
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.
133
188
public func expectAsyncThrowsError< T> (
134
189
_ expression: @autoclosure ( ) async throws -> T,
135
190
_ message: @autoclosure ( ) - > Comment? = nil ,
0 commit comments