jattool-qrun 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. #shellcheck disable=SC1090
  3. . "$(sfpath)" || exit 3
  4. shellfu import pretty
  5. shellfu import saturnin
  6. shellfu import jat
  7. usage() {
  8. mkusage "$@" "[options] BODY" \
  9. -- \
  10. "Initialize session and quick-run JAT test." \
  11. "" \
  12. -o \
  13. "-n NS Set BEID namespace to NS" \
  14. "-d SDIR Set JAR session directory to SDIR. This is where" \
  15. " state data is kept. Default: /var/tmp/jat." \
  16. "-y YLOG Write YAML log also to file YLOG. Default is to" \
  17. " write only to default file under session dir." \
  18. -- \
  19. "Test body should consist of asserts and/or phases documented" \
  20. "in jat.sh Shellfu module; use \`sfdoc jat\` to access its" \
  21. "documentation."
  22. }
  23. qrun() {
  24. #
  25. # Wrap in boilerplate and run test code in $1
  26. #
  27. local tes
  28. JAT__BEID_NS=$BeidNs
  29. JAT__YLOG=$YLog
  30. JAT__DIR=$SDir
  31. bash -n "$Body" || {
  32. warn "test body has syntax errors"
  33. return 3
  34. }
  35. jat__sinit || {
  36. warn "failed to initialize logging"
  37. return 3
  38. }
  39. source "$Body"
  40. jat__sfinish; tes=$?
  41. test $tes -gt 1 && die "test indicated invalid results"
  42. return $tes
  43. }
  44. main() {
  45. local Body
  46. local SDir=$JAT__DIR
  47. local YLog=$JAT__YLOG
  48. local BeidNs=$JAT__BEID_NS
  49. while true; do case $1 in
  50. -n) BeidNs=$2; shift 2 || usage -w "missing NS" ;;
  51. -d) SDir=$2; shift 2 || usage -w "missing SDIR" ;;
  52. -y) YLog=$2; shift 2 || usage -w "missing YLOG" ;;
  53. -*) usage ;;
  54. *) break ;;
  55. esac done
  56. Body=$1; shift
  57. test -n "$Body" || usage -w "no BODY?"
  58. test -f "$Body" || warn "test body not found: $Body"
  59. test -n "$SDir" && SDir=$(saturnin__conf -j -1 jattool.sdir)
  60. test -n "$YLog" && YLog=$(saturnin__conf -j -1 jattool.ylog)
  61. test -n "$BeidNs" && BeidNs=$(saturnin__conf -j -1 jattool.beid_ns)
  62. test -n "$SDir" || SDir=/var/tmp/jat
  63. debug -v Body BeidNs SDir YLog
  64. qrun
  65. }
  66. main "$@"