Last active
October 8, 2020 20:10
-
-
Save Potherca/e473a28d15c0d4d4db1468befa6c574a to your computer and use it in GitHub Desktop.
Minimal code example for https://stackoverflow.com/questions/64232453/bats-how-to-force-a-check-for-existence-of-a-program-to-fail
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
#!/usr/bin/env bash | |
ds() { | |
is_command() { | |
[[ -x "$("${command}" -v "$1" 2> /dev/null)" ]] && return 0 | |
return 1 | |
} | |
is_command 'dos2unix' || { echo 'dos2unix is required'; exit 1; } | |
exit 0; | |
} |
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
#!/usr/bin/env bats | |
source "${BATS_TEST_DIRNAME}/ds.sh" | |
@test 'dos2unix does not exist' { | |
hash -r | |
BASH_CMDS['dos2unix']='/no/such/dir/dos2unix' | |
run ds | |
[ "${status}" -eq 1 ] | |
[ "${output}" = 'dos2unix is required' ] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment