diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt index f13fbc4..343642e 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt @@ -374,8 +374,9 @@ open class Prov protected constructor( successPerLevel.add(successOfCurrentLevel) } - val successOfLevelAbove = if (currentLevel == 0) successOfCurrentLevel else successPerLevel[currentLevel - 1] - println(result.toString().escapeControlChars().formattedAsResultLine(successOfLevelAbove)) + // check success levels above; if a level above succeeded then a failure in this level will be considered optional (i.e. marked yellow instead of red) + val successOfLevelsAbove = levelsAboveContainsSuccess(successPerLevel, currentLevel) + println(result.toString().escapeControlChars().formattedAsResultLine(successOfLevelsAbove)) } if (internalResults.size > 1) { println("----------------------------------------------------------------------------------------------------- ") @@ -384,6 +385,14 @@ open class Prov protected constructor( println("============================================ SUMMARY END ============================================ " + newline()) } + private fun levelsAboveContainsSuccess(successPerLevel: ArrayList, currentLevel: Int): Boolean { + var success = false + for (i in 0..currentLevel - 1) { + success = success || successPerLevel[i] + } + return success + } + private fun String.formattedAsResultLine(showFailedInYellow: Boolean = false): String { val failedColor = if (showFailedInYellow) ANSI_BRIGHT_YELLOW else ANSI_BRIGHT_RED return this diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt index c72e93d..10e056b 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt @@ -355,7 +355,7 @@ internal class ProvTest { @Test @NonCi - fun prov_prints_correct_output_for_failure_that_is_not_taken_into_account() { + fun prov_marks_failed_output_yellow_if_optional() { // given setRootLoggingLevel(Level.OFF) @@ -369,11 +369,14 @@ internal class ProvTest { System.setErr(PrintStream(errContent)) // when - Prov.newInstance(name = "test instance with no progress info", progressType = ProgressType.NONE).requireLast { - checkPrereq_evaluateToFailure() - task("returns success") { - ProvResult(true) - } + Prov.newInstance(name = "test instance with no progress info", progressType = ProgressType.NONE).task("taskA") { + optional { + taskWithResult("taskB") { + taskWithResult("taskC") { + ProvResult(false) + } + } + } } // then @@ -384,9 +387,10 @@ internal class ProvTest { val expectedOutput = "============================================== SUMMARY (test instance with no progress info) ============================================== \n" + - "> \u001B[92mSuccess\u001B[0m -- prov_prints_correct_output_for_failure_that_is_not_taken_into_account (requireLast) \n" + - "---> \u001B[93mFAILED\u001B[0m -- checkPrereq_evaluateToFailure (requireLast) -- Error: This is a test error.\n" + - "---> \u001B[92mSuccess\u001B[0m -- returns success \n" + + "> \u001B[92mSuccess\u001B[0m -- taskA \n" + + "---> \u001B[92mSuccess\u001B[0m -- prov_marks_failed_output_yellow_if_optional (optional) \n" + + "------> \u001B[93mFAILED\u001B[0m -- taskB \n" + + "---------> \u001B[93mFAILED\u001B[0m -- taskC \n" + "----------------------------------------------------------------------------------------------------- \n" + "Overall > \u001B[92mSuccess\u001B[0m\n" + "============================================ SUMMARY END ============================================ \n" + diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/keys/ProvisionKeysTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/keys/ProvisionKeysTest.kt index e81257e..612b0f5 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/keys/ProvisionKeysTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/keys/ProvisionKeysTest.kt @@ -2,13 +2,13 @@ package org.domaindrivenarchitecture.provs.framework.ubuntu.keys import org.domaindrivenarchitecture.provs.framework.core.Secret import org.domaindrivenarchitecture.provs.test.defaultTestContainer +import org.domaindrivenarchitecture.provs.test.tags.ContainerTest import org.domaindrivenarchitecture.provs.test.tags.NonCi import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test internal class ProvisionKeysTest { - @Test + @ContainerTest @NonCi fun provisionKeys() { // given