Skip to content

Commit a0c48c7

Browse files
committed
Add canExecute assertion for File
Like `isExecutable` for `Path`.
1 parent 4990d38 commit a0c48c7

File tree

2 files changed

+22
-0
lines changed
  • assertk/src

2 files changed

+22
-0
lines changed

assertk/src/jvmMain/kotlin/assertk/assertions/file.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ fun Assert<File>.isFile() = given { actual ->
6464
expected("to be a file")
6565
}
6666

67+
/** Assert that the file is an executable. */
68+
fun Assert<File>.canExecute() = given { actual ->
69+
if (actual.canExecute()) return
70+
expected("to be executable")
71+
}
72+
6773
/**
6874
* Asserts the file is hidden.
6975
* @see [isNotHidden]

assertk/src/jvmTest/kotlin/test/assertk/assertions/FileTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ class FileTest {
5858
}
5959
//endregion
6060

61+
//region canExecute
62+
@Test
63+
fun canExecute_value_regular_file_passes() {
64+
file.setExecutable(true)
65+
assertThat(file).canExecute()
66+
}
67+
68+
@Test
69+
fun canExecute_value_directory_fails() {
70+
val error = assertFailsWith<AssertionError> {
71+
assertThat(file).canExecute()
72+
}
73+
assertEquals("expected to be executable", error.message)
74+
}
75+
//endregion
76+
6177
//region isNotHidden
6278
@Test
6379
fun isNotHidden_value_regular_file_passes() {

0 commit comments

Comments
 (0)