Kaynağa Gözat

Update TFKit to version 0.0.10

Alois Mahdal 8 yıl önce
ebeveyn
işleme
c98b368cd2
3 değiştirilmiş dosya ile 65 ekleme ve 34 silme
  1. 13
    13
      utils/tfkit/doc/README.md
  2. 31
    19
      utils/tfkit/include/subtest.sh
  3. 21
    2
      utils/tfkit/runtests

+ 13
- 13
utils/tfkit/doc/README.md Dosyayı Görüntüle

@@ -106,8 +106,8 @@ in *TF_RUN*.
106 106
 
107 107
 In order to make use of the subtests functionality, you will need to
108 108
 define two functions yourself:  `tf_enum_subtests` to enumerate names of
109
-tests you want to run, and `tf_name2cmd` to translate each name an actual
110
-command that would perform it and return with the the correct exit status.
109
+tests you want to run, and `tf_do_subtest` with actual test
110
+implementation.
111 111
 
112 112
 The minimal *TF_RUN* with two subtests could look like this:
113 113
 
@@ -121,10 +121,10 @@ The minimal *TF_RUN* with two subtests could look like this:
121 121
         something && echo test3
122 122
     }
123 123
 
124
-    tf_name2cmd() {
124
+    tf_do_subtest() {
125 125
         case $1 in
126
-            test1)  echo myprog foo ;;
127
-            test2)  echo myprog bar ;;
126
+            test1)  myprog foo ;;
127
+            test2)  myprog bar ;;
128 128
         esac
129 129
     }
130 130
 
@@ -133,15 +133,15 @@ The minimal *TF_RUN* with two subtests could look like this:
133 133
 At the end, `tf_do_subtests` acts as a launcher of the actual test.
134 134
 In short, it will
135 135
 
136
- *  take each enumerated subtest from `tf_enum_subtests`,
137
- *  source *TF_SETUP*, if such file is found,
138
- *  translate te subtest name to a command,
139
- *  launch the command,
140
- *  source *TF_CLEANUP*, if such file is found,
141
- *  and report "worst" exit status encountered.
136
+ 1. run `tf_enum_subtests`, taking each line as name of a subtest;
137
+    for each subtest:
142 138
 
143
-All but the first and last step is done by `tf_do_subtest`, so in some
144
-cases you may want to re-define this one as well.
139
+     1. source *TF_SETUP*, if such file is found,
140
+     2. launch the `tf_do_subtest()` function with subtest name as
141
+        the only argument,
142
+     3. source *TF_CLEANUP*, if such file is found,
143
+
144
+ 2. and finally, report "worst" exit status encountered.
145 145
 
146 146
 Note that subtest names need to be single words (`[a-zA-Z0-9_]`).
147 147
 

+ 31
- 19
utils/tfkit/include/subtest.sh Dosyayı Görüntüle

@@ -7,33 +7,44 @@ tf_enum_subtests() {
7 7
     # Stub: enumerate subtests
8 8
     #
9 9
     tf_warn "implement tf_enum_subtests()!"
10
-    return $TF_ES_ERROR
10
+    return "$TF_ES_ERROR"
11 11
 }
12 12
 
