#! /bin/bash # Test me with: ./test_cli.sh PATH/TO/PROGRAM SCRIPTDIR="$(dirname "$0")" ORIGDIR="$(pwd)" cd "$SCRIPTDIR" export FORGEHOOK="$(pwd)/tests/mock-forgehook.sh" source tests/helper.bash if [ -z "$1" ]; then output="$(findBin "$ORIGDIR"/bin/cli ../bin/cli)" if [ $? -eq 0 ]; then if [[ "$(echo "$output" | wc -l)" == "1" ]]; then FIND_WHCK="$output" else # Some warnings, print but use result from last line echo "$output" | head -n -1 FIND_WHCK="$(echo "$output" | tail -n 1)" fi else echo "ERROR: Could not find webhook validation program. Output:" echo "$output" exit 1 fi # cli script needs to be executed to get absolute path to the program export WHCK="$("$FIND_WHCK")" else if [ -f "$ORIGDIR"/"$1" ] && [ -x "$ORIGDIR"/"$1" ]; then export WHCK="$(realpath "$ORIGDIR"/"$1")" elif [ -f "$1" ] && [ -x "$1" ]; then export WHCK="$(realpath "$1")" else echo "ERROR: Could not find provided validation program: "$1"" exit 2 fi fi bats tests/cli/*.bats status=$? cd "$ORIGDIR" exit $status