Skip to content

Commit

Permalink
Return status 1 from _file_is_text() when path is blank or nonexi…
Browse files Browse the repository at this point in the history
…stent.

refs gh-304
  • Loading branch information
xwmx committed Feb 6, 2024
1 parent 8668ee5 commit d88d2bb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nb
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@ _file_is_text() {
--exclude=tar \
-b --mime-type)" =~ ^text ]]
else
return 0
[[ -f "${_file_path:-}" ]]
fi
}
}
Expand Down
43 changes: 43 additions & 0 deletions test/helpers-file-is-text.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bats

load test_helper

@test "'_file_is_text()' returns status 0 for text file." {
run "${_NB}" helpers file_is_text "${NB_TEST_BASE_PATH}/example.asciidoc"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 0 ]]
[[ -z "${output}" ]]
}

@test "'_file_is_text()' returns status 1 for pdf file." {
run "${_NB}" helpers file_is_text "${NB_TEST_BASE_PATH}/example.pdf"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 1 ]]
[[ -z "${output}" ]]
}

@test "'_file_is_text()' returns status 1 for nonexistent file." {
run "${_NB}" helpers file_is_text "${NB_TEST_BASE_PATH}/nonexistent"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 1 ]]
[[ -z "${output}" ]]
}

@test "'_file_is_text()' returns status 1 for blank file path." {
run "${_NB}" helpers file_is_text ""

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 1 ]]
[[ -z "${output}" ]]
}

0 comments on commit d88d2bb

Please sign in to comment.