#!/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__TESTID=$TestId jattool qrun "./test" } JATS__PATH=${JATS__PATH:-/usr/share/jat/suite} tlocate() { # # Locate test $TestId under known paths # debug -v JATS__PATH local trypath for trypath in ${JATS__PATH//:/ }; do debug -v trypath test -n "$trypath" || continue test -d "$trypath" || continue case $(jattool tfind -f ALL "$trypath" | grep -c " $TestId$") in 1) jattool tfind "$trypath"; return 0 ;; *) continue ;; esac done return 3 } main() { local TestHome local TestTmp local TestId 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) || die "could not locate test: $TestId" ;; esac test -f "$TestHome/test" \ || die "test body not found: $TestHome/test" 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 "$@"