specs/test_cli.sh

42 lines
982 B
Bash
Executable File

#! /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 WHCK="$(realpath -q "$ORIGDIR"/"$1")"; then
export WHCK
else
export WHCK="$(realpath "$1")"
fi
fi
bats tests/cli/*.bats
cd "$ORIGDIR"