123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #!/bin/bash
- #shellcheck disable=SC1090,SC2164
-
- . "$(sfpath)" || exit 3
-
- shellfu import pretty
-
- usage() {
- mkusage "$@" "[options] TESTDIR" \
- -- \
- "Initialize session and run JAT test." \
- "" \
- "Copy whole directory into temp, launch it there under watchdog,"\
- "and after the test finishes, collect any relics back into" \
- "session directory." \
- "" \
- -o \
- "-k Keep run directory." \
- "-t TIMEOUT Kill test after TIMEOUT seconds. Default: 0," \
- " which disables the timeout. " \
- -- \
- "Test body should consist of asserts and/or phases documented" \
- "in jat.sh Shellfu module; use \`sfdoc jat\` to access its" \
- "documentation."
- }
-
- runtest() {
- #
- # Wrap in boilerplate and run test code in $1
- #
- JAT__TEST_ID=$TestId \
- JAT__TEST_VERSION=$TestVersion \
- jattool qrun "./test"
- }
-
- JATS__PATH=${JATS__PATH:-/usr/share/jats/suite}
-
- tlocate() {
- #
- # Locate test $TestId under known paths
- #
- debug -v JATS__PATH
- local trypath
- local tmatches
- for trypath in ${JATS__PATH//:/ }; do
- debug -v trypath
- test -n "$trypath" || continue
- test -d "$trypath" || continue
- tmatches=$(jattool tfind -f ALL "$trypath" | grep "^$TestId " )
- case $(wc -l <<<"$tmatches") in
- 1) cut -d' ' -f3 <<<"$tmatches"; return 0 ;;
- *) continue ;;
- esac
- done
- return 3
- }
-
- main() {
- local TestHome
- local TestTmp
- local TestId
- local TestVersion
- local Timeout
- local keeptmp=false
- local es=0
- while true; do case $1 in
- -k) keeptmp=true; shift ;;
- -t) Timeout=$2; shift 2 || usage -w "missing TIMEOUT" ;;
- -*) usage ;;
- *) break ;;
- esac done
- test -n "$Timeout" && die "sorry TIMEOUT is not supported yet"
- case $1 in
- "")
- usage -w "no TESTDIR or TESTID?"
- ;;
- jats://*)
- TestId=$1
- TestHome=$(tlocate) || die "could not locate test: $TestId"
- ;;
- */*)
- TestHome=$1
- TestId=$(jattool tfind -f id "$TestHome") || {
- warn "could not find test id, using pathname: $TestHome"
- TestId="jats://_jats_no_suite_/$TestHome"
- }
- ;;
- esac
- test -f "$TestHome/test" \
- || die "test body not found: $TestHome/test"
- TestVersion=$(jattool tfind -f version "$TestHome")
- TestTmp=$(mktemp -dt jattool-runtest.XXXXXXXX)
- debug -v TestHome TestId TestTmp
- cp -ar "$TestHome"/* "$TestTmp" \
- || die "could not copy test to tempdir"
- pushd "$TestTmp" >/dev/null
- runtest; es=$?
- popd >/dev/null
- $keeptmp || rm -rf "$TestTmp"
- $keeptmp && warn "leaving temporary directory behind: $TestTmp"
- return $es
- }
-
- main "$@"
|