Allow verifying prerequisites!

This commit is contained in:
vlad 2021-12-20 21:10:46 -08:00
parent e8bc9f0655
commit c06ca5dad2
4 changed files with 46 additions and 1 deletions

View File

@ -44,4 +44,12 @@
_bad-message - Bad Message _bad-message - Bad Message
} }
_verify-prerequisites() {
if ! [[ -f /tmp/banana ]]; then
_bad-message There\'s not enough banana
_bad-message touch /tmp/banana to continue
exit 1
fi
}
source ⚡️ source ⚡️

View File

@ -119,7 +119,7 @@ $ echo '
#!/usr/bin/env bash #!/usr/bin/env bash
_verify-prerequisites() { _verify-prerequisites() {
docker ps &> /dev/null || echo 'Not enough docker' docker ps &> /dev/null || (echo 'Not enough docker'; exit 1)
} }
ubuntu() { ubuntu() {

35
test/test-prereqs Normal file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
testShouldBailIfRequirementsNotMet() {
echo '
#!/usr/bin/env bash
_verify-prerequisites() { false; }
hello() { echo "Hello, World!" ; }
' > go
echo "source $REPO_ROOT/⚡️" >> go
chmod +x go
try ./go
assertNotContains "$STDOUT" "hello"
assertEquals 1 "$EXIT_CODE"
}
testShouldNotBailWhenPrereqsAreAllGood() {
echo '
#!/usr/bin/env bash
_verify-prerequisites() { true; }
hello() { echo "Hello, World!" ; }
' > go
echo "source $REPO_ROOT/⚡️" >> go
chmod +x go
try ./go
assertContains "$STDOUT" "hello"
assertEquals 0 "$EXIT_CODE"
}
source $(dirname $0)/runner

2
⚡️
View File

@ -40,4 +40,6 @@ _bad-message() {
echo -e "\e[31m$@\e[0m" echo -e "\e[31m$@\e[0m"
} }
[[ $(type -t _verify-prerequisites) == "function" ]] && ! _verify-prerequisites && exit 1
main "$@" main "$@"