1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#!/usr/bin/env bash
set -uexo pipefail
usage() { echo "Usage: [TRAPPERKEEPER_JAR=JAR] $(basename "$0")"; }
misuse() { usage 1>&2; exit 2; }
test $# -eq 0 || misuse
tmpdir="$(mktemp -d "test-top-level-cli-XXXXXX")"
tmpdir="$(cd "$tmpdir" && pwd)"
trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT
## Test handling an unknown option
rc=0
./tk -- --invalid-option 1>"$tmpdir/out" 2>"$tmpdir/err" || rc=$?
cat "$tmpdir/out" "$tmpdir/err"
test "$rc" -eq 1
grep -F 'Unknown option: "--invalid-option"' "$tmpdir/err"
## Test --help
rc=0
./tk -- --help 1>"$tmpdir/out" 2>"$tmpdir/err" || rc=$?
cat "$tmpdir/out" "$tmpdir/err"
test "$rc" -eq 0
grep -F 'Path to bootstrap config file' "$tmpdir/out"
test $(grep -c -F 'Path to bootstrap config file' "$tmpdir/out") -eq 1
test $(wc -c < "$tmpdir/out") -eq 650
## Test handling a missing bootstrap file
rc=0
./tk -- frobnicate ... 1>"$tmpdir/out" 2>"$tmpdir/err" || rc=$?
cat "$tmpdir/out" "$tmpdir/err"
test "$rc" -eq 1
grep -F 'Unable to find bootstrap.cfg file via --bootstrap-config' "$tmpdir/err"
|