Skip to content

Commit

Permalink
Merge pull request #190 from muter-mutation-testing/bugfix/zeveisenbe…
Browse files Browse the repository at this point in the history
…rg/185-189-process-termination-code

#185 #189 process termination code
  • Loading branch information
rakaramos authored Nov 5, 2020
2 parents af7c6d8 + 80bb3f4 commit b4e128d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ struct MutationTestingDelegate: MutationTestingIODelegate {
savingResultsIntoFileNamed fileName: String) -> (outcome: TestSuiteOutcome, testLog: String) {
do {
let (testProcessFileHandle, testLogUrl) = try fileHandle(for: fileName)
defer { testProcessFileHandle.closeFile() }

let process = try testProcess(with: configuration, and: testProcessFileHandle)
try process.run()
process.waitUntilExit()
testProcessFileHandle.closeFile()

let contents = try String(contentsOf: testLogUrl)

return (
outcome: TestSuiteOutcome.from(testLog: contents),
outcome: TestSuiteOutcome.from(testLog: contents, terminationStatus: process.terminationStatus),
testLog: contents
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ final class PlainTextReporter: Reporter {
}
}

func mutationTestingFinished(notification: Notification) {
let outcomes = notification.object as! [MutationTestOutcome]
func mutationTestingFinished(mutationTestOutcomes outcomes: [MutationTestOutcome]) {
printMessage(report(from: outcomes))
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/muterCore/TestReporting/TestSuiteOutcome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public enum TestSuiteOutcome: String, Codable {
}

extension TestSuiteOutcome {
public static func from(testLog: String) -> TestSuiteOutcome {
public static func from(testLog: String, terminationStatus: Int32) -> TestSuiteOutcome {

if logContainsRuntimeError(testLog) {
if !terminationStatusIsSuccess(terminationStatus) {
return .runtimeError
} else if logContainsBuildError(testLog) {
return .buildError
Expand Down Expand Up @@ -53,8 +53,8 @@ extension TestSuiteOutcome {
return try! NSRegularExpression(pattern: "with ([1-9]{1}[0-9]{0,}) failure", options: [])
}

static private func logContainsRuntimeError(_ testLog: String) -> Bool {
return testLog.contains("Fatal error")
static private func terminationStatusIsSuccess(_ terminationStatus: Int32) -> Bool {
return terminationStatus == 0
}

static private func logContainsBuildError(_ testLog: String) -> Bool {
Expand Down
33 changes: 19 additions & 14 deletions Tests/TestReporting/testSuiteResultParsingSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,60 @@ class TestSuiteResultParsingSpec: QuickSpec {
context("when a test log doesn't contain a failure, runtime error, or build error") {
it("returns a passed test result") {
var contents = loadLogFile(named: "testRunWithoutFailures_withTestSucceededFooter.log")
expect(TestSuiteOutcome.from(testLog: contents)).to(equal(.passed))
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: 0)).to(equal(.passed))

contents = loadLogFile(named: "testRunWithoutFailures_withTestSucceededFooter_buckOutput.log")
expect(TestSuiteOutcome.from(testLog: contents)).to(equal(.passed))
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: 0)).to(equal(.passed))
}
}

context("when a test log contains a failure") {
it("returns a failed test result") {
var contents = loadLogFile(named: "testRunWithFailures_withoutTestFailedFooter.log")
expect(TestSuiteOutcome.from(testLog: contents)).to(equal(.failed))
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: 0)).to(equal(.failed))

contents = loadLogFile(named: "testRunWithFailures_withTestFailedFooter.log")
expect(TestSuiteOutcome.from(testLog: contents)).to(equal(.failed))
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: 0)).to(equal(.failed))

contents = loadLogFile(named: "testRunWithFailures_withTestFailedFooter_singleTestFailure.log")
expect(TestSuiteOutcome.from(testLog: contents)).to(equal(.failed))
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: 0)).to(equal(.failed))

contents = loadLogFile(named: "testRunWithFailures_withTestFailedFooter_noTestFailureCount.log")
expect(TestSuiteOutcome.from(testLog: contents)).to(equal(.failed))
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: 0)).to(equal(.failed))

contents = loadLogFile(named: "testRunWithFailures_withTestFailedFooter_buckOutput.log")
expect(TestSuiteOutcome.from(testLog: contents)).to(equal(.failed))
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: 0)).to(equal(.failed))
}
}

context("when a test log contains a fatal error") {
it("returns a runtime error") {
it("does not return a runtime error if the termination status was 0") {
let contents = loadLogFile(named: "runtimeError_fatalError.log")
expect(TestSuiteOutcome.from(testLog: contents)).to(equal(.runtimeError))
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: 0)).to(equal(.passed))
}
it("returns a runtime error if the termination status was not 0") {
let contents = loadLogFile(named: "runtimeError_fatalError.log")
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: -127)).to(equal(.runtimeError))
}

}

context("when a test log contains a build error") {
it("returns a build error") {
var contents = loadLogFile(named: "buildError_missingProjectFile.log")
expect(TestSuiteOutcome.from(testLog: contents)).to(equal(.buildError))
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: 0)).to(equal(.buildError))

contents = loadLogFile(named: "buildError_runScriptStepFailed.log")
expect(TestSuiteOutcome.from(testLog: contents)).to(equal(.buildError))
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: 0)).to(equal(.buildError))

contents = loadLogFile(named: "buildError_invalidSwiftCode.log")
expect(TestSuiteOutcome.from(testLog: contents)).to(equal(.buildError))
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: 0)).to(equal(.buildError))

contents = loadLogFile(named: "buildError_withTestFailedFooter.log")
expect(TestSuiteOutcome.from(testLog: contents)).to(equal(.buildError))
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: 0)).to(equal(.buildError))

contents = loadLogFile(named: "buildError_buckOutput.log")
expect(TestSuiteOutcome.from(testLog: contents)).to(equal(.buildError))
expect(TestSuiteOutcome.from(testLog: contents, terminationStatus: 0)).to(equal(.buildError))
}
}
}
Expand Down

0 comments on commit b4e128d

Please sign in to comment.