From 37cb1261269368e4f3e5c852db9d8c90806f4903 Mon Sep 17 00:00:00 2001 From: Alexander Ikonomou Date: Wed, 21 Aug 2024 01:14:03 +0200 Subject: [PATCH] Add support for the note output and tests for the parser and the renderers. Additionally, I had to decrease the magic numbers in ParsingTests.swift. --- Sources/XcbeautifyLib/CaptureGroups.swift | 21 +++++++++++ Sources/XcbeautifyLib/Formatter.swift | 2 ++ Sources/XcbeautifyLib/Parser.swift | 1 + .../Renderers/OutputRendering.swift | 5 +++ Tests/XcbeautifyLibTests/ParserTests.swift | 36 +++++++++++++++++++ .../ParsingTests/ParsingTests.swift | 4 +-- .../GitHubActionsRendererTests.swift | 5 +++ .../RendererTests/TeamCityRendererTests.swift | 5 +++ .../RendererTests/TerminalRendererTests.swift | 5 +++ 9 files changed, 82 insertions(+), 2 deletions(-) diff --git a/Sources/XcbeautifyLib/CaptureGroups.swift b/Sources/XcbeautifyLib/CaptureGroups.swift index d97bbcc4..7114bbfa 100644 --- a/Sources/XcbeautifyLib/CaptureGroups.swift +++ b/Sources/XcbeautifyLib/CaptureGroups.swift @@ -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:) (.*)") + + 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 + } +} diff --git a/Sources/XcbeautifyLib/Formatter.swift b/Sources/XcbeautifyLib/Formatter.swift index 2ee1a431..e6c8f2df 100644 --- a/Sources/XcbeautifyLib/Formatter.swift +++ b/Sources/XcbeautifyLib/Formatter.swift @@ -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 diff --git a/Sources/XcbeautifyLib/Parser.swift b/Sources/XcbeautifyLib/Parser.swift index d108b54a..6931353e 100644 --- a/Sources/XcbeautifyLib/Parser.swift +++ b/Sources/XcbeautifyLib/Parser.swift @@ -97,6 +97,7 @@ package final class Parser { TestSuiteAllTestsPassedCaptureGroup.self, TestSuiteAllTestsFailedCaptureGroup.self, TestingStartedCaptureGroup.self, + NoteCaptureGroup.self, ] // MARK: - Init diff --git a/Sources/XcbeautifyLib/Renderers/OutputRendering.swift b/Sources/XcbeautifyLib/Renderers/OutputRendering.swift index 70ea8a88..1a3ba45a 100644 --- a/Sources/XcbeautifyLib/Renderers/OutputRendering.swift +++ b/Sources/XcbeautifyLib/Renderers/OutputRendering.swift @@ -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 { @@ -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 + } } diff --git a/Tests/XcbeautifyLibTests/ParserTests.swift b/Tests/XcbeautifyLibTests/ParserTests.swift index d66fee72..a26397d6 100644 --- a/Tests/XcbeautifyLibTests/ParserTests.swift +++ b/Tests/XcbeautifyLibTests/ParserTests.swift @@ -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)) + } + } } diff --git a/Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift b/Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift index a51aea1d..9df50f1d 100644 --- a/Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift +++ b/Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift @@ -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 @@ -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 diff --git a/Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift b/Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift index 07829c88..f946f5d8 100644 --- a/Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift +++ b/Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift @@ -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") + } } diff --git a/Tests/XcbeautifyLibTests/RendererTests/TeamCityRendererTests.swift b/Tests/XcbeautifyLibTests/RendererTests/TeamCityRendererTests.swift index 028dbe14..1a98599b 100644 --- a/Tests/XcbeautifyLibTests/RendererTests/TeamCityRendererTests.swift +++ b/Tests/XcbeautifyLibTests/RendererTests/TeamCityRendererTests.swift @@ -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") + } } diff --git a/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift b/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift index 914d70d9..7c28602a 100644 --- a/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift +++ b/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift @@ -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") + } }