12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #!/bin/bash
- #shellcheck disable=SC1090,SC2164
-
- . "$(sfpath)" || exit 3
-
- shellfu import pretty
-
- usage() {
- mkusage "$@" "[options] PATH" \
- -- \
- "Discover all JATS tests under directory PATH." \
- -o \
- "-f FMT Print test name in format FMT. 'id' or 'path'."
- }
-
- discover() {
- #
- # Find tests under dirs ${FindDirs[@]}
- #
- local s_dir # suite root dir
- local t_cand # possible test path
- local t_apath # absolute path to test directory
- local t_rpath # relative path to test directory within $s_dir
- local s_id # suite's jats: id
- find "${FindDirs[@]}" -name test \
- | while read -r t_cand; do
- s_dir=$(straverse "$t_cand") || continue
- t_apath=$(dirname "$(readlink -f "$t_cand")")
- t_rpath=${t_apath#$s_dir/}
- s_id=$(jattool sfind -f id "$s_dir")
- debug -v s_dir s_id t_apath t_rpath
- case $Fmt in
- path) echo "$s_dir/$t_rpath" ;;
- id) echo "$s_id$t_rpath" ;;
- esac
- done
- }
-
- straverse() {
- #
- # Traverse back from test dir $1 and print its suite dir
- #
- local tdir=$1
- local dir
- dir=$(readlink -f "$tdir")
- while true; do
- test -d "$dir/.jats" && echo "$dir" && return 0
- test "$dir" == "/" && return 1
- dir=${dir%/*}; test -n "$dir" || dir=/
- done
- }
-
- main() {
- local FindDirs=()
- local Fmt=path
- while true; do case $1 in
- -f) Fmt=$2; shift 2 || usage -w "missing FMT" ;;
- -*) usage -w "unknown argument: $1" ;;
- *) break ;;
- esac done
- FindDirs=("$@")
- case $Fmt in
- id|path) : ;;
- *) usage -w "unknown FMT: $Fmt" ;;
- esac
- debug -v FindDirs Fmt
- discover | grep .
- }
-
- main "$@"
|