#!/bin/bash #shellcheck disable=SC1090 . "$(sfpath)" || exit 3 shellfu import pretty shellfu import saturnin shellfu import jat usage() { mkusage "$@" "[options] BODY" \ -- \ "Initialize session and quick-run JAT test." \ "" \ -o \ "-n NS Set BEID namespace to NS" \ "-d SDIR Set JAR session directory to SDIR. This is where" \ " state data is kept. Default: /var/tmp/jat." \ "-y YLOG Write YAML log also to file YLOG. Default is to" \ " write only to default file under session dir." \ -- \ "Test body should consist of asserts and/or phases documented" \ "in jat.sh Shellfu module; use \`sfdoc jat\` to access its" \ "documentation." } qrun() { # # Wrap in boilerplate and run test code in $1 # JAT__BEID_NS=$BeidNs JAT__YLOG=$YLog JAT__DIR=$SDir bash -n "$Body" || { warn "test body has syntax errors" return 3 } jat__sinit || { warn "failed to initialize logging" return 3 } source "$Body" jat__sfinish } main() { local Body local SDir=$JAT__DIR local YLog=$JAT__YLOG local BeidNs=$JAT__BEID_NS while true; do case $1 in -n) BeidNs=$2; shift 2 || usage -w "missing NS" ;; -d) SDir=$2; shift 2 || usage -w "missing SDIR" ;; -y) YLog=$2; shift 2 || usage -w "missing YLOG" ;; -*) usage ;; *) break ;; esac done Body=$1; shift test -n "$Body" || usage -w "no BODY?" test -f "$Body" || warn "test body not found: $Body" test -n "$SDir" && SDir=$(saturnin__conf -j -1 jattool.sdir) test -n "$YLog" && YLog=$(saturnin__conf -j -1 jattool.ylog) test -n "$BeidNs" && BeidNs=$(saturnin__conf -j -1 jattool.beid_ns) test -n "$SDir" || SDir=/var/tmp/jat debug -v Body BeidNs SDir YLog qrun } main "$@"