Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 4c2f16f

Browse files
Lukas-Stuehrkmattt
andauthored
Add end-to-end continuous integration tests for Homebrew distribution (#243)
* Add the possibility to test homebrew's swift-doc in the e2e tests. * Add an GitHub action to make sure we don't break the homebrew version. * Apply suggestions from code review * Rename swiftDocCommand helper Pass swiftDocCommand directly to Process.run Co-authored-by: Mattt <[email protected]>
1 parent c3f476d commit 4c2f16f

File tree

5 files changed

+62
-14
lines changed

5 files changed

+62
-14
lines changed

.github/workflows/homebrew_ci.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Homebrew CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
schedule:
7+
- cron: 0 0 * * *
8+
9+
jobs:
10+
homebrew-bottle:
11+
runs-on: macos-10.15
12+
name: Test Homebrew installation from bottle
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v1
17+
- uses: actions/cache@v2
18+
with:
19+
path: .build
20+
key: ${{ runner.os }}-spm-xcode-${{ matrix.xcode }}-${{ hashFiles('**/Package.resolved') }}
21+
restore-keys: |
22+
${{ runner.os }}-spm-xcode-${{ matrix.xcode }}-
23+
- name: Install swift-doc
24+
run: brew install swiftdocorg/formulae/swift-doc --force-bottle
25+
- name: Run Tests
26+
run: |
27+
swift test --filter EndToEndTests. -Xswiftc -DUSE_HOMEBREW
28+
29+
homebrew-sources:
30+
runs-on: macos-11.0
31+
32+
name: Test Homebrew installation from sources
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v1
36+
- uses: actions/cache@v2
37+
with:
38+
path: .build
39+
key: ${{ runner.os }}-spm-xcode-${{ hashFiles('**/Package.resolved') }}
40+
restore-keys: |
41+
${{ runner.os }}-spm-xcode-
42+
- name: Install swift-doc
43+
run: brew install swiftdocorg/formulae/swift-doc --build-from-source
44+
- name: Run Tests
45+
run: swift test --filter EndToEndTests. -Xswiftc -DUSE_HOMEBREW

Tests/EndToEndTests/CoverageSubcommandTests.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import XCTest
22

33
final class CoverageSubcommandTests: XCTestCase {
44
func testStandardOutput() throws {
5-
let command = Bundle.productsDirectory.appendingPathComponent("swift-doc")
6-
75
let outputDirectory = try temporaryDirectory()
86
defer { try? FileManager.default.removeItem(at: outputDirectory) }
97

10-
try Process.run(command: command,
8+
try Process.run(command: swiftDocCommand,
119
arguments: [
1210
"coverage",
1311
"Sources"
@@ -20,13 +18,11 @@ final class CoverageSubcommandTests: XCTestCase {
2018
}
2119

2220
func testFileOutput() throws {
23-
let command = Bundle.productsDirectory.appendingPathComponent("swift-doc")
24-
2521
let outputDirectory = try temporaryDirectory()
2622
let outputFile = outputDirectory.appendingPathComponent("report.json")
2723
defer { try? FileManager.default.removeItem(at: outputDirectory) }
2824

29-
try Process.run(command: command,
25+
try Process.run(command: swiftDocCommand,
3026
arguments: [
3127
"coverage",
3228
"--output", outputFile.path,

Tests/EndToEndTests/DiagramSubcommandTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import XCTest
22

33
final class DiagramSubcommandTests: XCTestCase {
44
func testStandardOutput() throws {
5-
let command = Bundle.productsDirectory.appendingPathComponent("swift-doc")
6-
75
let outputDirectory = try temporaryDirectory()
86
defer { try? FileManager.default.removeItem(at: outputDirectory) }
97

10-
try Process.run(command: command,
8+
try Process.run(command: swiftDocCommand,
119
arguments: [
1210
"diagram",
1311
"Sources"

Tests/EndToEndTests/GenerateSubcommandTests.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import XCTest
22

33
final class GenerateSubcommandTests: XCTestCase {
44
func testCommonMark() throws {
5-
let command = Bundle.productsDirectory.appendingPathComponent("swift-doc")
6-
75
let outputDirectory = try temporaryDirectory()
86
defer { try? FileManager.default.removeItem(at: outputDirectory) }
97

10-
try Process.run(command: command,
8+
try Process.run(command: swiftDocCommand,
119
arguments: [
1210
"generate",
1311
"--module-name", "SwiftDoc",
@@ -44,11 +42,10 @@ final class GenerateSubcommandTests: XCTestCase {
4442
}
4543

4644
func testHTML() throws {
47-
let command = Bundle.productsDirectory.appendingPathComponent("swift-doc")
4845
let outputDirectory = try temporaryDirectory()
4946

5047
defer { try? FileManager.default.removeItem(at: outputDirectory) }
51-
try Process.run(command: command,
48+
try Process.run(command: swiftDocCommand,
5249
arguments: [
5350
"generate",
5451
"--module-name", "SwiftDoc",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import XCTest
2+
import Foundation
3+
4+
extension XCTestCase {
5+
var swiftDocCommand: URL {
6+
#if USE_HOMEBREW
7+
return URL(fileURLWithPath: "/usr/local/bin/swift-doc")
8+
#else
9+
return Bundle.productsDirectory.appendingPathComponent("swift-doc")
10+
#endif
11+
}
12+
}

0 commit comments

Comments
 (0)