From debad3b6078e60326b627c4d0f39d1eeb15236e1 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Tue, 29 Mar 2016 09:39:35 +0200 Subject: [PATCH] fixed #253, now when result is either Warnings or AnalyzerWarnings, both counts get included in the summary message. --- BuildaKit/SummaryBuilder.swift | 27 +++++++++++++++---- .../GitHubSummaryBuilderTests.swift | 16 +++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/BuildaKit/SummaryBuilder.swift b/BuildaKit/SummaryBuilder.swift index a65051f..1fb018c 100644 --- a/BuildaKit/SummaryBuilder.swift +++ b/BuildaKit/SummaryBuilder.swift @@ -32,12 +32,21 @@ class SummaryBuilder { let status = self.createStatus(.Success, description: "Build passed!", targetUrl: linkToIntegration) let buildResultSummary = integration.buildResultSummary! - if integration.result == .Succeeded { + switch integration.result { + case .Succeeded?: self.appendTestsPassed(buildResultSummary) - } else if integration.result == .Warnings { - self.appendWarnings(buildResultSummary) - } else if integration.result == .AnalyzerWarnings { - self.appendAnalyzerWarnings(buildResultSummary) + case .Warnings?, .AnalyzerWarnings?: + + switch (buildResultSummary.warningCount, buildResultSummary.analyzerWarningCount) { + case (_, 0): + self.appendWarnings(buildResultSummary) + case (0, _): + self.appendAnalyzerWarnings(buildResultSummary) + default: + self.appendWarningsAndAnalyzerWarnings(buildResultSummary) + } + + default: break } //and code coverage @@ -132,6 +141,14 @@ class SummaryBuilder { self.lines.append(self.resultString + "All \(testsCount) tests passed, but please **fix \(analyzerWarningCount) " + "analyzer warning".pluralizeStringIfNecessary(analyzerWarningCount) + "**.") } + func appendWarningsAndAnalyzerWarnings(buildResultSummary: BuildResultSummary) { + + let warningCount = buildResultSummary.warningCount + let analyzerWarningCount = buildResultSummary.analyzerWarningCount + let testsCount = buildResultSummary.testsCount + self.lines.append(self.resultString + "All \(testsCount) tests passed, but please **fix \(warningCount) " + "warning".pluralizeStringIfNecessary(warningCount) + "** and **\(analyzerWarningCount) " + "analyzer warning".pluralizeStringIfNecessary(analyzerWarningCount) + "**.") + } + func appendCodeCoverage(buildResultSummary: BuildResultSummary) { let codeCoveragePercentage = buildResultSummary.codeCoveragePercentage diff --git a/BuildaKitTests/GitHubSummaryBuilderTests.swift b/BuildaKitTests/GitHubSummaryBuilderTests.swift index 1c7d96f..5bce9a5 100644 --- a/BuildaKitTests/GitHubSummaryBuilderTests.swift +++ b/BuildaKitTests/GitHubSummaryBuilderTests.swift @@ -130,6 +130,22 @@ class GitHubSummaryBuilderTests: XCTestCase { expect(result.status.state) == exp_state } + func testPassing_withTests_withWarningsAndAnalyzerWarnings() { + + let buildResultSummary = MockBuildResultSummary(analyzerWarningCount: 10, testsCount: 99, warningCount: 2, codeCoveragePercentage: 12) + let integration = self.integration(.Warnings, buildResultSummary: buildResultSummary) + let summary = SummaryBuilder() + summary.statusCreator = MockGitHubServer() + let result = summary.buildPassing(integration) + + let exp_comment = "Result of Integration 15\n---\n*Duration*: 28 seconds\n*Result*: All 99 tests passed, but please **fix 2 warnings** and **10 analyzer warnings**.\n*Test Coverage*: 12%" + let exp_status = "Build passed!" + let exp_state = BuildState.Success + expect(result.comment) == exp_comment + expect(result.status.description) == exp_status + expect(result.status.state) == exp_state + } + func testFailingTests() { //got 99 tests but failing's just one