testing: Update CliTest Support.

And add tests for Cli preprocessing.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-05-21 22:40:58 -04:00
parent b3ca30541a
commit d60465e669
6 changed files with 58 additions and 17 deletions
+16 -3
View File
@@ -16,8 +16,12 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import Foundation
import SystemPackage
import Testing
private let TestGoldenPath: FilePath.Component = FilePath.Component("TestData")
private let TestGoldenExtension: String = ".golden"
typealias Accessor =
@convention(c) (
_ outValue: UnsafeMutableRawPointer,
@@ -68,7 +72,6 @@ func swiftRun(withArgs args: [String]) throws -> String? {
let path = swiftPath()!
let child = Process()
let so = Pipe()
let se = Pipe()
child.standardOutput = so
child.executableURL = path
@@ -90,7 +93,7 @@ func swiftRun(withArgs args: [String]) throws -> String? {
return output
}
func swiftCliTestRunner(_ arg_gen: () -> [String], _ expected: String) async throws {
func swiftCliTestRunner(_ arg_gen: () -> [String], withExpected expected: String) async throws {
let args = arg_gen()
let run_output = try! swiftRun(withArgs: args)
@@ -98,7 +101,17 @@ func swiftCliTestRunner(_ arg_gen: () -> [String], _ expected: String) async thr
#expect(run_output == expected)
}
func swiftCliTestRunner(_ arg_gen: () -> [String], withExpectedPath expected_path: String) async throws {
let args = arg_gen()
let run_output = try! swiftRun(withArgs: args)
let expected_source_absolute = FilePath(FileManager().currentDirectoryPath).appending(TestGoldenPath).appending(expected_path + TestGoldenExtension)
let expected_output = try! String(contentsOfFile: expected_source_absolute.string)
#expect(run_output == expected_output)
}
@attached(peer) public macro CliTest() =
#externalMacro(module: "Macros", type: "CliTestDeclarationMacro")
#externalMacro(module: "Macros", type: "CliTestDeclarationMacro")