Skip to content

Commit ebbfaa6

Browse files
committed
Add DealerTests test target
1 parent 22e26b7 commit ebbfaa6

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@ let package = Package(
2828
.target(
2929
name: "Dealer",
3030
dependencies: ["DeckOfPlayingCards"]),
31+
.testTarget(
32+
name: "DealerTests",
33+
dependencies: ["Dealer"]),
3134
]
3235
)

Tests/DealerTests/DealerTests.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2021 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import XCTest
12+
import class Foundation.Bundle
13+
14+
final class DealerTests: XCTestCase {
15+
func testExample() throws {
16+
// This is an example of a functional test case.
17+
// Use XCTAssert and related functions to verify your tests produce the correct
18+
// results.
19+
20+
// Some of the APIs that we use below are available in macOS 10.13 and above.
21+
guard #available(macOS 10.13, *) else {
22+
return
23+
}
24+
25+
// Mac Catalyst won't have `Process`, but it is supported for executables.
26+
#if !targetEnvironment(macCatalyst)
27+
28+
let dealerBinary = productsDirectory.appendingPathComponent("Dealer")
29+
30+
let process = Process()
31+
process.executableURL = dealerBinary
32+
33+
let pipe = Pipe()
34+
process.standardOutput = pipe
35+
36+
try process.run()
37+
process.waitUntilExit()
38+
39+
let data = pipe.fileHandleForReading.readDataToEndOfFile()
40+
let output = String(data: data, encoding: .utf8)
41+
42+
XCTAssertNotEqual(output, "")
43+
#endif
44+
}
45+
46+
/// Returns path to the built products directory.
47+
var productsDirectory: URL {
48+
#if os(macOS)
49+
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
50+
return bundle.bundleURL.deletingLastPathComponent()
51+
}
52+
fatalError("couldn't find the products directory")
53+
#else
54+
return Bundle.main.bundleURL
55+
#endif
56+
}
57+
}

0 commit comments

Comments
 (0)