Files
resgen.swift/Tests/ResgenSwiftTests/ResgenSwiftTests.swift
T
t.schmitt ac5d9cef58
openium/resgen.swift/pipeline/head There was a failure building this commit
openium/resgen.swift/pipeline/pr-master There was a failure building this commit
Migrate tests from XCTest to Swift Testing
- Convert XCTestCase classes to structs with @Test functions
- Replace XCTAssert* with #expect, and force unwraps/XCTFail with #require
- Resolve test bundle via a class token in the CLI smoke test (Swift Testing
  does not register the .xctest bundle in Bundle.allBundles)
- Rename adaptForXCTest() to adaptForTest()
2026-11-23 15:53:21 +01:00

42 lines
1.2 KiB
Swift

import Foundation
import Testing
@testable import ResgenSwift
struct ResgenCLITests {
/// Smoke test: the built executable launches and exits.
@Test
func executableRuns() throws {
// Process available on Mac only
#if os(macOS)
let process = Process()
process.executableURL = try productsDirectory().appendingPathComponent("ResgenSwift")
let pipe = Pipe()
process.standardOutput = pipe
try process.run()
process.waitUntilExit()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
#expect(String(data: data, encoding: .utf8) != nil)
#endif
}
/// Returns path to the built products directory.
private func productsDirectory() throws -> URL {
#if os(macOS)
// Swift Testing does not register the test bundle in `Bundle.allBundles`,
// so resolve it from a class compiled into this test target.
let bundle = Bundle(for: BundleToken.self)
try #require(bundle.bundlePath.hasSuffix(".xctest"))
return bundle.bundleURL.deletingLastPathComponent()
#else
return Bundle.main.bundleURL
#endif
}
}
private final class BundleToken {}