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 89d93d6..2f97b6c 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt @@ -274,7 +274,7 @@ open class Prov protected constructor( level++ // call the actual function - val res = if (!exit) { + val sublevelResult = if (!exit) { progress(internalResult) @Suppress("UNUSED_EXPRESSION") // false positive a() @@ -291,20 +291,20 @@ open class Prov protected constructor( // for a leaf (task with mo subtask) or tasks "cmd" resp. "repeatUntilTrue" provide also out and err of original results // because results of cmd and leafs are not included in the reporting // and the caller of repeatUntilTrue might need to see the complete result (incl. out and err) and not only success value - res.copy() + sublevelResult.copy() } else { // just pass success value, no other data of the original result - ProvResult(res.success) + ProvResult(sublevelResult.success) } } else if (mode == ResultMode.ALL) { // leaf - if (internalResultIsLeaf(resultIndex)) res.copy() + if (internalResultIsLeaf(resultIndex)) sublevelResult.copy() // evaluate subcalls' results - else ProvResult(cumulativeSuccessSublevel(resultIndex) ?: false) + else ProvResult((cumulativeSuccessSublevel(resultIndex) ?: false) && sublevelResult.success) } else if (mode == ResultMode.NONE) { ProvResult(true) } else if (mode == ResultMode.FAILEXIT) { - return if (res.success) { + return if (sublevelResult.success) { ProvResult(true) } else { exit = true 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 619e1a2..0474458 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt @@ -406,6 +406,44 @@ internal class ProvTest { assertEquals(ProvResult(true), res) } + @Test + fun task_with_subtask_and_failed_result_fails() { + // given + fun Prov.inner() { + addResultToEval(ProvResult(true)) + } + + fun Prov.outer() = task { + inner() + ProvResult(false) + } + + // when + val res = testLocal().outer() + + //then + assertEquals(ProvResult(false), res) + } + + @Test + fun task_with_failing_subtask_and_successful_result_fails() { + // given + fun Prov.inner() = task { + ProvResult(false) + } + + fun Prov.outer() = task { + inner() + ProvResult(true) + } + + // when + val res = testLocal().outer() + + //then + assertEquals(ProvResult(false), res) + } + @Test fun addResultToEval_failure() { // given