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: otherNativeCrash NPE #1027

Merged
merged 1 commit into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
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
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)
}
}