Skip to content

Commit

Permalink
(PDB-5215) Change ./tk to allow jvm args and use it in all ext tests
Browse files Browse the repository at this point in the history
Allow jvm args so we can adjust the -cp, and then use it in all of the
ext tests, both for consistency and so we're closer to the real
runtime arrangement.  run-all also made it look like that was already
the case.
  • Loading branch information
rbrw committed Feb 6, 2023
1 parent a8813e8 commit 6af99e5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
6 changes: 3 additions & 3 deletions ext/test/custom-exit-behavior
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ set -uexo pipefail

usage() { echo "Usage: $(basename "$0")"; }
misuse() { usage 1>&2; exit 2; }
tk() { lein trampoline run "$@"; }

test $# -eq 0 || misuse

Expand All @@ -13,8 +12,9 @@ tmpdir="$(cd "$tmpdir" && pwd)"
trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT

rc=0
tk -d -b <(echo puppetlabs.trapperkeeper.custom-exit-behavior-test/custom-exit-behavior-test-service) \
1>"$tmpdir/out" 2>"$tmpdir/err" || rc=$?
./tk -cp "$(pwd)/test" -- \
-d -b <(echo puppetlabs.trapperkeeper.custom-exit-behavior-test/custom-exit-behavior-test-service) \
1>"$tmpdir/out" 2>"$tmpdir/err" || rc=$?
cat "$tmpdir/out" "$tmpdir/err"
test "$rc" -eq 7
grep -F 'Some excitement!' "$tmpdir/out"
Expand Down
6 changes: 3 additions & 3 deletions ext/test/top-level-cli
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT

## Test handling an unknown option
rc=0
./tk --invalid-option 1>"$tmpdir/out" 2>"$tmpdir/err" || rc=$?
./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=$?
./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"
Expand All @@ -32,7 +32,7 @@ test $(wc -c < "$tmpdir/out") -eq 650

## Test handling a missing bootstrap file
rc=0
./tk frobnicate ... 1>"$tmpdir/out" 2>"$tmpdir/err" || rc=$?
./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"
42 changes: 40 additions & 2 deletions tk
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
#!/usr/bin/env bash

set -e
set -ueo pipefail

usage() { echo "Usage: tk JVM_ARG ... -- TK_ARG ..."; }
misuse() { usage 1>&2; exit 2; }

jar_glob='trapperkeeper-*-SNAPSHOT-standalone.jar'

# Believe last -cp wins for java, and here, any final -cp path will be
# placed in front of the jar.

cp=''
jvm_args=()
while test $# -gt 0; do
case "$1" in
-h|--help)
usage
exit 0
;;
-cp)
shift
test $# -gt 0 || misuse
cp="$1"
shift
;;
--)
shift
break
;;
*)
shift
jvm_args+=("$1")
;;
esac
done

if test "${TRAPPERKEEPER_JAR:-}"; then
jar="$TRAPPERKEEPER_JAR"
else
Expand All @@ -28,4 +59,11 @@ if ! test -e "$jar"; then
exit 2
fi

exec java -jar "$jar" "$@"
set -x
if test "$cp"; then
cp="$cp:$jar"
else
cp="$jar"
fi

exec java -cp "$cp" clojure.main -m puppetlabs.trapperkeeper.main "$@"

0 comments on commit 6af99e5

Please sign in to comment.