123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #!/bin/bash
- #shellcheck disable=SC1090
-
- . "$(sfpath)" || exit 3
-
- shellfu import pretty
-
- usage() {
- mkusage "$@" "[options] BODY" \
- -- \
- "Discover test in suite located at PATH" \
- -o \
- "-f FMT Print test name in format FMT. 'id' or 'path'." \
- -- \
- "Test body should consist of asserts and/or phases documented" \
- "in jat.sh Shellfu module; use \`sfdoc jat\` to access its" \
- "documentation."
- }
-
- JATS__COMPAT=0.0
-
- sprop() {
- #
- # Get property $1 of suite at $SuiteDir
- #
- local pname=$1
- local pvalue
- local dvalue
- local fpath
- case $SuiteDir in
- .) fpath=.jats/$pname ;;
- *) fpath=$SuiteDir/.jats/$pname ;;
- esac
- case $pname in
- domain) dvalue="jats.example.org" ;;
- ns) dvalue="anonns" ;;
- sut_nicename) dvalue=$(sprop sut_pname) ;;
- sut_pname) dvalue="anonsut" ;;
- sut_url) dvalue="https://example.org/anonsut" ;;
- url) dvalue="https://$(sprop domain)/$(sprop ns)" ;;
- format) : ;;
- *) warn "unknown property: $pname"; return 2 ;;
- esac
- pvalue=$(cat "$fpath" 2>/dev/null)
- debug -v pname dvalue pvalue
- if test -n "$pvalue"; then
- echo "$pvalue"
- return 0
- elif test "$pname" == "format"; then
- warn "missing mandatory property: $fpath"
- return 3
- else
- echo "$dvalue"
- fi
- }
-
- discover() {
- #
- # Find tests under dirs ${FindDirs[@]}
- #
- local SuiteDir # each suite root dir
- local SuiteFmt # suite format version
- find "${FindDirs[@]}" -type d -path '*/.jats' \
- | sed 's:/\.jats::' \
- | while read -r SuiteDir; do
- debug -v SuiteDir
- SuiteFmt=$(sprop format) || continue
- debug -v SuiteFmt
- test "$SuiteFmt" == "$JATS__COMPAT" || continue
- SuiteDomain=$(sprop domain)
- SuiteNs=$(sprop ns)
- SuiteSutPname=$(sprop sut_pname)
- case $Fmt in
- id)
- echo -n "jats://$SuiteDomain/$SuiteNs"
- test -n "$SuiteSutPname" && echo -n "/$SuiteSutPname"
- echo //
- ;;
- path)
- echo "$SuiteDir"
- ;;
- esac
- done
- }
-
- main() {
- local SuiteDir
- 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|version) : ;;
- *) usage -w "unknown FMT: $Fmt" ;;
- esac
- debug -v FindDirs Fmt
- discover
- }
-
- main "$@"
|