#!/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. 'jats' 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 jats) 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 jats|path) : ;; *) usage -w "unknown FMT: $Fmt" ;; esac debug -v FindDirs Fmt discover } main "$@"