Explorar el Código

Update TFKit to version 0.0.10

Alois Mahdal hace 8 años
padre
commit
c98b368cd2
Se han modificado 3 ficheros con 65 adiciones y 34 borrados
  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 Ver fichero

106
 
106
 
107
 In order to make use of the subtests functionality, you will need to
107
 In order to make use of the subtests functionality, you will need to
108
 define two functions yourself:  `tf_enum_subtests` to enumerate names of
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
 The minimal *TF_RUN* with two subtests could look like this:
112
 The minimal *TF_RUN* with two subtests could look like this:
113
 
113
 
121
         something && echo test3
121
         something && echo test3
122
     }
122
     }
123
 
123
 
124
-    tf_name2cmd() {
124
+    tf_do_subtest() {
125
         case $1 in
125
         case $1 in
126
-            test1)  echo myprog foo ;;
127
-            test2)  echo myprog bar ;;
126
+            test1)  myprog foo ;;
127
+            test2)  myprog bar ;;
128
         esac
128
         esac
129
     }
129
     }
130
 
130
 
133
 At the end, `tf_do_subtests` acts as a launcher of the actual test.
133
 At the end, `tf_do_subtests` acts as a launcher of the actual test.
134
 In short, it will
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
 Note that subtest names need to be single words (`[a-zA-Z0-9_]`).
146
 Note that subtest names need to be single words (`[a-zA-Z0-9_]`).
147
 
147
 

+ 31
- 19
utils/tfkit/include/subtest.sh Ver fichero

7
     # Stub: enumerate subtests
7
     # Stub: enumerate subtests
8
     #
8
     #
9
     tf_warn "implement tf_enum_subtests()!"
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
     # Run single subtest inc. setup/cleanup if present
23
     # Run single subtest inc. setup/cleanup if present
24
     #
24
     #
25
     local subtname="$1"     # this subtest name
25
     local subtname="$1"     # this subtest name
26
     local ses=0             # subtest exit status
26
     local ses=0             # subtest exit status
27
-    local tcmd=""           # test command
28
     local setup=true        # setup command
27
     local setup=true        # setup command
29
     local cleanup=true      # cleanup command
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
     if $setup;
45
     if $setup;
33
     then
46
     then
34
-        tcmd="$(tf_name2cmd "$subtname")"
35
-        tf_debug "tcmd='$tcmd'"
36
-        $tcmd; ses=$?
47
+        tf_do_subtest "$subtname"; ses=$?
37
     else
48
     else
38
         tf_warn "setup phase failed, skipping: $subtname"
49
         tf_warn "setup phase failed, skipping: $subtname"
39
         ses=$TF_ES_ERROR
50
         ses=$TF_ES_ERROR
43
         tf_warn "cleanup phase failed: $subtname"
54
         tf_warn "cleanup phase failed: $subtname"
44
         ses=$TF_ES_PANIC
55
         ses=$TF_ES_PANIC
45
     fi
56
     fi
46
-    return $ses
57
+    return "$ses"
47
 }
58
 }
48
 
59
 
49
 tf_do_subtests() {
60
 tf_do_subtests() {
55
     local tes=""            # one subtest exit status
66
     local tes=""            # one subtest exit status
56
     local enumd=TF_ENUMERATED_SUBTESTS
67
     local enumd=TF_ENUMERATED_SUBTESTS
57
     local fltrd=TF_FILTERED_SUBTESTS
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
     grep -e "$TF_FILTER_SUBTEST" $enumd > $fltrd
71
     grep -e "$TF_FILTER_SUBTEST" $enumd > $fltrd
61
     test -s $fltrd  || tf_debug "TF_FILTER_SUBTEST ate everything: $TF_FILTER_SUBTEST"
72
     test -s $fltrd  || tf_debug "TF_FILTER_SUBTEST ate everything: $TF_FILTER_SUBTEST"
73
+
62
     for subtname in $(<$fltrd);
74
     for subtname in $(<$fltrd);
63
     do
75
     do
64
         export TF_SUBTNAME=$subtname
76
         export TF_SUBTNAME=$subtname
65
         tf_think "::: $TF_TNAME::$TF_SUBTNAME"
77
         tf_think "::: $TF_TNAME::$TF_SUBTNAME"
66
-        tf_do_subtest "$TF_SUBTNAME";
78
+        _tf_do_subtest "$TF_SUBTNAME";
67
         tes=$?
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
     done
83
     done
72
     return $es
84
     return $es
73
 }
85
 }

+ 21
- 2
utils/tfkit/runtests Ver fichero

2
 # tfkit - Shellfu's movable test framework
2
 # tfkit - Shellfu's movable test framework
3
 # See LICENSE file for copyright and license details.
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
 die() {
7
 die() {
8
     echo "$@" && exit 9
8
     echo "$@" && exit 9
19
 }
19
 }
20
 
20
 
21
 LC_ALL=C
21
 LC_ALL=C
22
+
23
+#
24
+# Location of own directory
25
+#
22
 TF_DIR=${TF_DIR:-$(dirname "$0")}
26
 TF_DIR=${TF_DIR:-$(dirname "$0")}
27
+
28
+#
29
+# Location of test suite
30
+#
23
 TF_SUITE="${TF_SUITE:-tests}"
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
 TF_COLLECT="${TF_COLLECT:-auto}"
44
 TF_COLLECT="${TF_COLLECT:-auto}"
26
 
45
 
27
 while true; do case "$1" in
46
 while true; do case "$1" in