Skip to content

Commit d0df58a

Browse files
committed
Add EndToEndTests subclassing XCTest
1 parent 2e03529 commit d0df58a

File tree

5 files changed

+68
-11
lines changed

5 files changed

+68
-11
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ jobs:
2525
key: ${{ runner.os }}-spm-xcode-${{ matrix.xcode }}-${{ hashFiles('**/Package.resolved') }}
2626
restore-keys: |
2727
${{ runner.os }}-spm-xcode-${{ matrix.xcode }}-
28-
- name: Build and Test
28+
- name: Install System Dependencies
2929
run: |
3030
brew install graphviz
31-
./test.sh
31+
- name: Build and Test
32+
run: |
33+
swift test -c release
3234
env:
3335
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
3436

@@ -54,6 +56,6 @@ jobs:
5456
- name: Install System Dependencies
5557
run: |
5658
apt-get update
57-
apt-get install -y libxml2-dev
59+
apt-get install -y libxml2-dev graphviz
5860
- name: Build and Test
59-
run: ./test.sh
61+
run: swift test -c release --enable-test-discovery

Package.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,11 @@ let package = Package(
6363
.product(name: "SwiftMarkup", package: "SwiftMarkup")
6464
]
6565
),
66+
.testTarget(
67+
name: "EndToEndTests",
68+
dependencies: [
69+
.target(name: "swift-doc"),
70+
]
71+
),
6672
]
6773
)

[email protected]

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,11 @@ let package = Package(
4141
name: "SwiftDocTests",
4242
dependencies: ["SwiftDoc", "SwiftSyntax", "SwiftSemantics", "SwiftMarkup"]
4343
),
44+
.testTarget(
45+
name: "EndToEndTests",
46+
dependencies: [
47+
.target(name: "swift-doc"),
48+
]
49+
),
4450
]
4551
)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import class Foundation.Bundle
2+
import XCTest
3+
4+
final class EndToEndTests: XCTestCase {
5+
func testCSS() throws {
6+
// Some of the APIs that we use below are available in macOS 10.13 and above.
7+
guard #available(macOS 10.13, *) else {
8+
return
9+
}
10+
11+
let process = Process()
12+
process.executableURL = productsDirectory.appendingPathComponent("swift-doc")
13+
process.arguments = ["generate", "--module-name", "SwiftDoc", "--format", "html", "Sources"]
14+
15+
let pipe = Pipe()
16+
process.standardOutput = pipe
17+
18+
try process.run()
19+
process.waitUntilExit()
20+
21+
let data = pipe.fileHandleForReading.readDataToEndOfFile()
22+
let output = String(data: data, encoding: .utf8)
23+
24+
XCTAssertEqual(output, "")
25+
26+
let cssPath = productsDirectory
27+
.deletingLastPathComponent()
28+
.deletingLastPathComponent()
29+
.appendingPathComponent("documentation")
30+
.appendingPathComponent("all.css")
31+
let cssData = try Data(contentsOf: cssPath)
32+
guard let css = String(data: cssData, encoding: .utf8) else {
33+
return XCTFail("Failed to decode a UTF-8 string from `cssData` in \(#function)")
34+
}
35+
36+
XCTAssertTrue(css.starts(with: ":root"))
37+
}
38+
39+
/// Returns path to the built products directory.
40+
lazy var productsDirectory: URL = {
41+
#if os(macOS)
42+
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
43+
return bundle.bundleURL.deletingLastPathComponent()
44+
}
45+
fatalError("couldn't find the products directory")
46+
#else
47+
return Bundle.main.bundleURL
48+
#endif
49+
}()
50+
}

test.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)