jattool-qrun 2.2KB

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