Browse Source

Rewrite broken parts of test discovery and identification

There's no way this would have worked properly; I don't know what I was
thinking of.
Alois Mahdal 6 years ago
parent
commit
7a2f35b2eb
2 changed files with 35 additions and 20 deletions
  1. 4
    1
      src/libexec/jattool-runtest
  2. 31
    19
      src/libexec/jattool-tfind

+ 4
- 1
src/libexec/jattool-runtest View File

75
             ;;
75
             ;;
76
         */*)
76
         */*)
77
             TestHome=$1
77
             TestHome=$1
78
-            TestId=$(jattool tfind) || die "could not locate test: $TestId"
78
+            TestId=$(jattool tfind -f jats "$TestHome") || {
79
+                warn "could not find test id, using pathname: $TestHome"
80
+                TestId="jats://_jats_no_suite_/$TestHome"
81
+            }
79
             ;;
82
             ;;
80
     esac
83
     esac
81
     test -f "$TestHome/test" \
84
     test -f "$TestHome/test" \

+ 31
- 19
src/libexec/jattool-tfind View File

17
     #
17
     #
18
     # Find tests under dirs ${FindDirs[@]}
18
     # Find tests under dirs ${FindDirs[@]}
19
     #
19
     #
20
-    local SuiteDir  # suite root dir
21
-    local TRPath    # relative path to test directory within $SuiteDir
22
-    local SuiteId   # suite's jats: id
23
-    jattool sfind -f path "${FindDirs[@]}" \
24
-      | while read -r SuiteDir; do
25
-            SuiteId=$(jattool sfind "$SuiteDir")
26
-            debug -v SuiteDir SuiteId
27
-            pushd "$SuiteDir">/dev/null
28
-                find . -type f -name test -printf '%P\n' \
29
-                  | sed 's:/test::' \
30
-                  | while read -r TRPath; do
31
-                        case $Fmt in
32
-                            path) echo "$SuiteDir/$TRPath" ;;
33
-                            jats) echo "$SuiteId/$TRPath" ;;
34
-                        esac
35
-                        debug -v TRPath
36
-                    done
37
-            popd >/dev/null
20
+    local s_dir  # suite root dir
21
+    local t_cand     # possible test path
22
+    local t_apath    # absolute path to test directory
23
+    local t_rpath    # relative path to test directory within $s_dir
24
+    local s_id   # suite's jats: id
25
+    find "${FindDirs[@]}" -name test \
26
+      | while read -r t_cand; do
27
+            s_dir=$(straverse "$t_cand") || continue
28
+            t_apath=$(dirname "$(readlink -f "$t_cand")")
29
+            t_rpath=${t_apath#$s_dir/}
30
+            s_id=$(jattool sfind -f jats "$s_dir")
31
+            debug -v s_dir s_id t_apath t_rpath
32
+            case $Fmt in
33
+                path) echo "$s_dir/$t_rpath" ;;
34
+                jats) echo "$s_id/$t_rpath" ;;
35
+            esac
38
         done
36
         done
39
 }
37
 }
40
 
38
 
39
+straverse() {
40
+    #
41
+    # Traverse back from test dir $1 and print its suite dir
42
+    #
43
+    local tdir=$1
44
+    local dir
45
+    dir=$(readlink -f "$tdir")
46
+    while true; do
47
+        test -d "$dir/.jats" && echo "$dir" && return 0
48
+        test "$dir" == "/" && return 1
49
+        dir=${dir%/*}; test -n "$dir" || dir=/
50
+    done
51
+}
52
+
41
 main() {
53
 main() {
42
     local FindDirs=()
54
     local FindDirs=()
43
     local Fmt=path
55
     local Fmt=path
52
         *) usage -w "unknown FMT: $Fmt" ;;
64
         *) usage -w "unknown FMT: $Fmt" ;;
53
     esac
65
     esac
54
     debug -v FindDirs Fmt
66
     debug -v FindDirs Fmt
55
-    discover
67
+    discover | grep .
56
 }
68
 }
57
 
69
 
58
 main "$@"
70
 main "$@"