From b27f71790f98972ef5615ee428eca5a8e879db07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20St=C3=BChrk?= Date: Sun, 4 Apr 2021 23:29:53 +0200 Subject: [PATCH 1/4] Add the possibility to test homebrew's swift-doc in the e2e tests. --- Tests/EndToEndTests/CoverageSubcommandTests.swift | 4 ++-- Tests/EndToEndTests/DiagramSubcommandTests.swift | 2 +- Tests/EndToEndTests/GenerateSubcommandTests.swift | 2 +- .../EndToEndTests/Helpers/XCTestCase+Extensions.swift | 11 +++++++++++ 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 Tests/EndToEndTests/Helpers/XCTestCase+Extensions.swift diff --git a/Tests/EndToEndTests/CoverageSubcommandTests.swift b/Tests/EndToEndTests/CoverageSubcommandTests.swift index 548befa0..7c313cd9 100644 --- a/Tests/EndToEndTests/CoverageSubcommandTests.swift +++ b/Tests/EndToEndTests/CoverageSubcommandTests.swift @@ -2,7 +2,7 @@ import XCTest final class CoverageSubcommandTests: XCTestCase { func testStandardOutput() throws { - let command = Bundle.productsDirectory.appendingPathComponent("swift-doc") + let command = getSwiftDocCommand() let outputDirectory = try temporaryDirectory() defer { try? FileManager.default.removeItem(at: outputDirectory) } @@ -20,7 +20,7 @@ final class CoverageSubcommandTests: XCTestCase { } func testFileOutput() throws { - let command = Bundle.productsDirectory.appendingPathComponent("swift-doc") + let command = getSwiftDocCommand() let outputDirectory = try temporaryDirectory() let outputFile = outputDirectory.appendingPathComponent("report.json") diff --git a/Tests/EndToEndTests/DiagramSubcommandTests.swift b/Tests/EndToEndTests/DiagramSubcommandTests.swift index 60a3ea27..6dde7616 100644 --- a/Tests/EndToEndTests/DiagramSubcommandTests.swift +++ b/Tests/EndToEndTests/DiagramSubcommandTests.swift @@ -2,7 +2,7 @@ import XCTest final class DiagramSubcommandTests: XCTestCase { func testStandardOutput() throws { - let command = Bundle.productsDirectory.appendingPathComponent("swift-doc") + let command = getSwiftDocCommand() let outputDirectory = try temporaryDirectory() defer { try? FileManager.default.removeItem(at: outputDirectory) } diff --git a/Tests/EndToEndTests/GenerateSubcommandTests.swift b/Tests/EndToEndTests/GenerateSubcommandTests.swift index dc2bcde4..f98595c6 100644 --- a/Tests/EndToEndTests/GenerateSubcommandTests.swift +++ b/Tests/EndToEndTests/GenerateSubcommandTests.swift @@ -2,7 +2,7 @@ import XCTest final class GenerateSubcommandTests: XCTestCase { func testCommonMark() throws { - let command = Bundle.productsDirectory.appendingPathComponent("swift-doc") + let command = getSwiftDocCommand() let outputDirectory = try temporaryDirectory() defer { try? FileManager.default.removeItem(at: outputDirectory) } diff --git a/Tests/EndToEndTests/Helpers/XCTestCase+Extensions.swift b/Tests/EndToEndTests/Helpers/XCTestCase+Extensions.swift new file mode 100644 index 00000000..92ff5043 --- /dev/null +++ b/Tests/EndToEndTests/Helpers/XCTestCase+Extensions.swift @@ -0,0 +1,11 @@ +import XCTest + +extension XCTestCase { + func getSwiftDocCommand() -> URL { + #if USE_HOMEBREW + return URL(fileURLWithPath: "/usr/local/bin/swift-doc") + #else + return Bundle.productsDirectory.appendingPathComponent("swift-doc") + #endif + } +} From 8bfd872e2c8682311db85559e2b3853669ddda47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20St=C3=BChrk?= Date: Sun, 4 Apr 2021 23:57:02 +0200 Subject: [PATCH 2/4] Add an GitHub action to make sure we don't break the homebrew version. --- .github/workflows/homebrew_ci.yml | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/homebrew_ci.yml diff --git a/.github/workflows/homebrew_ci.yml b/.github/workflows/homebrew_ci.yml new file mode 100644 index 00000000..0d1a5820 --- /dev/null +++ b/.github/workflows/homebrew_ci.yml @@ -0,0 +1,45 @@ +name: homebrew CI + +on: + push: + branches: [master] + schedule: + - cron: 0 0 * * * + +jobs: + homebrew-bottle: + runs-on: macos-10.15 + name: homebrew from bottle + + steps: + - name: Checkout + uses: actions/checkout@v1 + - uses: actions/cache@v2 + with: + path: .build + key: ${{ runner.os }}-spm-xcode-${{ matrix.xcode }}-${{ hashFiles('**/Package.resolved') }} + restore-keys: | + ${{ runner.os }}-spm-xcode-${{ matrix.xcode }}- + - name: Install swift-doc + run: brew install swiftdocorg/formulae/swift-doc --force-bottle + - name: Run Tests + run: | + swift test --filter EndToEndTests. -Xswiftc -DUSE_HOMEBREW + + homebrew-sources: + runs-on: macos-11.0 + + name: homebrew from source + steps: + - name: Checkout + uses: actions/checkout@v1 + - uses: actions/cache@v2 + with: + path: .build + key: ${{ runner.os }}-spm-xcode-${{ hashFiles('**/Package.resolved') }} + restore-keys: | + ${{ runner.os }}-spm-xcode- + - name: Install swift-doc + run: brew install swiftdocorg/formulae/swift-doc --build-from-source + - name: Run Tests + run: swift test --filter EndToEndTests. -Xswiftc -DUSE_HOMEBREW From 6bd8c78b2b9633dd8022d18716d1cb08010d0e76 Mon Sep 17 00:00:00 2001 From: Mattt Date: Sat, 17 Apr 2021 09:48:52 -0700 Subject: [PATCH 3/4] Apply suggestions from code review --- .github/workflows/homebrew_ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/homebrew_ci.yml b/.github/workflows/homebrew_ci.yml index 0d1a5820..50bcc06d 100644 --- a/.github/workflows/homebrew_ci.yml +++ b/.github/workflows/homebrew_ci.yml @@ -1,4 +1,4 @@ -name: homebrew CI +name: Homebrew CI on: push: @@ -9,7 +9,7 @@ on: jobs: homebrew-bottle: runs-on: macos-10.15 - name: homebrew from bottle + name: Test Homebrew installation from bottle steps: - name: Checkout @@ -29,7 +29,7 @@ jobs: homebrew-sources: runs-on: macos-11.0 - name: homebrew from source + name: Test Homebrew installation from sources steps: - name: Checkout uses: actions/checkout@v1 From 4703a045613f691d460f28ba1ff121d2902622d5 Mon Sep 17 00:00:00 2001 From: Mattt Date: Sat, 17 Apr 2021 11:14:46 -0700 Subject: [PATCH 4/4] Rename swiftDocCommand helper Pass swiftDocCommand directly to Process.run --- Tests/EndToEndTests/CoverageSubcommandTests.swift | 8 ++------ Tests/EndToEndTests/DiagramSubcommandTests.swift | 4 +--- Tests/EndToEndTests/GenerateSubcommandTests.swift | 7 ++----- Tests/EndToEndTests/Helpers/XCTestCase+Extensions.swift | 3 ++- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/Tests/EndToEndTests/CoverageSubcommandTests.swift b/Tests/EndToEndTests/CoverageSubcommandTests.swift index 7c313cd9..c28bb772 100644 --- a/Tests/EndToEndTests/CoverageSubcommandTests.swift +++ b/Tests/EndToEndTests/CoverageSubcommandTests.swift @@ -2,12 +2,10 @@ import XCTest final class CoverageSubcommandTests: XCTestCase { func testStandardOutput() throws { - let command = getSwiftDocCommand() - let outputDirectory = try temporaryDirectory() defer { try? FileManager.default.removeItem(at: outputDirectory) } - try Process.run(command: command, + try Process.run(command: swiftDocCommand, arguments: [ "coverage", "Sources" @@ -20,13 +18,11 @@ final class CoverageSubcommandTests: XCTestCase { } func testFileOutput() throws { - let command = getSwiftDocCommand() - let outputDirectory = try temporaryDirectory() let outputFile = outputDirectory.appendingPathComponent("report.json") defer { try? FileManager.default.removeItem(at: outputDirectory) } - try Process.run(command: command, + try Process.run(command: swiftDocCommand, arguments: [ "coverage", "--output", outputFile.path, diff --git a/Tests/EndToEndTests/DiagramSubcommandTests.swift b/Tests/EndToEndTests/DiagramSubcommandTests.swift index 6dde7616..04feb3cd 100644 --- a/Tests/EndToEndTests/DiagramSubcommandTests.swift +++ b/Tests/EndToEndTests/DiagramSubcommandTests.swift @@ -2,12 +2,10 @@ import XCTest final class DiagramSubcommandTests: XCTestCase { func testStandardOutput() throws { - let command = getSwiftDocCommand() - let outputDirectory = try temporaryDirectory() defer { try? FileManager.default.removeItem(at: outputDirectory) } - try Process.run(command: command, + try Process.run(command: swiftDocCommand, arguments: [ "diagram", "Sources" diff --git a/Tests/EndToEndTests/GenerateSubcommandTests.swift b/Tests/EndToEndTests/GenerateSubcommandTests.swift index f98595c6..8557d5fc 100644 --- a/Tests/EndToEndTests/GenerateSubcommandTests.swift +++ b/Tests/EndToEndTests/GenerateSubcommandTests.swift @@ -2,12 +2,10 @@ import XCTest final class GenerateSubcommandTests: XCTestCase { func testCommonMark() throws { - let command = getSwiftDocCommand() - let outputDirectory = try temporaryDirectory() defer { try? FileManager.default.removeItem(at: outputDirectory) } - try Process.run(command: command, + try Process.run(command: swiftDocCommand, arguments: [ "generate", "--module-name", "SwiftDoc", @@ -44,11 +42,10 @@ final class GenerateSubcommandTests: XCTestCase { } func testHTML() throws { - let command = Bundle.productsDirectory.appendingPathComponent("swift-doc") let outputDirectory = try temporaryDirectory() defer { try? FileManager.default.removeItem(at: outputDirectory) } - try Process.run(command: command, + try Process.run(command: swiftDocCommand, arguments: [ "generate", "--module-name", "SwiftDoc", diff --git a/Tests/EndToEndTests/Helpers/XCTestCase+Extensions.swift b/Tests/EndToEndTests/Helpers/XCTestCase+Extensions.swift index 92ff5043..32ced846 100644 --- a/Tests/EndToEndTests/Helpers/XCTestCase+Extensions.swift +++ b/Tests/EndToEndTests/Helpers/XCTestCase+Extensions.swift @@ -1,7 +1,8 @@ import XCTest +import Foundation extension XCTestCase { - func getSwiftDocCommand() -> URL { + var swiftDocCommand: URL { #if USE_HOMEBREW return URL(fileURLWithPath: "/usr/local/bin/swift-doc") #else