1111import Basics
1212import 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.
1421public func expectFileExists(
1522 at path: AbsolutePath ,
1623 sourceLocation: SourceLocation = #_sourceLocation,
1724) {
18-
1925 #expect(
2026 localFileSystem. exists ( path) ,
2127 " Files ' \( path) ' does not exist. " ,
2228 sourceLocation: sourceLocation,
2329 )
2430}
2531
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.
2638public func expectFileDoesNotExists (
2739 at fixturePath: AbsolutePath,
2840 _ comment: Comment? = nil ,
@@ -41,6 +53,12 @@ public func expectFileDoesNotExists(
4153 )
4254}
4355
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.
4462public func expectFileIsExecutable(
4563 at fixturePath: AbsolutePath,
4664 _ comment: Comment? = nil ,
@@ -59,6 +77,11 @@ public func expectFileIsExecutable(
5977 )
6078}
6179
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.
6285public func expectDirectoryExists (
6386 at path: AbsolutePath,
6487 sourceLocation: SourceLocation = #_sourceLocation,
@@ -70,6 +93,11 @@ public func expectDirectoryExists(
7093 )
7194}
7295
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.
73101public func expectDirectoryDoesNotExist (
74102 at path: AbsolutePath,
75103 sourceLocation: SourceLocation = #_sourceLocation,
@@ -81,6 +109,15 @@ public func expectDirectoryDoesNotExist(
81109 )
82110}
83111
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.
84121public func expectThrowsCommandExecutionError< T> (
85122 _ expression: @autoclosure ( ) async throws -> T,
86123 _ message: @autoclosure ( ) - > Comment = " " ,
@@ -99,7 +136,13 @@ public func expectThrowsCommandExecutionError<T>(
99136 }
100137}
101138
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.
103146public func expectAsyncThrowsError< T> (
104147 _ expression: @autoclosure ( ) async throws -> T,
105148 _ message: @autoclosure ( ) - > Comment? = nil ,
0 commit comments