Files
resgen.swift/Tests/ResgenSwiftTests/ResgenSwiftTests.swift
T
t.schmitt 58b049c629
openium/resgen.swift/pipeline/head This commit looks good
Migrate tests from XCTest to Swift Testing (#26)
Reviewed-on: #26
2026-11-23 16:25:37 +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 {}