@@ -6,7 +6,7 @@ import de.joshuagleitze.test.spek.testfiles.DeletionMode.IF_SUCCESSFUL
66import de.joshuagleitze.test.spek.testfiles.DeletionMode.NEVER
77import org.spekframework.spek2.dsl.Root
88import org.spekframework.spek2.lifecycle.ExecutionResult
9- import org.spekframework.spek2.lifecycle.ExecutionResult.Success
9+ import org.spekframework.spek2.lifecycle.ExecutionResult.Failure
1010import org.spekframework.spek2.lifecycle.GroupScope
1111import org.spekframework.spek2.lifecycle.LifecycleListener
1212import org.spekframework.spek2.lifecycle.Scope
@@ -57,7 +57,10 @@ class DefaultTestFiles internal constructor(): LifecycleListener, TestFiles {
5757 }
5858
5959 private fun leave (result : ExecutionResult ) {
60- scopeFiles.pop().cleanup(wasSuccess = result is Success )
60+ if (result is Failure ) {
61+ scopeFiles.forEach { it.reportFailure() }
62+ }
63+ scopeFiles.pop().cleanup()
6164 }
6265
6366 private val Scope .name: String
@@ -74,6 +77,7 @@ class DefaultTestFiles internal constructor(): LifecycleListener, TestFiles {
7477 private val toDelete : MutableSet <Path > = HashSet (),
7578 private var created : Boolean = false
7679 ) {
80+ private var wasSuccess = true
7781 private val idGenerator = Random (targetDirectory.hashCode().toLong())
7882
7983 fun prepareNewPath (name : String? , delete : DeletionMode ): Path {
@@ -100,7 +104,7 @@ class DefaultTestFiles internal constructor(): LifecycleListener, TestFiles {
100104 return targetDirectory
101105 }
102106
103- fun cleanup (wasSuccess : Boolean ) {
107+ fun cleanup () {
104108 if (created) {
105109 synchronized(this ) {
106110 toDelete.forEach(::clear)
@@ -112,6 +116,10 @@ class DefaultTestFiles internal constructor(): LifecycleListener, TestFiles {
112116 }
113117 }
114118
119+ fun reportFailure () {
120+ wasSuccess = false
121+ }
122+
115123 private fun generateTestFileName () = " test-" + idGenerator.nextInt(MAX_VALUE )
116124 }
117125
0 commit comments