Skip to content

Commit

Permalink
Fix otherNativeCrash NPE (#1027)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-goral authored Aug 20, 2020
1 parent ca0cfa6 commit 4771b65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.google.api.services.toolresults.model.FailureDetail
import com.google.api.services.toolresults.model.InconclusiveDetail
import com.google.api.services.toolresults.model.Outcome
import com.google.api.services.toolresults.model.SkippedDetail
import com.google.common.annotations.VisibleForTesting
import ftl.reports.api.data.TestSuiteOverviewData
import ftl.util.StepOutcome.failure
import ftl.util.StepOutcome.flaky
Expand Down Expand Up @@ -34,13 +35,14 @@ private fun TestSuiteOverviewData.getSuccessOutcomeDetails(
private val TestSuiteOverviewData.successCount
get() = total - errors - failures - skipped - flakes

private fun FailureDetail?.getFailureOutcomeDetails(testSuiteOverviewData: TestSuiteOverviewData?) = when {
@VisibleForTesting
internal fun FailureDetail?.getFailureOutcomeDetails(testSuiteOverviewData: TestSuiteOverviewData?) = when {
this == null -> testSuiteOverviewData?.buildFailureOutcomeDetailsSummary() ?: "Unknown failure"
crashed == true -> "Application crashed"
timedOut == true -> "Test timed out"
notInstalled == true -> "App failed to install"
else -> testSuiteOverviewData?.buildFailureOutcomeDetailsSummary() ?: "Unknown failure"
} + this?.takeIf { it.otherNativeCrash }?.let { NATIVE_CRASH_MESSAGE }.orEmpty()
} + this?.takeIf { it.otherNativeCrash ?: false }?.let { NATIVE_CRASH_MESSAGE }.orEmpty()

private fun TestSuiteOverviewData.buildFailureOutcomeDetailsSummary() =
StringBuilder("$failures test cases failed").apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ftl.json

import com.google.api.services.toolresults.model.FailureDetail
import com.google.api.services.toolresults.model.Outcome
import ftl.reports.api.data.TestSuiteOverviewData
import ftl.util.StepOutcome
Expand All @@ -20,8 +21,8 @@ internal class OutcomeDetailsFormatterTest {
val testSuiteOverviewData = TestSuiteOverviewData(12, 0, 0, 3, 2, 0.0, 0.0)
val successCount = with(testSuiteOverviewData) { total - errors - failures - flakes - skipped }
val expectedMessage = "$successCount test cases passed, " +
"${testSuiteOverviewData.skipped} skipped, " +
"${testSuiteOverviewData.flakes} flaky"
"${testSuiteOverviewData.skipped} skipped, " +
"${testSuiteOverviewData.flakes} flaky"

// when
val result = mockedOutcome.getDetails(testSuiteOverviewData)
Expand All @@ -40,9 +41,9 @@ internal class OutcomeDetailsFormatterTest {
val testSuiteOverviewData = TestSuiteOverviewData(12, 0, 0, 3, 2, 0.0, 0.0)
val successCount = with(testSuiteOverviewData) { total - errors - failures - flakes - skipped }
val expectedMessage = "$successCount test cases passed, " +
"${testSuiteOverviewData.skipped} skipped, " +
"${testSuiteOverviewData.flakes} flaky" +
" (Native crash)"
"${testSuiteOverviewData.skipped} skipped, " +
"${testSuiteOverviewData.flakes} flaky" +
" (Native crash)"

// when
val result = mockedOutcome.getDetails(testSuiteOverviewData)
Expand All @@ -65,10 +66,10 @@ internal class OutcomeDetailsFormatterTest {
}
val testSuiteOverviewData = TestSuiteOverviewData(12, 3, 3, 3, 2, 0.0, 0.0)
val expectedMessage = "${testSuiteOverviewData.failures} test cases failed, " +
"${testSuiteOverviewData.errors} errors, " +
"1 passed, " +
"${testSuiteOverviewData.skipped} skipped, " +
"${testSuiteOverviewData.flakes} flaky"
"${testSuiteOverviewData.errors} errors, " +
"1 passed, " +
"${testSuiteOverviewData.skipped} skipped, " +
"${testSuiteOverviewData.flakes} flaky"

// when
val result = mockedOutcome.getDetails(testSuiteOverviewData)
Expand Down Expand Up @@ -346,4 +347,11 @@ internal class OutcomeDetailsFormatterTest {
// then
assertEquals(expectedMessage, result)
}

@Test // https://github.com/flank/flank/issues/1026
fun `should not throw when otherNativeCrash is null`() {
FailureDetail().apply {
otherNativeCrash = null
}.getFailureOutcomeDetails(null)
}
}

0 comments on commit 4771b65

Please sign in to comment.