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 ,
16
23
sourceLocation: SourceLocation = #_sourceLocation,
17
24
) {
18
-
19
25
#expect(
20
26
localFileSystem. exists ( path) ,
21
27
" Files ' \( path) ' does not exist. " ,
22
28
sourceLocation: sourceLocation,
23
29
)
24
30
}
25
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.
26
38
public func expectFileDoesNotExists (
27
39
at fixturePath: AbsolutePath,
28
40
_ comment: Comment? = nil ,
@@ -41,6 +53,12 @@ public func expectFileDoesNotExists(
41
53
)
42
54
}
43
55
56
+ /// Verifies that a file exists and is executable at the specified path.
57
+ ///
58
+ /// - Parameters:
59
+ /// - fixturePath: The absolute path to check for executable file existence.
60
+ /// - comment: An optional comment to include in the failure message.
61
+ /// - sourceLocation: The source location where the expectation is made.
44
62
public func expectFileIsExecutable(
45
63
at fixturePath: AbsolutePath,
46
64
_ comment: Comment? = nil ,
@@ -59,6 +77,11 @@ public func expectFileIsExecutable(
59
77
)
60
78
}
61
79
80
+ /// Verifies that a directory exists at the specified path.
81
+ ///
82
+ /// - Parameters:
83
+ /// - path: The absolute path to check for directory existence.
84
+ /// - sourceLocation: The source location where the expectation is made.
62
85
public func expectDirectoryExists (
63
86
at path: AbsolutePath,
64
87
sourceLocation: SourceLocation = #_sourceLocation,
@@ -70,6 +93,11 @@ public func expectDirectoryExists(
70
93
)
71
94
}
72
95
96
+ /// Verifies that a directory does not exist at the specified path.
97
+ ///
98
+ /// - Parameters:
99
+ /// - path: The absolute path to check for directory non-existence.
100
+ /// - sourceLocation: The source location where the expectation is made.
73
101
public func expectDirectoryDoesNotExist (
74
102
at path: AbsolutePath,
75
103
sourceLocation: SourceLocation = #_sourceLocation,
@@ -81,6 +109,15 @@ public func expectDirectoryDoesNotExist(
81
109
)
82
110
}
83
111
112
+ // MARK: Error Helpers
113
+
114
+ /// Verifies that an expression throws a `CommandExecutionError`.
115
+ ///
116
+ /// - Parameters:
117
+ /// - expression: The expression to evaluate.
118
+ /// - message: An optional description of the failure.
119
+ /// - sourceLocation: The source location where the expectation is made.
120
+ /// - errorHandler: A closure that's called with the error if the expression throws.
84
121
public func expectThrowsCommandExecutionError< T> (
85
122
_ expression: @autoclosure ( ) async throws -> T,
86
123
_ message: @autoclosure ( ) - > Comment = " " ,
@@ -99,7 +136,13 @@ public func expectThrowsCommandExecutionError<T>(
99
136
}
100
137
}
101
138
102
- /// An `async`-friendly replacement for `XCTAssertThrowsError`.
139
+ /// An async-friendly replacement for `XCTAssertThrowsError` that verifies an expression throws an error.
140
+ ///
141
+ /// - Parameters:
142
+ /// - expression: The expression to evaluate that should throw an error.
143
+ /// - message: An optional failure message to display if the expression doesn't throw.
144
+ /// - sourceLocation: The source location where the expectation is made.
145
+ /// - errorHandler: A closure that's called with the error if the expression throws.
103
146
public func expectAsyncThrowsError< T> (
104
147
_ expression: @autoclosure ( ) async throws -> T,
105
148
_ message: @autoclosure ( ) - > Comment? = nil ,
0 commit comments