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

[New Output] Support Note Output #311

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions Sources/XcbeautifyLib/CaptureGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1866,3 +1866,24 @@ struct SwiftDriverJobDiscoveryCompilingCaptureGroup: CaptureGroup {
self.project = project
}
}

/// This output is printed when running
/// `xcodebuild test -scheme xcbeautify-Package -destination 'platform=macOS,arch=arm64'`.
struct NoteCaptureGroup: CaptureGroup {
static let outputType: OutputType = .task

/// Regular expression captured groups:
/// $1 = note
/// $2 = information
static let regex = Regex(pattern: "^(note:) (.*)")
Copy link
Owner

Choose a reason for hiding this comment

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

nit: We can change this to `"^note: (.*)$".

No need to capture note, since it's a static keyword.


let note: String
let information: String

init?(groups: [String]) {
assert(groups.count == 2)
guard let note = groups[safe: 0], let information = groups[safe: 1] else { return nil }
self.note = note
self.information = information
}
}
2 changes: 2 additions & 0 deletions Sources/XcbeautifyLib/Formatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ package struct Formatter {
return renderer.formatSwiftDriverJobDiscoveryCompiling(group: group)
case let group as TestingStartedCaptureGroup:
return renderer.formatTestingStarted(group: group)
case let group as NoteCaptureGroup:
return renderer.formatNote(group: group)
default:
assertionFailure()
return nil
Expand Down
1 change: 1 addition & 0 deletions Sources/XcbeautifyLib/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ package final class Parser {
TestSuiteAllTestsPassedCaptureGroup.self,
TestSuiteAllTestsFailedCaptureGroup.self,
TestingStartedCaptureGroup.self,
NoteCaptureGroup.self,
]

// MARK: - Init
Expand Down
5 changes: 5 additions & 0 deletions Sources/XcbeautifyLib/Renderers/OutputRendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ protocol OutputRendering {
func formatSwiftDriverJobDiscoveryEmittingModule(group: SwiftDriverJobDiscoveryEmittingModuleCaptureGroup) -> String?
func formatTestingStarted(group: TestingStartedCaptureGroup) -> String
func formatSwiftDriverJobDiscoveryCompiling(group: SwiftDriverJobDiscoveryCompilingCaptureGroup) -> String?
func formatNote(group: NoteCaptureGroup) -> String
}

extension OutputRendering {
Expand Down Expand Up @@ -565,4 +566,8 @@ extension OutputRendering {
func formatTestingStarted(group: TestingStartedCaptureGroup) -> String {
colored ? group.wholeMessage.s.Bold.f.Cyan : group.wholeMessage
}

func formatNote(group: NoteCaptureGroup) -> String {
colored ? group.note.s.Bold.f.Cyan + " " + group.information : group.note + " " + group.information
}
}
36 changes: 36 additions & 0 deletions Tests/XcbeautifyLibTests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,40 @@ final class ParserTests: XCTestCase {
let input = #"2024-08-18 18:17:52.619 xcodebuild[9799:394817] [MT] IDETestOperationsObserverDebug: 21.975 elapsed -- Testing started completed."#
XCTAssertNil(parser.parse(line: input))
}

func testMatchNote() throws {
let inputs = [
(note: "note:", information: "Building targets in dependency order"),
(note: "Note:", information: "Building targets in dependency order"),
(note: "note:", information: "Metadata extraction skipped. No AppIntents.framework dependency found. (in target 'Target' from project 'Project')"),
(note: "Note:", information: "Metadata extraction skipped. No AppIntents.framework dependency found. (in target 'Target' from project 'Project')"),
(note: "note:", information: #"Run script build phase 'SomeRunScriptBuildPhase' will be run during every build because the option to run the script phase "Based on dependency analysis" is unchecked. (in target 'Target' from project 'Project')"#),
(note: "Note:", information: #"Run script build phase 'SomeRunScriptBuildPhase' will be run during every build because the option to run the script phase "Based on dependency analysis" is unchecked. (in target 'Target' from project 'Project')"#),
(note: "note:", information: "Target dependency graph (12 targets)"),
(note: "Note:", information: "Target dependency graph (12 targets)"),
]

for (note, information) in inputs {
let input = "\(note) \(information)"
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? NoteCaptureGroup)
XCTAssertEqual(captureGroup.note, note)
XCTAssertEqual(captureGroup.information, information)
}
}

func testNotMatchNote() throws {
let inputs = [
"in the note middle",
"in the note: middle",
"note Building targets in dependency order",
"Note Metadata extraction skipped.",
"Target dependency graph (12 targets) note",
"Target dependency graph (12 targets) note:",
"Target dependency graph (12 targets): note:",
]

for input in inputs {
XCTAssertNil(parser.parse(line: input))
}
}
}
4 changes: 2 additions & 2 deletions Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class ParsingTests: XCTestCase {
// Update this magic number whenever `uncapturedOutput` is less than the current magic number.
// There's a regression whenever `uncapturedOutput` is greater than the current magic number.
#if os(macOS)
XCTAssertEqual(uncapturedOutput, 255)
XCTAssertEqual(uncapturedOutput, 250)
#else
XCTAssertEqual(uncapturedOutput, 271)
#endif
Expand Down Expand Up @@ -56,7 +56,7 @@ final class ParsingTests: XCTestCase {
// Update this magic number whenever `uncapturedOutput` is less than the current magic number.
// There's a regression whenever `uncapturedOutput` is greater than the current magic number.
#if os(macOS)
XCTAssertEqual(uncapturedOutput, 8519)
XCTAssertEqual(uncapturedOutput, 8359)
#else
XCTAssertEqual(uncapturedOutput, 9087)
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,4 +607,9 @@ final class GitHubActionsRendererTests: XCTestCase {
let formatted = logFormatted(#"Testing started"#)
XCTAssertEqual(formatted, #"Testing started"#)
}

func testNote() {
let formatted = logFormatted("note: Building targets in dependency order")
XCTAssertEqual(formatted, "note: Building targets in dependency order")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,9 @@ final class TeamCityRendererTests: XCTestCase {
let formatted = noColoredFormatted(#"Testing started"#)
XCTAssertEqual(formatted, #"Testing started"#)
}

func testNote() {
let formatted = noColoredFormatted("note: Building targets in dependency order")
XCTAssertEqual(formatted, "note: Building targets in dependency order")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,9 @@ final class TerminalRendererTests: XCTestCase {
let formatted = noColoredFormatted(#"Testing started"#)
XCTAssertEqual(formatted, #"Testing started"#)
}

func testNote() {
let formatted = noColoredFormatted("note: Building targets in dependency order")
XCTAssertEqual(formatted, "note: Building targets in dependency order")
}
}
Loading