Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug where autoClose initialises itself when closing (#2691)
* AutoClose should be fully lazy * Don't close uninitialised lazy autoClose * Fix eager autoClose, needs an eager lazy instance
- Loading branch information
Showing
3 changed files
with
33 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ework-engine/src/jvmTest/kotlin/com/sksamuel/kotest/engine/autoclose/LazyAutoCloseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.sksamuel.kotest.engine.autoclose | ||
|
||
import io.kotest.core.spec.style.StringSpec | ||
import io.kotest.matchers.booleans.shouldBeFalse | ||
import io.kotest.matchers.booleans.shouldBeTrue | ||
|
||
class LazyAutoCloseTest : StringSpec({ | ||
|
||
var fullLazy = true | ||
var closed = false | ||
val closeme = AutoCloseable { closed = true } | ||
|
||
autoClose(lazy { | ||
fullLazy = false | ||
closeme | ||
}) | ||
|
||
"autoClose lazy should be lazy" { | ||
fullLazy.shouldBeTrue() | ||
closed.shouldBeFalse() | ||
} | ||
|
||
afterProject { | ||
// If never used in the Spec it should never get initialised, or closed | ||
fullLazy.shouldBeTrue() | ||
closed.shouldBeFalse() | ||
} | ||
}) |