jattool-qrun 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. }
  43. main() {
  44. local Body
  45. local SDir=$JAT__DIR
  46. local YLog=$JAT__YLOG
  47. local BeidNs=$JAT__BEID_NS
  48. while true; do case $1 in
  49. -n) BeidNs=$2; shift 2 || usage -w "missing NS" ;;
  50. -d) SDir=$2; shift 2 || usage -w "missing SDIR" ;;
  51. -y) YLog=$2; shift 2 || usage -w "missing YLOG" ;;
  52. -*) usage ;;
  53. *) break ;;
  54. esac done
  55. Body=$1; shift
  56. test -n "$Body" || usage -w "no BODY?"
  57. test -f "$Body" || warn "test body not found: $Body"
  58. test -n "$SDir" && SDir=$(saturnin__conf -j -1 jattool.sdir)
  59. test -n "$YLog" && YLog=$(saturnin__conf -j -1 jattool.ylog)
  60. test -n "$BeidNs" && BeidNs=$(saturnin__conf -j -1 jattool.beid_ns)
  61. test -n "$SDir" || SDir=/var/tmp/jat
  62. debug -v Body BeidNs SDir YLog
  63. qrun
  64. }
  65. main "$@"