Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add canExecute for File and add test case for assertions #519

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions assertk/src/jvmMain/kotlin/assertk/assertions/file.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ fun Assert<File>.isFile() = given { actual ->
expected("to be a file")
}

/** Assert that the file is an executable. */
fun Assert<File>.canExecute() = given { actual ->
if (actual.canExecute()) return
expected("to be executable")
}

/**
* Asserts the file is hidden.
* @see [isNotHidden]
Expand Down
24 changes: 24 additions & 0 deletions assertk/src/jvmTest/kotlin/test/assertk/assertions/FileTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ class FileTest {
}
//endregion

//region canExecute
@Test
fun canExecute_value_regular_file_passes() {
file.setExecutable(true)
assertThat(file).canExecute()
}

@Test
fun canExecute_value_directory_fails() {
file.setExecutable(false)
val error = assertFailsWith<AssertionError> {
assertThat(file).canExecute()
}
assertEquals("expected to be executable", error.message)
}
//endregion

//region isNotHidden
@Test
fun isNotHidden_value_regular_file_passes() {
Expand Down Expand Up @@ -207,6 +224,13 @@ class FileTest {
assertThat(fileWithText).text().contains("Forty-two")
}

//region bytes
@Test
fun hasBytes_correct_value_passes() {
assertThat(fileWithText).bytes().isEqualTo(fileWithText.readBytes())
}
//endregion

@Test
fun contains_wrong_substring_fails() {
val error = assertFailsWith<AssertionError> {
Expand Down
18 changes: 18 additions & 0 deletions assertk/src/jvmTest/kotlin/test/assertk/assertions/PathTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ class PathTest {
}
//endregion


//region isExecutable
@Test
fun isExecutable_value_regular_file_executable_passes() {
regularFile!!.toFile().setExecutable(true)
assertThat(regularFile!!).isExecutable()
}

@Test
fun isExecutable_value_regular_file_not_executable_fails() {
regularFile!!.toFile().setExecutable(false)
val error = assertFailsWith<AssertionError> {
assertThat(regularFile!!).isExecutable()
}
assertEquals("expected <$regularFile> to be an executable, but it is not", error.message)
}
//endregion

//region isHidden
@Test
fun isHidden_value_regular_file_not_hidden_fails() {
Expand Down