jattool-qrun 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. JAT__BEID_NS=$BeidNs
  28. JAT__YLOG=$YLog
  29. JAT__DIR=$SDir
  30. bash -n "$Body" || {
  31. warn "test body has syntax errors"
  32. return 3
  33. }
  34. jat__sinit || {
  35. warn "failed to initialize logging"
  36. return 3
  37. }
  38. source "$Body"
  39. jat__sfinish; tes=$?
  40. test $tes -gt 1 && die "test indicated invalid results"
  41. }
  42. main() {
  43. local Body
  44. local SDir=$JAT__DIR
  45. local YLog=$JAT__YLOG
  46. local BeidNs=$JAT__BEID_NS
  47. while true; do case $1 in
  48. -n) BeidNs=$2; shift 2 || usage -w "missing NS" ;;
  49. -d) SDir=$2; shift 2 || usage -w "missing SDIR" ;;
  50. -y) YLog=$2; shift 2 || usage -w "missing YLOG" ;;
  51. -*) usage ;;
  52. *) break ;;
  53. esac done
  54. Body=$1; shift
  55. test -n "$Body" || usage -w "no BODY?"
  56. test -f "$Body" || warn "test body not found: $Body"
  57. test -n "$SDir" && SDir=$(saturnin__conf -j -1 jattool.sdir)
  58. test -n "$YLog" && YLog=$(saturnin__conf -j -1 jattool.ylog)
  59. test -n "$BeidNs" && BeidNs=$(saturnin__conf -j -1 jattool.beid_ns)
  60. test -n "$SDir" || SDir=/var/tmp/jat
  61. debug -v Body BeidNs SDir YLog
  62. qrun
  63. }
  64. main "$@"