mirror of https://github.com/kdabir/has.git
return exit status based on number of failed commands, 0 means all passed
This commit is contained in:
parent
1549e88c4f
commit
3b6dbf78e4
|
@ -1,19 +1,22 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
@test "works with single command check" {
|
||||
result=$(bash has git)
|
||||
run bash has git
|
||||
|
||||
[[ $result == *"✔ git"* ]]
|
||||
[ "$status" -eq 0 ]
|
||||
[[ $output == *"✔ git"* ]]
|
||||
}
|
||||
|
||||
@test "safely tells about tools not configured" {
|
||||
result=$(bash has something-missing)
|
||||
run bash has something-missing
|
||||
|
||||
[[ $result == *"✘ something-missing not understood"* ]]
|
||||
[ "$status" -eq 1 ]
|
||||
[[ $output == *"✘ something-missing not understood"* ]]
|
||||
}
|
||||
|
||||
@test "env lets override safety check" {
|
||||
result=$(HAS_ALLOW_UNSAFE=y bash has something-missing)
|
||||
@test "env var lets override safety check" {
|
||||
HAS_ALLOW_UNSAFE=y run bash has something-missing
|
||||
|
||||
[[ $result == *"✘ something-missing"* ]]
|
||||
[ "$status" -eq 1 ]
|
||||
[[ $output == *"✘ something-missing"* ]]
|
||||
}
|
||||
|
|
15
has
15
has
|
@ -6,6 +6,9 @@ set -o pipefail
|
|||
PASS='✔'
|
||||
FAIL='✘'
|
||||
|
||||
OK=0
|
||||
KO=0
|
||||
|
||||
REGEX_SIMPLE_VERSION="([[:digit:]]+\.?){2,3}"
|
||||
|
||||
__dynamic_detect(){
|
||||
|
@ -85,19 +88,21 @@ __detect(){
|
|||
if [ "$status" -eq "-1" ]; then
|
||||
|
||||
echo ${FAIL} ${command} "not understood"
|
||||
|
||||
elif [ $status -eq 127 ]; then
|
||||
KO=$(($KO+1))
|
||||
elif [ ${status} -eq 127 ]; then
|
||||
|
||||
echo ${FAIL} ${command}
|
||||
|
||||
KO=$(($KO+1))
|
||||
elif [ ${status} -eq 0 ]; then
|
||||
|
||||
echo ${PASS} ${command} ${version}
|
||||
|
||||
OK=$(($OK+1))
|
||||
else
|
||||
|
||||
echo ${PASS} ${command}
|
||||
OK=$(($OK+1))
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -116,6 +121,8 @@ else
|
|||
__detect $cmd
|
||||
done
|
||||
|
||||
# echo ${OK} / $(($OK+$KO))
|
||||
exit ${KO}
|
||||
fi
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue