Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error message output #142

Merged
merged 9 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
18 changes: 12 additions & 6 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
- name: Build on macOS 10.15 with Swift 5.2
run: |
sudo xcode-select --switch /Applications/Xcode_11.7.app/Contents/Developer
swift build
swift test -c release
swift build -c release
brew bundle
cd TestApp && ../.build/debug/carton test
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
../.build/debug/carton bundle
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -31,7 +32,8 @@ jobs:
- name: Build on macOS 11.0 with Swift 5.2
run: |
sudo xcode-select --switch /Applications/Xcode_11.7.app/Contents/Developer
swift build
swift test -c release
swift build -c release
brew bundle
cd TestApp && ../.build/debug/carton test
../.build/debug/carton bundle
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -46,7 +48,8 @@ jobs:
- name: Build on macOS 10.15 with Swift 5.3
run: |
sudo xcode-select --switch /Applications/Xcode_12.app/Contents/Developer
swift build
swift test -c release
swift build -c release
brew bundle
cd TestApp && ../.build/debug/carton test
../.build/debug/carton bundle
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -61,7 +64,8 @@ jobs:
- name: Build on macOS 11.0 with Swift 5.3
run: |
sudo xcode-select --switch /Applications/Xcode_12.1.app/Contents/Developer
swift build
swift test -c release
swift build -c release
brew bundle
cd TestApp && ../.build/debug/carton test
../.build/debug/carton bundle
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -76,7 +80,8 @@ jobs:

- name: Build on Ubuntu 18.04 with Swift 5.3
run: |
swift build
swift test -c release
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
swift build -c release
sudo ./install_ubuntu_deps.sh
curl https://get.wasmer.io -sSfL | sh
source /home/runner/.wasmer/wasmer.sh
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -93,7 +98,8 @@ jobs:

- name: Build on Ubuntu 20.04 with Swift 5.3
run: |
swift build
swift test -c release
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
swift build -c release
sudo ./install_ubuntu_deps.sh
curl https://get.wasmer.io -sSfL | sh
source /home/runner/.wasmer/wasmer.sh
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ let package = Package(
),
.testTarget(
name: "CartonTests",
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
dependencies: ["carton"]
dependencies: [
"carton",
"CartonHelpers",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core")
]
),
]
)
10 changes: 6 additions & 4 deletions Sources/CartonHelpers/DiagnosticsParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private struct TerminalOutputFormat: OutputFormat {
/// The compiler output often repeats iteself, and the diagnostics can sometimes be
/// difficult to read.
/// This reformats them to a more readable output.
struct DiagnosticsParser {
public struct DiagnosticsParser {
// swiftlint:disable force_try
enum Regex {
/// The output has moved to a new file
Expand All @@ -105,7 +105,7 @@ struct DiagnosticsParser {
let line: String.SubSequence
let char: String.SubSequence
let code: String
let message: String.SubSequence
let message: String

enum Kind: String {
case error, warning, note
Expand All @@ -120,8 +120,10 @@ struct DiagnosticsParser {
}

fileprivate static let highlighter = SyntaxHighlighter(format: TerminalOutputFormat())

public init() {}

func parse(_ output: String, _ terminal: InteractiveWriter) {
public func parse(_ output: String, _ terminal: InteractiveWriter) {
let lines = output.split(separator: "\n")
var lineIdx = 0

Expand Down Expand Up @@ -157,7 +159,7 @@ struct DiagnosticsParser {
line: components[0],
char: components[1],
code: String(lines[lineIdx]),
message: components[3]
message: components.dropFirst(3).joined(separator: ":")
)
)
}
Expand Down
80 changes: 67 additions & 13 deletions Tests/CartonTests/CartonTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import class Foundation.Bundle
import XCTest
import CartonHelpers
import TSCBasic

final class CartonTests: XCTestCase {
/// Returns path to the built products directory.
var productsDirectory: URL {
#if os(macOS)
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
return bundle.bundleURL.deletingLastPathComponent()
}
fatalError("couldn't find the products directory")
#else
return Bundle.main.bundleURL
#endif
}

MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
func testExample() throws {
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
Expand All @@ -20,28 +34,68 @@ final class CartonTests: XCTestCase {
let pipe = Pipe()
process.standardOutput = pipe

process.arguments = ["--version"]
try process.run()
process.waitUntilExit()

let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)

XCTAssertEqual(output, "Hello, world!\n")
XCTAssertEqual(output?.trimmingCharacters(in: .whitespacesAndNewlines), "0.7.1")
}

/// Returns path to the built products directory.
var productsDirectory: URL {
#if os(macOS)
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
return bundle.bundleURL.deletingLastPathComponent()

final class TestOutputStream: OutputByteStream {
var bytes: [UInt8] = []
var currentOutput: String {
String(bytes: bytes, encoding: .utf8)!
}
fatalError("couldn't find the products directory")
#else
return Bundle.main.bundleURL
#endif
var position: Int = 0

init() {}

func flush() {}

func write(_ byte: UInt8) {
bytes.append(byte)
}

func write<C>(_ bytes: C) where C : Collection, C.Element == UInt8 {
self.bytes.append(contentsOf: bytes)
}
}

func testDiagnosticsParser() {
let testDiagnostics = """
[1/1] Compiling TokamakCore Font.swift
/Users/username/Project/Sources/TokamakCore/Tokens/Font.swift:58:15: error: invalid redeclaration of 'resolve(in:)'
public func resolve(in environment: EnvironmentValues) -> _Font {
^
/Users/username/Project/Sources/TokamakCore/Tokens/Font.swift:55:15: note: 'resolve(in:)' previously declared here
public func resolve(in environment: EnvironmentValues) -> _Font {
^
"""
let expectedOutput = """
\u{001B}[1m\u{001B}[7m Font.swift \u{001B}[0m /Users/username/Project/Sources/TokamakCore/Tokens/Font.swift:58

\u{001B}[41;1m\u{001B}[37;1m ERROR \u{001B}[0m invalid redeclaration of 'resolve(in:)'
\u{001B}[36m58 | \u{001B}[0m \u{001B}[35;1mpublic\u{001B}[0m \u{001B}[35;1mfunc\u{001B}[0m resolve(in environment: \u{001B}[94mEnvironmentValues\u{001B}[0m) -> \u{001B}[94m_Font\u{001B}[0m {
| ^

\u{001B}[7m\u{001B}[37;1m NOTE \u{001B}[0m 'resolve(in:)' previously declared here
\u{001B}[36m55 | \u{001B}[0m \u{001B}[35;1mpublic\u{001B}[0m \u{001B}[35;1mfunc\u{001B}[0m resolve(in environment: \u{001B}[94mEnvironmentValues\u{001B}[0m) -> \u{001B}[94m_Font\u{001B}[0m {
| ^



"""
let stream = TestOutputStream()
let writer = InteractiveWriter(stream: stream)
DiagnosticsParser().parse(testDiagnostics, writer)
XCTAssertEqual(stream.currentOutput, expectedOutput)
}

static var allTests = [
("testExample", testExample),
// ("testExample", testExample),
("testDiagnosticsParser", testDiagnosticsParser),
]
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
}