Skip to content

Commit

Permalink
fix: do not delete IF_SUCCESSFUL files of groups if one of their test…
Browse files Browse the repository at this point in the history
…s fail
  • Loading branch information
jGleitz committed Sep 29, 2020
1 parent 716aff3 commit fbca3f6
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import de.joshuagleitze.test.spek.testfiles.DeletionMode.IF_SUCCESSFUL
import de.joshuagleitze.test.spek.testfiles.DeletionMode.NEVER
import org.spekframework.spek2.dsl.Root
import org.spekframework.spek2.lifecycle.ExecutionResult
import org.spekframework.spek2.lifecycle.ExecutionResult.Success
import org.spekframework.spek2.lifecycle.ExecutionResult.Failure
import org.spekframework.spek2.lifecycle.GroupScope
import org.spekframework.spek2.lifecycle.LifecycleListener
import org.spekframework.spek2.lifecycle.Scope
Expand Down Expand Up @@ -57,7 +57,10 @@ class DefaultTestFiles internal constructor(): LifecycleListener, TestFiles {
}

private fun leave(result: ExecutionResult) {
scopeFiles.pop().cleanup(wasSuccess = result is Success)
if (result is Failure) {
scopeFiles.forEach { it.reportFailure() }
}
scopeFiles.pop().cleanup()
}

private val Scope.name: String
Expand All @@ -74,6 +77,7 @@ class DefaultTestFiles internal constructor(): LifecycleListener, TestFiles {
private val toDelete: MutableSet<Path> = HashSet(),
private var created: Boolean = false
) {
private var wasSuccess = true
private val idGenerator = Random(targetDirectory.hashCode().toLong())

fun prepareNewPath(name: String?, delete: DeletionMode): Path {
Expand All @@ -100,7 +104,7 @@ class DefaultTestFiles internal constructor(): LifecycleListener, TestFiles {
return targetDirectory
}

fun cleanup(wasSuccess: Boolean) {
fun cleanup() {
if (created) {
synchronized(this) {
toDelete.forEach(::clear)
Expand All @@ -112,6 +116,10 @@ class DefaultTestFiles internal constructor(): LifecycleListener, TestFiles {
}
}

fun reportFailure() {
wasSuccess = false
}

private fun generateTestFileName() = "test-" + idGenerator.nextInt(MAX_VALUE)
}

Expand Down

0 comments on commit fbca3f6

Please sign in to comment.