From 14690a089d9f2cfe5bb5ad9afcc7f4e33caaa08d Mon Sep 17 00:00:00 2001 From: ansgarz Date: Tue, 22 Mar 2022 20:13:10 +0100 Subject: [PATCH] improve layout of result line for FAILED results --- .../domaindrivenarchitecture/provs/framework/core/Prov.kt | 2 +- .../provs/framework/core/TaskFunctions.kt | 4 ++-- .../provs/framework/core/ProvTest.kt | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) 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 f6976b1..da95cad 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt @@ -418,7 +418,7 @@ internal data class ResultLine(val level: Int, val method: String?, var provResu override fun toString(): String { val provResult = provResult return if (provResult != null) { - prefix(level) + (if (provResult.success) "Success -- " else "FAILED -- ") + + prefix(level) + (if (provResult.success) "Success -- " else "FAILED -- ") + method + " " + (provResult.cmd ?: "") + (if (!provResult.success && provResult.err != null) " -- Error: " + provResult.err.escapeControlChars() else "") } else diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/TaskFunctions.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/TaskFunctions.kt index 595a047..ded28c1 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/TaskFunctions.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/TaskFunctions.kt @@ -4,11 +4,11 @@ package org.domaindrivenarchitecture.provs.framework.core /** * Repeats task until it returns success */ -fun Prov.repeatTaskUntilSuccess(times: Int, sleepInSec: Int, func: Prov.() -> ProvResult) = requireLast { +fun Prov.repeatTaskUntilSuccess(times: Int, sleepInSec: Int, task: Prov.() -> ProvResult) = requireLast { require(times > 0) var result = ProvResult(false, err = "Internal error") // Will only be returned if function is not executed at all, otherwise func's last result is returned for (i in 1..times) { - result = func() + result = task() if (result.success) return@requireLast result Thread.sleep(sleepInSec * 1000L) 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 39f0772..a622a24 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt @@ -305,7 +305,7 @@ internal class ProvTest { val expectedOutput = "============================================== SUMMARY (test instance with no progress info) ============================================== \n" + "> \u001B[92mSuccess\u001B[0m -- methodThatProvidesSomeOutput (requireLast) \n" + - "---> \u001B[93mFAILED\u001B[0m -- checkPrereq_evaluateToFailure (requireLast) -- Error: This is a test error.\n" + + "---> \u001B[93mFAILED\u001B[0m -- checkPrereq_evaluateToFailure (requireLast) -- Error: This is a test error.\n" + "---> \u001B[92mSuccess\u001B[0m -- sh \n" + "------> \u001B[92mSuccess\u001B[0m -- cmd [/bin/bash, -c, echo -Start test-]\n" + "------> \u001B[92mSuccess\u001B[0m -- cmd [/bin/bash, -c, echo Some output]\n" + @@ -346,7 +346,7 @@ internal class ProvTest { val expectedOutput = "============================================== SUMMARY (test instance with no progress info) ============================================== \n" + - "> \u001B[91mFAILED\u001B[0m -- checkPrereq_evaluateToFailure (requireLast) -- Error: This is a test error.\n" + + "> \u001B[91mFAILED\u001B[0m -- checkPrereq_evaluateToFailure (requireLast) -- Error: This is a test error.\n" + "============================================ SUMMARY END ============================================ \n" + "\n" @@ -384,8 +384,8 @@ internal class ProvTest { 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 -- 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" + "----------------------------------------------------------------------------------------------------- \n" + "Overall > \u001B[92mSuccess\u001B[0m\n" +