jattool-tfind 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. #shellcheck disable=SC1090,SC2164
  3. . "$(sfpath)" || exit 3
  4. shellfu import pretty
  5. usage() {
  6. mkusage "$@" "[options] PATH" \
  7. -- \
  8. "Discover all JATS tests under directory PATH." \
  9. -o \
  10. "-f FMT Print test name in format FMT. 'jats' or 'path'."
  11. }
  12. discover() {
  13. #
  14. # Find tests under dirs ${FindDirs[@]}
  15. #
  16. local SuiteDir # suite root dir
  17. local TRPath # relative path to test directory within $SuiteDir
  18. local SuiteId # suite's jats: id
  19. jattool sfind -f path "${FindDirs[@]}" \
  20. | while read -r SuiteDir; do
  21. SuiteId=$(jattool sfind "$SuiteDir")
  22. debug -v SuiteDir SuiteId
  23. pushd "$SuiteDir">/dev/null
  24. find . -type f -name test -printf '%P\n' \
  25. | sed 's:/test::' \
  26. | while read -r TRPath; do
  27. case $Fmt in
  28. path) echo "$SuiteDir/$TRPath" ;;
  29. jats) echo "$SuiteId/$TRPath" ;;
  30. esac
  31. debug -v TRPath
  32. done
  33. popd >/dev/null
  34. done
  35. }
  36. main() {
  37. local FindDirs=()
  38. local Fmt=path
  39. while true; do case $1 in
  40. -f) Fmt=$2; shift 2 || usage -w "missing FMT" ;;
  41. -*) usage -w "unknown argument: $1" ;;
  42. *) break ;;
  43. esac done
  44. FindDirs=("$@")
  45. case $Fmt in
  46. jats|path) : ;;
  47. *) usage -w "unknown FMT: $Fmt" ;;
  48. esac
  49. debug -v FindDirs Fmt
  50. discover
  51. }
  52. main "$@"