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 27defa6..c98bd32 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt @@ -60,12 +60,14 @@ open class Prov protected constructor( } } - private val internalResults = arrayListOf() private var level = 0 private var previousLevel = 0 private var exit = false private var runInContainerWithName: String? = null + private val internalResults = arrayListOf() + private val infoTexts = arrayListOf() + /** * A task is the base execution unit in provs. In the results overview it is represented by one line resp. result (of either success or failure). * Returns success if no sub-tasks are called or if all subtasks finish with success. @@ -233,6 +235,12 @@ open class Prov protected constructor( ProvResult(success) } + fun addInfoText(text: String) { + infoTexts.add(text) + } + + // ===================================== private functions ================================== + /** * Provides task evaluation, i.e. computes a ProvResult based on the provided resultMode, * on the returned ProvResult from the task as well as on the results from executed subtasks (if there are). @@ -365,6 +373,7 @@ open class Prov protected constructor( println("----------------------------------------------------------------------------------------------------- ") println("Overall " + internalResults[0].toString().take(10).formattedAsResultLine()) } + printInfoTexts() println("============================================ SUMMARY END ============================================ " + newline()) } @@ -412,6 +421,15 @@ open class Prov protected constructor( } } + private fun printInfoTexts() { + if (infoTexts.isNotEmpty()) { + println("----------------------------------------------------------------------------------------------------- ") + for (text in infoTexts) { + println(text) + } + } + } + } 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 7f37281..875181e 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt @@ -368,13 +368,13 @@ internal class ProvTest { // when Prov.newInstance(name = "test instance with no progress info", progressType = ProgressType.NONE).task("taskA") { - optional { - taskWithResult("taskB") { - taskWithResult("taskC") { - ProvResult(false) - } - } + optional { + taskWithResult("taskB") { + taskWithResult("taskC") { + ProvResult(false) } + } + } } // then @@ -590,5 +590,46 @@ internal class ProvTest { assertEquals(true, res.success) } + @Test + fun infoText_is_printed_correctly() { + // 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)) + + val prov = Prov.newInstance(name = "test instance with no progress info", progressType = ProgressType.NONE) + + // when + prov.task { + addInfoText("Text1") + addInfoText("Text2\nwith newline") + } + + // then + System.setOut(originalOut) + System.setErr(originalErr) + + println(outContent.toString()) + + val expectedOutput = + "============================================== SUMMARY (test instance with no progress info) ============================================== \n" + + "> \u001B[92mSuccess\u001B[0m -- infoText_is_printed_correctly \n" + + "----------------------------------------------------------------------------------------------------- \n" + + "Text1\n" + + "Text2\n" + + "with newline\n" + + "============================================ SUMMARY END ============================================ \n" + + "\n" + + assertEquals(expectedOutput, outContent.toString().replace("\r", "")) + + } + }