Created
September 8, 2018 21:49
-
-
Save SeanROlszewski/747678fc6a1bd9ac36e7960f696e73ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testExample() throws { | |
// This is an example of a functional test case. | |
// Use XCTAssert and related functions to verify your tests produce the correct | |
// results. | |
// Some of the APIs that we use below are available in macOS 10.13 and above. | |
guard #available(macOS 10.13, *) else { | |
return | |
} | |
let fooBinary = productsDirectory.appendingPathComponent("muter") | |
let process = Process() | |
process.executableURL = fooBinary | |
let pipe = Pipe() | |
process.standardOutput = pipe | |
try process.run() | |
process.waitUntilExit() | |
let data = pipe.fileHandleForReading.readDataToEndOfFile() | |
let output = String(data: data, encoding: .utf8) | |
XCTAssertEqual(output, "example\n") | |
} | |
/// Returns path to the built products directory. | |
var productsDirectory: URL { | |
#if os(macOS) | |
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") { | |
return bundle.bundleURL.deletingLastPathComponent() | |
} | |
fatalError("couldn't find the products directory") | |
#else | |
return Bundle.main.bundleURL | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this assumes a project is using the swift package manager's layout of files