Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

Update for Swift 5.3 and macOS Big Sur #13

Merged
merged 7 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 66 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,86 @@ on:
branches: [main]

jobs:
macos:
runs-on: macos-10.15
macos_big_sur:
runs-on: macos-11.0

strategy:
matrix:
xcode:
- "12.2" # Swift 5.3

name: "macOS Big Sur (Xcode ${{ matrix.xcode }})"

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: Build and Test
run: swift test
run: |
swift test
env:
DEVELOPER_DIR: /Applications/Xcode_12.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
- name: Install and Run
run: |
make install
swift-highlight 'print("Hello, world!")'

linux:
runs-on: ubuntu-latest
macos_catalina:
runs-on: macos-10.15

container:
image: swift:5.3
strategy:
matrix:
xcode:
- "12" # Swift 5.3

name: "macOS Catalina (Xcode ${{ matrix.xcode }})"

steps:
- name: Checkout
uses: actions/checkout@v1
- uses: actions/cache@v2
with:
path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
key: ${{ runner.os }}-spm-xcode-${{ matrix.xcode }}-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
${{ runner.os }}-spm-xcode-${{ matrix.xcode }}-
- name: Build and Test
run: |
swift test
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
- name: Install and Run
run: |
make install
swift-highlight 'print("Hello, world!")'
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer

linux:
runs-on: ubuntu-latest

strategy:
matrix:
swift:
- "5.3"

name: "Ubuntu Linux (Swift ${{ matrix.swift }})"

container:
image: swift:${{ matrix.swift }}

steps:
- name: Checkout
uses: actions/checkout@v1
- name: Build and Test
run: swift test
run: |
swift test --enable-test-discovery
- name: Install and Run
run: |
make install
swift-highlight 'print("Hello, world!")'
19 changes: 5 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,20 @@ SOURCES = $(wildcard $(srcdir)/**/*.swift)

.DEFAULT_GOAL = all

.PHONY: all
all: swift-syntax-highlight

swift-syntax-highlight: $(SOURCES)
swift-highlight: $(SOURCES)
@swift build \
-c release \
--disable-sandbox \
--build-path "$(BUILDDIR)"

.PHONY: install
install: swift-syntax-highlight
@install -d "$(bindir)" "$(libdir)"
@install "$(BUILDDIR)/release/swift-syntax-highlight" "$(bindir)"
@install "$(BUILDDIR)/release/libSwiftSyntax.dylib" "$(libdir)"
@install_name_tool -change \
"$(BUILDDIR)/x86_64-apple-macosx10.10/release/libSwiftSyntax.dylib" \
"$(libdir)/libSwiftSyntax.dylib" \
"$(bindir)/swift-syntax-highlight"
install: swift-highlight
@install -d "$(bindir)"
@install "$(wildcard $(BUILDDIR)/**/release/swift-highlight)" "$(bindir)"

.PHONY: uninstall
uninstall:
@rm -rf "$(bindir)/swift-syntax-highlight"
@rm -rf "$(libdir)/libSwiftSyntax.dylib"
@rm -rf "$(bindir)/swift-highlight"

.PHONY: clean
distclean:
Expand Down
3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import PackageDescription

let package = Package(
name: "SwiftSyntaxHighlighter",
platforms: [
.macOS(.v10_13)
],
products: [
.library(
name: "SwiftSyntaxHighlighter",
Expand Down
9 changes: 1 addition & 8 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
import XCTest

import SwiftSyntaxHighlighterTests

var tests = [XCTestCaseEntry]()
tests += SwiftSyntaxHighlighterTests.__allTests()

XCTMain(tests)
fatalError("Use `swift test --enable-test-discovery` to run tests")
28 changes: 12 additions & 16 deletions Tests/SwiftSyntaxHighlighterTests/CommandTests.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import XCTest
import class Foundation.Bundle

fileprivate let source = #"""
let greeting = "Hello, world!"
"""#
#if os(macOS)
final class CommandTests: XCTestCase {
let source = #"""
let greeting = "Hello, world!"
"""#

fileprivate let expectedOutput = #"""
<pre class="highlight"><code><span class="keyword">let</span> <span class="variable">greeting</span> = <span class="string literal">&quot;</span><span class="string literal">Hello, world!</span><span class="string literal">&quot;</span></code></pre>
"""#
let expectedOutput = #"""
<pre class="highlight"><code><span class="keyword">let</span> <span class="variable">greeting</span> = <span class="string literal">&quot;</span><span class="string literal">Hello, world!</span><span class="string literal">&quot;</span></code></pre>
"""#

fileprivate let expectedPygmentsOutput = #"""
<pre class="highlight"><code><span class="kd">let</span><span class="w"> </span><span class="n">greeting</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">&quot;</span><span class="s2">Hello, world!</span><span class="p">&quot;</span></code></pre>
"""#
let expectedPygmentsOutput = #"""
<pre class="highlight"><code><span class="kd">let</span><span class="w"> </span><span class="n">greeting</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">&quot;</span><span class="s2">Hello, world!</span><span class="p">&quot;</span></code></pre>
"""#

final class CommandTests: XCTestCase {
func testHighlightArguments() throws {
guard #available(macOS 10.13, *) else { return }

do {
let output = try runCommand(arguments: source, "--scheme", "xcode")
XCTAssertEqual(output, expectedOutput)
Expand All @@ -39,8 +38,6 @@ final class CommandTests: XCTestCase {
}

func testHighlightStandardInput() throws {
guard #available(macOS 10.13, *) else { return }

do {
let output = try runCommand(standardInput: source)
XCTAssertEqual(output, expectedOutput)
Expand All @@ -57,7 +54,6 @@ final class CommandTests: XCTestCase {
}
}

@available(macOS 10.13, *)
private func runCommand(arguments: String..., standardInput: String = "") throws -> String? {
let process = Process()
process.executableURL = executable
Expand Down Expand Up @@ -91,7 +87,6 @@ final class CommandTests: XCTestCase {
return productsDirectory.appendingPathComponent("swift-highlight")
}

/// Returns path to the built products directory.
private var productsDirectory: URL {
#if os(macOS)
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
Expand All @@ -103,3 +98,4 @@ final class CommandTests: XCTestCase {
#endif
}
}
#endif
28 changes: 0 additions & 28 deletions Tests/SwiftSyntaxHighlighterTests/XCTestManifests.swift

This file was deleted.