13
-tf_name2cmd() {
13
+tf_do_subtest() {
14 14
     #
15
-    # Stub: expand test name to test command
15
+    # Stub: perform test named $1
16 16
     #
17
-    tf_warn "implement tf_name2cmd()!"
18
-    return $TF_ES_ERROR
17
+    tf_warn "implement tf_do_subtest()!"
18
+    return "$TF_ES_ERROR"
19 19
 }
20 20
 
21
-tf_do_subtest() {
21
+_tf_do_subtest() {
22 22
     #
23 23
     # Run single subtest inc. setup/cleanup if present
24 24
     #
25 25
     local subtname="$1"     # this subtest name
26 26
     local ses=0             # subtest exit status
27
-    local tcmd=""           # test command
28 27
     local setup=true        # setup command
29 28
     local cleanup=true      # cleanup command
30
-    test -f TF_SETUP   && setup=". TF_SETUP"
31
-    test -f TF_CLEANUP && cleanup=". TF_CLEANUP"
29
+    if test -f TF_SETUP;
30
+    then
31
+        setup=". TF_SETUP"
32
+        bash -n TF_SETUP || {
33
+            tf_warn "synax errors in TF_SETUP, skipping"
34
+            return "$TF_ES_ERROR"
35
+        }
36
+    fi
37
+    if test -f TF_CLEANUP;
38
+    then
39
+        setup=". TF_CLEANUP"
40
+        bash -n TF_CLEANUP || {
41
+            tf_warn "synax errors in TF_CLEANUP, skipping"
42
+            return "$TF_ES_ERROR"
43
+        }
44
+    fi
32 45
     if $setup;
33 46
     then
34
-        tcmd="$(tf_name2cmd "$subtname")"
35
-        tf_debug "tcmd='$tcmd'"
36
-        $tcmd; ses=$?
47
+        tf_do_subtest "$subtname"; ses=$?
37 48
     else
38 49
         tf_warn "setup phase failed, skipping: $subtname"
39 50
         ses=$TF_ES_ERROR
@@ -43,7 +54,7 @@ tf_do_subtest() {
43 54
         tf_warn "cleanup phase failed: $subtname"
44 55
         ses=$TF_ES_PANIC
45 56
     fi
46
-    return $ses
57
+    return "$ses"
47 58
 }
48 59
 
49 60
 tf_do_subtests() {
@@ -55,19 +66,20 @@ tf_do_subtests() {
55 66
     local tes=""            # one subtest exit status
56 67
     local enumd=TF_ENUMERATED_SUBTESTS
57 68
     local fltrd=TF_FILTERED_SUBTESTS
58
-    tf_enum_subtests >$enumd    || { tf_warn "error enumerating subtests"; return $TF_ES_BAILOUT; }
59
-    test -s $enumd              || { tf_warn "no subtests enumerated";     return $TF_ES_BAILOUT; }
69
+    tf_enum_subtests >$enumd    || { tf_warn "error enumerating subtests"; return "$TF_ES_BAILOUT"; }
70
+    test -s $enumd              || { tf_warn "no subtests enumerated";     return "$TF_ES_BAILOUT"; }
60 71
     grep -e "$TF_FILTER_SUBTEST" $enumd > $fltrd
61 72
     test -s $fltrd  || tf_debug "TF_FILTER_SUBTEST ate everything: $TF_FILTER_SUBTEST"
73
+
62 74
     for subtname in $(<$fltrd);
63 75
     do
64 76
         export TF_SUBTNAME=$subtname
65 77
         tf_think "::: $TF_TNAME::$TF_SUBTNAME"
66
-        tf_do_subtest "$TF_SUBTNAME";
78
+        _tf_do_subtest "$TF_SUBTNAME";
67 79
         tes=$?
68
-        test $tes -gt $es            && es=$tes
69
-        test $tes -gt $TF_ES_OK      && tf_warn "!!! $TF_TNAME::$TF_SUBTNAME ($tes)"
70
-        test $tes -gt $TF_ES_BAILOUT && break
80
+        test $tes -gt $es              && es=$tes
81
+        test $tes -gt "$TF_ES_OK"      && tf_warn "!!! $TF_TNAME::$TF_SUBTNAME ($tes)"
82
+        test $tes -gt "$TF_ES_BAILOUT" && break
71 83
     done
72 84
     return $es
73 85
 }

+ 21
- 2
utils/tfkit/runtests Dosyayı Görüntüle

@@ -2,7 +2,7 @@
2 2
 # tfkit - Shellfu's movable test framework
3 3
 # See LICENSE file for copyright and license details.
4 4
 
5
-TF_VERSION="0.0.8"
5
+TF_VERSION="0.0.10"
6 6
 
7 7
 die() {
8 8
     echo "$@" && exit 9
@@ -19,9 +19,28 @@ version() {
19 19
 }
20 20
 
21 21
 LC_ALL=C
22
+
23
+#
24
+# Location of own directory
25
+#
22 26
 TF_DIR=${TF_DIR:-$(dirname "$0")}
27
+
28
+#
29
+# Location of test suite
30
+#
23 31
 TF_SUITE="${TF_SUITE:-tests}"
24
-TF_ARTIFACTS="${TF_ARTIFACTS:-tfkit-artifacts}"
32
+
33
+#
34
+# Artifact directory path
35
+#
36
+TF_ARTIFACTS="${TF_ARTIFACTS:-artifacts}"
37
+
38
+#
39
+# Artifact collection mode
40
+#
41
+# 'always' to always collect, 'never` to never collect and 'auto'
42
+# to collect only on failed tests.
43
+#
25 44
 TF_COLLECT="${TF_COLLECT:-auto}"
26 45
 
27 46
 while true; do case "$1" in