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 build status string sanitizing #153

Merged
merged 1 commit into from
Nov 30, 2021
Merged
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
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)
}
}