Skip to content

Commit

Permalink
Add Path doesNotExist assertion (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
jisungbin authored Jul 9, 2024
1 parent 58e6931 commit 9a7abb8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- renamed `prop` to `having` as part of effort to unify API naming, old name is deprecated.
- renamed `suspendCall` to `having` as part of effort to unify API naming, old name is deprecated.
- added `doesNotExist` assertions to `Path`.

## [0.28.1] 2024-04-17

Expand Down
12 changes: 12 additions & 0 deletions assertk/src/jvmMain/kotlin/assertk/assertions/path.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,15 @@ fun Assert<Path>.exists(vararg options: LinkOption) = given { actual ->
expected("${show(actual)} to exist, but it does not")
}
}

/**
* Assert that the path does not exists.
*
* @param options indicating how symbolic links are handled
*/
@Suppress("SpreadOperator") // https://github.com/arturbosch/detekt/issues/391
fun Assert<Path>.doesNotExist(vararg options: LinkOption) = given { actual ->
if (!Files.notExists(actual, *options)) {
expected("${show(actual)} does not exist, but it exists")
}
}
23 changes: 23 additions & 0 deletions assertk/src/jvmTest/kotlin/test/assertk/assertions/PathTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,29 @@ class PathTest {
}
//endregion

//region exists
@Test
fun doesNotExist_value_regularFile_fails() {
val error = assertFailsWith<AssertionError> {
assertThat(regularFile!!).doesNotExist()
}
assertEquals("expected <$regularFile> does not exist, but it exists", error.message)
}

@Test
fun doesNotExist_value_directory_fails() {
val error = assertFailsWith<AssertionError> {
assertThat(directory!!).doesNotExist()
}
assertEquals("expected <$directory> does not exist, but it exists", error.message)
}

@Test
fun doesNotExist_value_not_exists_passes() {
assertThat(doesNotExist!!).doesNotExist()
}
//endregion

//region lines
@Test
fun lines_correct_string_passes() {
Expand Down

0 comments on commit 9a7abb8

Please sign in to comment.