Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix build status string sanitizing
Browse files Browse the repository at this point in the history
Signed-off-by: Ronan Nunes <ronan.nunes@picpay.com>
ronanrodrigo committed Nov 29, 2021
1 parent 946d722 commit 6f36e0b
Showing 4 changed files with 113 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/XCLogParser/commands/Version.swift
Original file line number Diff line number Diff line change
@@ -21,6 +21,6 @@ import Foundation

public struct Version {

public static let current = "0.2.31"
public static let current = "0.2.32"

}
30 changes: 30 additions & 0 deletions Sources/XCLogParser/parser/BuildStatusSanitizer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2019 Spotify AB.
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import Foundation

class BuildStatusSanitizer {
static func sanitize(originalStatus: String) -> String {
let sanitizedStatus = originalStatus
.replacingOccurrences(of: "Build", with: "")
.replacingOccurrences(of: "Clean", with: "")
.trimmingCharacters(in: .whitespacesAndNewlines)
return sanitizedStatus
}
}
2 changes: 1 addition & 1 deletion Sources/XCLogParser/parser/ParserBuildSteps.swift
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ public final class ParserBuildSteps {
/// - returns: A `BuildStep` with the parsed content from the log.
public func parse(activityLog: IDEActivityLog) throws -> BuildStep {
self.buildIdentifier = "\(machineName)_\(activityLog.mainSection.uniqueIdentifier)"
buildStatus = activityLog.mainSection.localizedResultString.replacingOccurrences(of: "Build ", with: "")
buildStatus = BuildStatusSanitizer.sanitize(originalStatus: activityLog.mainSection.localizedResultString)
let mainSectionWithTargets = activityLog.mainSection.groupedByTarget()
var mainBuildStep = try parseLogSection(logSection: mainSectionWithTargets, type: .main, parentSection: nil)
mainBuildStep.errorCount = totalErrors
81 changes: 81 additions & 0 deletions Tests/XCLogParserTests/BuildStatusSanitizerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import XCTest
@testable import XCLogParser

final class BuildStatusSanitizerTests: XCTestCase {
private let sut = BuildStatusSanitizer.self
private let succeededStatus = "succeeded"
private let failedStatus = "failed"
private let stoppedStatus = "stopped"

func testSanitizeWhenStringIsOnlySucceededThenReturnSucceeded() {
let sanitizedStatus = sut.sanitize(originalStatus: succeededStatus)

XCTAssertEqual(sanitizedStatus, succeededStatus)
}

func testSanitizeWhenStringIsOnlyFailedThenReturnFailed() {
let sanitizedStatus = sut.sanitize(originalStatus: failedStatus)

XCTAssertEqual(sanitizedStatus, failedStatus)
}

func testSanitizeWhenStringIsOnlyStoppedThenReturnStopped() {
let sanitizedStatus = sut.sanitize(originalStatus: stoppedStatus)

XCTAssertEqual(sanitizedStatus, stoppedStatus)
}

func testSanitizeWhenStringIsSucceededAndContainsCleanThenReturnSucceeded() {
let sanitizedStatus = sut.sanitize(originalStatus: "Clean " + succeededStatus)

XCTAssertEqual(sanitizedStatus, succeededStatus)
}

func testSanitizeWhenStringIsFailedAndContainsCleanThenReturnFailed() {
let sanitizedStatus = sut.sanitize(originalStatus: "Clean " + failedStatus)

XCTAssertEqual(sanitizedStatus, failedStatus)
}

func testSanitizeWhenStringIsStoppedAndContainsCleanThenReturnStopped() {
let sanitizedStatus = sut.sanitize(originalStatus: "Clean " + stoppedStatus)

XCTAssertEqual(sanitizedStatus, stoppedStatus)
}

func testSanitizeWhenStringIsSucceededAndContainsBuildThenReturnSucceeded() {
let sanitizedStatus = sut.sanitize(originalStatus: "Build " + succeededStatus)

XCTAssertEqual(sanitizedStatus, succeededStatus)
}

func testSanitizeWhenStringIsFailedAndContainsBuildThenReturnFailed() {
let sanitizedStatus = sut.sanitize(originalStatus: "Build " + failedStatus)

XCTAssertEqual(sanitizedStatus, failedStatus)
}

func testSanitizeWhenStringIsStoppedAndContainsBuildThenReturnStopped() {
let sanitizedStatus = sut.sanitize(originalStatus: "Build " + stoppedStatus)

XCTAssertEqual(sanitizedStatus, stoppedStatus)
}

func testSanitizeWhenStringIsSucceededAndContainsSurroundingSpacesThenReturnSucceededTrimmed() {
let sanitizedStatus = sut.sanitize(originalStatus: " " + succeededStatus + " ")

XCTAssertEqual(sanitizedStatus, succeededStatus)
}

func testSanitizeWhenStringIsFailedAndContainsSurroundingSpacesThenReturnFailedTrimmed() {
let sanitizedStatus = sut.sanitize(originalStatus: " " + failedStatus + " ")

XCTAssertEqual(sanitizedStatus, failedStatus)
}

func testSanitizeWhenStringIsStoppedAndContainsSurroundingSpacesThenReturnStoppedTrimmed() {
let sanitizedStatus = sut.sanitize(originalStatus: " " + stoppedStatus + " ")

XCTAssertEqual(sanitizedStatus, stoppedStatus)
}
}

0 comments on commit 6f36e0b

Please sign in to comment.