StringsConvertorTests.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import XCTest
  2. import class Foundation.Bundle
  3. final class StringsConvertorTests: XCTestCase {
  4. func testExample() throws {
  5. // This is an example of a functional test case.
  6. // Use XCTAssert and related functions to verify your tests produce the correct
  7. // results.
  8. // Some of the APIs that we use below are available in macOS 10.13 and above.
  9. guard #available(macOS 10.13, *) else {
  10. return
  11. }
  12. let fooBinary = productsDirectory.appendingPathComponent("StringsConvertor")
  13. let process = Process()
  14. process.executableURL = fooBinary
  15. let pipe = Pipe()
  16. process.standardOutput = pipe
  17. try process.run()
  18. process.waitUntilExit()
  19. let data = pipe.fileHandleForReading.readDataToEndOfFile()
  20. let output = String(data: data, encoding: .utf8)
  21. XCTAssertEqual(output, "Hello, world!\n")
  22. }
  23. /// Returns path to the built products directory.
  24. var productsDirectory: URL {
  25. #if os(macOS)
  26. for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
  27. return bundle.bundleURL.deletingLastPathComponent()
  28. }
  29. fatalError("couldn't find the products directory")
  30. #else
  31. return Bundle.main.bundleURL
  32. #endif
  33. }
  34. static var allTests = [
  35. ("testExample", testExample),
  36. ]
  37. }