From ab561ded3a3aba107d9345199d140e688842bf4f Mon Sep 17 00:00:00 2001 From: ansgarz Date: Sat, 19 Mar 2022 20:45:57 +0100 Subject: [PATCH] add test for output if failure is not taken into account --- .../provs/framework/core/ProvTest.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) 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 7a41311..a72a257 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt @@ -353,6 +353,48 @@ internal class ProvTest { assertEquals(expectedOutput, outContent.toString().replace("\r", "")) } + @Test + @NonCi + fun prov_prints_correct_output_for_failure_that_is_not_taken_into_account() { + + // given + setRootLoggingLevel(Level.OFF) + + val outContent = ByteArrayOutputStream() + val errContent = ByteArrayOutputStream() + val originalOut = System.out + val originalErr = System.err + + System.setOut(PrintStream(outContent)) + 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) + } + } + + // then + System.setOut(originalOut) + System.setErr(originalErr) + + println(outContent.toString()) + + val expectedOutput = + "============================================== SUMMARY (test instance with no progress info) ============================================== \n" + + "> \u001B[92mSuccess\u001B[0m -- prov_prints_correct_output_for_failure_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" + + "----------------------------------------------------------------------------------------------------- \n" + + "Overall > \u001B[92mSuccess\u001B[0m\n" + + "============================================ SUMMARY END ============================================ \n" + + "\n" + + assertEquals(expectedOutput, outContent.toString().replace("\r", "")) + } + @Test fun check_returnsTrue() { // when