Skip to content
Permalink
Browse files

Handle invalid invocation

Exit early with status 64 (usage error) and a message explaining the
problem.
  • Loading branch information
semanticart committed Jan 24, 2020
1 parent c8a113e commit 780d577e003fff0da5e48694c290caa51102c8bf
Showing with 22 additions and 0 deletions.
  1. +10 −0 cache
  2. +12 −0 test/cache.bats
10 cache
@@ -57,6 +57,16 @@ do
esac
done

if [ -z "$cache_key" ]; then
echo "Error: You must provide a cache key and command"
exit 64
fi

if [ -z "$1" ]; then
echo "Error: You must provide a command"
exit 64
fi

cache_dir=${CACHE_DIR:-$TMPDIR}
cache_file="$cache_dir$cache_key"

@@ -196,3 +196,15 @@ wait_for_second_to_pass() {
[ "$status" -eq 0 ]
[ "$output" = "2" ]
}

@test "exits with an error message when no cache-key is provided" {
run ./cache
[ "$status" -eq 64 ]
[ "$output" = "Error: You must provide a cache key and command" ]
}

@test "exits with an error message when no command is provided" {
run ./cache $TEST_KEY
[ "$status" -eq 64 ]
[ "$output" = "Error: You must provide a command" ]
}

0 comments on commit 780d577

Please sign in to comment.
You can’t perform that action at this time.