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

Pretty print carton test output #144

Merged
merged 14 commits into from
Oct 28, 2020
Merged

Pretty print carton test output #144

merged 14 commits into from
Oct 28, 2020

Conversation

carson-katri
Copy link
Member

@carson-katri carson-katri commented Oct 26, 2020

Generalized the ProcessRunner to take a ProcessOutputParser (currently only DiagnosticsParser and TestsParser conform).

Here's a sample of passing & failing test cases:

Screen Shot 2020-10-26 at 5 51 19 PM

Screen Shot 2020-10-26 at 6 01 31 PM

And here's what the raw output of swift test would be:

Test Suite 'All tests' started at 2020-10-26 21:33:57.453
Test Suite 'testBundle.xctest' started at 2020-10-26 21:33:57.453
Test Suite 'Test' started at 2020-10-26 21:33:57.454
Test Case 'Test.testTrivial' started at 2020-10-26 21:33:57.460
/Users/carson/.carton/carton/TestApp/Tests/Tests/Test.swift:21: error: Test.testTrivial : XCTAssertEqual failed: ("Hello, world") is not equal to ("Hello world") - 
/Users/carson/.carton/carton/TestApp/Tests/Tests/Test.swift:22: error: Test.testTrivial : XCTAssertGreaterThan failed: ("5") is not greater than ("5") - 
/Users/carson/.carton/carton/TestApp/Tests/Tests/Test.swift:23: error: Test.testTrivial : XCTAssertLessThan failed: ("5") is not less than ("4") - 
/Users/carson/.carton/carton/TestApp/Tests/Tests/Test.swift:24: error: Test.testTrivial : XCTAssertLessThanOrEqual failed: ("5") is greater than ("4") - 
/Users/carson/.carton/carton/TestApp/Tests/Tests/Test.swift:25: error: Test.testTrivial : XCTAssertGreaterThanOrEqual failed: ("5") is less than ("6") - 
Test Case 'Test.testTrivial' failed (0.001 seconds)
Test Suite 'Test' failed at 2020-10-26 21:33:57.461
	 Executed 2 tests, with 6 failures (1 unexpected) in 0.007 (0.007) seconds
Test Suite 'testBundle.xctest' failed at 2020-10-26 21:33:57.461
	 Executed 2 tests, with 6 failures (1 unexpected) in 0.007 (0.007) seconds
Test Suite 'All tests' failed at 2020-10-26 21:33:57.461
	 Executed 2 tests, with 6 failures (1 unexpected) in 0.007 (0.007) seconds

@carson-katri carson-katri added the enhancement New feature or request label Oct 26, 2020
MaxDesiatov added a commit that referenced this pull request Oct 27, 2020
For some reason GHA Big Sur hosts no longer have Xcode 12.1 installed as evidenced by CI failures in #141 and #144. We can use Xcode 12.2 instead.
MaxDesiatov
MaxDesiatov previously approved these changes Oct 27, 2020
Copy link
Collaborator

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is marvelous! 👏 I myself lost all hope for parsing XCTest output long time ago, and that's the reason I hacked an XCTest JSON output formatter in our development snapshots (but it didn't land in our 5.3 due to lack of time). This amazing work means I can revert the JSON output formatter, as it had almost no chances to land upstream in its current form. Even though XCTest JSON output is more elegant in theory.

Maybe this output parser could become a separate library at some point? But I'm surely fine with merging it now here and battle-testing for a bit to make sure we can publish it later as a separate library for other people to rely on.

@MaxDesiatov MaxDesiatov requested a review from a team October 27, 2020 10:47
public protocol ProcessOutputParser {
/// Parse the output of a `Process`, format it, then output in the `InteractiveWriter`.
func parse(_ output: String, _ terminal: InteractiveWriter)
var onlyOnFail: Bool { get }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a doc comment for this property.

@MaxDesiatov MaxDesiatov requested a review from a team October 27, 2020 10:49
@carson-katri
Copy link
Member Author

Yeah it'd be nice to separate these from carton. Hopefully we can get Json output in the future (and for compiler output too 🤞)

@MaxDesiatov
Copy link
Collaborator

MaxDesiatov commented Oct 27, 2020

The compiler can already output parseable diagnostics, I'm not sure about JSON, but bitstream output is available for sure, and now can be parsed in pure Swift thanks to swiftlang/swift-tools-support-core#120 and swiftlang/swift-tools-support-core#145.

@carson-katri
Copy link
Member Author

Oh, awesome!

@carson-katri
Copy link
Member Author

I tried to implement the DiagnosticsParser with TSCUtility.SerializedDiagnostics, but it seems to fall apart if there are fixits... I kept getting the error unexpectedSubblock.

@MaxDesiatov MaxDesiatov changed the title Pretty print tests Pretty print carton test output Oct 27, 2020
Copy link
Collaborator

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@MaxDesiatov
Copy link
Collaborator

Seems like TSC support for diagnostics in the bitcode format is unfinished 😕

@carson-katri carson-katri requested a review from a team October 27, 2020 17:37
@carson-katri carson-katri merged commit 1e286b4 into main Oct 28, 2020
@carson-katri carson-katri deleted the pretty-print-tests branch October 28, 2020 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants