From 445fa02406347e0fc1fb3c8dd778cb706ab4fda8 Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Tue, 15 Feb 2022 21:42:58 +0100 Subject: Iniitial commit - v1.0.0 --- Tests/gameTests/gameTests.swift | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Tests/gameTests/gameTests.swift (limited to 'Tests/gameTests') diff --git a/Tests/gameTests/gameTests.swift b/Tests/gameTests/gameTests.swift new file mode 100644 index 0000000..b8efa51 --- /dev/null +++ b/Tests/gameTests/gameTests.swift @@ -0,0 +1,47 @@ +import XCTest +import class Foundation.Bundle + +final class gameTests: XCTestCase { + 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 + } + + // Mac Catalyst won't have `Process`, but it is supported for executables. + #if !targetEnvironment(macCatalyst) + + let fooBinary = productsDirectory.appendingPathComponent("game") + + 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, "Hello, world!\n") + #endif + } + + /// 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 + } +} -- cgit v1.3.1