42 lines
1.2 KiB
Swift
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 {}
|