-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Path.shouldBeAFile should fail on non-existant files
Fixes #3825 Signed-off-by: Leonardo Colman Lopes <dev@leonardo.colman.com.br>
- Loading branch information
Showing
2 changed files
with
25 additions
and
16 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
33 changes: 20 additions & 13 deletions
33
...assertions-core/src/jvmTest/kotlin/com/sksamuel/kotest/matchers/paths/PathMatchersTest.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 |
---|---|---|
@@ -1,27 +1,34 @@ | ||
package com.sksamuel.kotest.matchers.paths | ||
|
||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.paths.shouldBeAFile | ||
import io.kotest.matchers.paths.shouldBeEmptyDirectory | ||
import io.kotest.matchers.paths.shouldNotBeEmptyDirectory | ||
import java.nio.file.Files | ||
import kotlin.io.path.Path | ||
|
||
@Suppress("BlockingMethodInNonBlockingContext") | ||
class PathMatchersTest : FunSpec() { | ||
class PathMatchersTest : FunSpec({ | ||
|
||
init { | ||
|
||
test("directory should be empty (deprecated)") { | ||
val path = Files.createTempDirectory("testdir") | ||
path.shouldBeEmptyDirectory() | ||
Files.write(path.resolve("testfile.txt"), byteArrayOf(1, 2, 3)) | ||
path.shouldNotBeEmptyDirectory() | ||
} | ||
context("Be a file") { | ||
test("Should fail for files that don't exist") { | ||
shouldThrow<AssertionError> { Path("abc").shouldBeAFile() } | ||
} | ||
} | ||
|
||
test("directory should be empty") { | ||
|
||
test("directory should be empty (deprecated)") { | ||
val path = Files.createTempDirectory("testdir") | ||
path.shouldBeEmptyDirectory() | ||
Files.write(path.resolve("testfile.txt"), byteArrayOf(1, 2, 3)) | ||
path.shouldNotBeEmptyDirectory() | ||
} | ||
|
||
test("directory should be empty") { | ||
val path = Files.createTempDirectory("testdir") | ||
path.shouldBeEmptyDirectory() | ||
Files.write(path.resolve("testfile.txt"), byteArrayOf(1, 2, 3)) | ||
path.shouldNotBeEmptyDirectory() | ||
} | ||
} | ||
} | ||
} | ||
}) |