jattool-qrun 2.3KB

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