Browse Source

Update TFKit to v0.0.14

Alois Mahdal 7 years ago
parent
commit
24e7dc5fa5
4 changed files with 104 additions and 82 deletions
  1. 43
    14
      utils/tfkit/doc/README.md
  2. 0
    25
      utils/tfkit/include/common.sh
  3. 27
    34
      utils/tfkit/include/harness.sh
  4. 34
    9
      utils/tfkit/runtests

+ 43
- 14
utils/tfkit/doc/README.md View File

@@ -24,7 +24,7 @@ The harness, though, assumes that:
24 24
  *  basename of this directory becomes the name of the test,
25 25
 
26 26
  *  and return code from running the executable is reported
27
-    as result of the test, according to "Exit status" chapter below.
27
+    as result of the test, according to "Exit status" section below.
28 28
 
29 29
 
30 30
 Naming
@@ -96,7 +96,7 @@ Framework
96 96
 
97 97
 This part is not intended to be used in tests, but rather contains
98 98
 functions that help govern test discovery, preparation and execution as
99
-is described in previous chapters.  Feel free to poke around, of course.
99
+is described in previous sections.  Feel free to poke around, of course.
100 100
 
101 101
 
102 102
 ### subtest.sh ###
@@ -125,6 +125,7 @@ The minimal *TF_RUN* with two subtests could look like this:
125 125
         case $1 in
126 126
             test1)  myprog foo ;;
127 127
             test2)  myprog bar ;;
128
+            test3)  myprog baz ;;
128 129
         esac
129 130
     }
130 131
 
@@ -257,7 +258,7 @@ As you may have noticed, there are two ways how to skip a test:
257 258
 return prematurely with `TF_ES_BAILOUT`, or suppress enumeration in
258 259
 `tf_enum_subtests`.  The problem is that the latter does not do anything
259 260
 to inform upper in the stack that a test has been skipped, which seems to
260
-break the principle described in the previous chapters.
261
+break the principle described in previous sections.
261 262
 
262 263
 Don't confuse these mechanisms, though. Each is supposed to be used
263 264
 for distinct purpose.  Compare: by using the `tf_enum_subtests` you are
@@ -271,19 +272,47 @@ A few common cases if that helps you:
271 272
     carried out (e.g. an external resource is not available, or
272 273
     something outside the SUT is broken), use `TF_ES_BAILOUT`.
273 274
 
274
- *  If you want to disable the test because for some long-term condition,
275
-    e.g. a known bug outside SUT but preventing execution of the test
276
-    is not fixed, use `tf_enum_subtests`.
277
-
278
- *  If you want to filter out some sub-tests to only for some platforms,
279
-    e.g. 64-bit architecture, (IOW, you can safely check that a
280
-    sub-test would be totally pointless if run on this box), use
281
-    `tf_enum_subtests`.
275
+        tf_enum_subtests() {
276
+            echo test1
277
+            echo test2
278
+            echo test3
279
+        }
280
+
281
+        tf_do_subtest() {
282
+            case $1 in
283
+                test1) do_stuff  ;;
284
+                test2) do_other_stuff ;;
285
+                test3) curl -s http://www.example.com/ >file \
286
+                        || return $TF_ES_BAILOUT
287
+                       do_stuff_with file ;;
288
+            esac
289
+        }
290
+
291
+ *  If you want to filter out some sub-tests for some platforms, e.g. a
292
+    test for only 64-bit architectures, or a test only for Mac OS (IOW,
293
+    you can safely say that running this sub-test would be totally
294
+    pointless on this box), use `tf_enum_subtests`--just omit this test
295
+    from enumeration.
296
+
297
+        tf_enum_subtests() {
298
+            echo test1
299
+            echo test2
300
+            if this_is_macos_x; then
301
+                echo test3
302
+            fi
303
+        }
282 304
 
283 305
  *  If you want to disable (comment out test) that you might not have
284 306
     implemented yet or is broken (and for some reason you still want
285
-    it to haunt the test code), use `tf_enum_subtests` and properly
286
-    comment the reasons in code.
307
+    it to haunt the test code) or something else outside SUT is broken
308
+    and prevents you from running the test, use `tf_enum_subtests` and
309
+    properly comment the reasons in code.
310
+
311
+        tf_enum_subtests() {
312
+            echo test1
313
+            echo test2
314
+        #   echo test3      #FIXME: implement after bz1234
315
+        }
287 316
 
288 317
  *  If in doubt, use `TF_ES_BAILOUT`.
289 318
 
@@ -313,7 +342,7 @@ important.  Follow me as I try to explain:
313 342
     by the script, albeit exiting "in a hurry"--without proper clean up.
314 343
 
315 344
 Unfortunately there will be cases like above but with the error code less
316
-than four.   Example is a bash script syntax error, which returns 2, or
345
+than four.   Example is a Bash script syntax error, which returns 2, or
317 346
 Python exception which returns 1.  Yes, in such cases the information
318 347
 conveyed by the exit status is wrong and you should do everything to
319 348
 avoid it.

+ 0
- 25
utils/tfkit/include/common.sh View File

@@ -7,31 +7,6 @@ TF_ES_BAILOUT=2
7 7
 TF_ES_ERROR=3
8 8
 TF_ES_PANIC=4
9 9
 
10
-#
11
-# Option to turn on/off verbosity
12
-#
13
-TF_VERBOSE=${TF_VERBOSE:-true}
14
-
15
-#
16
-# Option to turn on/off debug mode
17
-#
18
-TF_DEBUG=${TF_DEBUG:-false}
19
-
20
-#
21
-# Regex to filter test names to run
22
-#
23
-TF_FILTER_TEST="${TF_FILTER_TEST:-.*}"
24
-
25
-#
26
-# Regex to filter subtest names to run
27
-#
28
-TF_FILTER_SUBTEST="${TF_FILTER_SUBTEST:-.*}"
29
-
30
-#
31
-# Enable color?
32
-#
33
-TF_COLOR=${TF_COLOR:-true}
34
-
35 10
 #
36 11
 # Color definition variables
37 12
 #

+ 27
- 34
utils/tfkit/include/harness.sh View File

@@ -4,11 +4,6 @@
4 4
 
5 5
 . "$TF_DIR/include/common.sh"
6 6
 
7
-#
8
-# Default path to header generator
9
-#
10
-__TF_HDRCMD="$TF_SUITE/TF_HEADER"
11
-
12 7
 
13 8
 __tf_collect_if_needed() {
14 9
     #
@@ -37,39 +32,36 @@ __tf_collect_if_needed() {
37 32
     cp -r "$tmpdir"/* "$artifact_dir/$stamp"
38 33
 }
39 34
 
40
-__tf_default_header() {
41
-    #
42
-    # Create default header
43
-    #
44
-    echo "hint = Add $__TF_HDRCMD executable for own header."
45
-    echo "hint = It should output 'key = value' pairs about"
46
-    echo "hint = your SUT ('version' at least')."
47
-}
48
-
49 35
 __tf_header() {
50 36
     #
51 37
     # create header to add to output before test
52 38
     #
53
-    local field
54
-    local hdrcmd="$__TF_HDRCMD"
55
-    test -x "$hdrcmd" || hdrcmd="__tf_default_header"
56
-    tf_think "#"
57
-    tf_think "# [tfkit.sut]"
58
-    tf_think "#"
59
-    $hdrcmd \
60
-      | while read field;
61
-        do
62
-            test -n "$field" || break
63
-            tf_think "#     $field"
64
-        done
65
-    tf_think "#"
66
-    tf_think "# [tfkit.run]"
39
+    local hdrline                       # each line from generator
40
+    local hdrgen="$TF_SUITE/TF_HEADER"  # header generator script
67 41
     tf_think "#"
68
-    tf_think "#     start_time = $(date -Iseconds)"
69
-    test "$TF_FILTER_TEST" = '.*' \
70
-     || tf_think "#     TF_FILTER_TEST = $TF_FILTER_TEST"
71
-    test "$TF_FILTER_SUBTEST" = '.*' \
72
-     || tf_think "#     TF_FILTER_SUBTEST = $TF_FILTER_SUBTEST"
42
+    tf_think "# ---"
43
+    tf_think "# tfkit:"
44
+    if test -x "$hdrgen";
45
+    then
46
+        tf_think "#     sut:"
47
+        $hdrgen \
48
+          | while IFS= read -r hdrline;
49
+            do
50
+                test -n "$hdrline" || break
51
+                tf_think "#         $hdrline"
52
+            done
53
+    else
54
+        tf_think "#     hint: >"
55
+        tf_think "#         Add $hdrgen executable for own header."
56
+        tf_think "#         It should output YAML (\"key: value\" pairs) about"
57
+        tf_think "#         your SUT ('version' at least')."
58
+    fi
59
+    tf_think "#     run:"
60
+    tf_think "#         start_time: $(date -Iseconds)"
61
+    test -n "$TF_FILTER_TEST" \
62
+     && tf_think "#         TF_FILTER_TEST: $TF_FILTER_TEST"
63
+    test -n "$TF_FILTER_SUBTEST" \
64
+     && tf_think "#         TF_FILTER_SUBTEST: $TF_FILTER_SUBTEST"
73 65
     tf_think "#"
74 66
     tf_think ""
75 67
 }
@@ -100,7 +92,8 @@ tf_run_tests() {
100 92
     local tes=0         # test result
101 93
     local stamp=""      # test stamp to use as artifact name
102 94
     local tf_dir tf_suite   # to keep absolute paths for TF_RUN
103
-    local artifact_dir="$(readlink -f "$TF_ARTIFACTS")"
95
+    local artifact_dir  # where to keep artifacts
96
+    artifact_dir="$(readlink -f "$TF_ARTIFACTS")"
104 97
     __tf_header
105 98
     tf_debug "TF_VERSION='$TF_VERSION'"
106 99
     tf_dir="$(readlink -f "$TF_DIR")"

+ 34
- 9
utils/tfkit/runtests View File

@@ -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.11"
5
+TF_VERSION="0.0.14"
6 6
 
7 7
 die() {
8 8
     echo "$@" && exit 9
@@ -20,28 +20,53 @@ version() {
20 20
 
21 21
 LC_ALL=C
22 22
 
23
+#
24
+# Artifact directory path
25
+#
26
+TF_ARTIFACTS="${TF_ARTIFACTS:-artifacts}"
27
+
28
+#
29
+# Artifact collection mode
30
+#
31
+# 'always' to always collect, 'never` to never collect and 'auto'
32
+# to collect only on failed tests.
33
+#
34
+TF_COLLECT="${TF_COLLECT:-auto}"
35
+
36
+#
37
+# Enable color?
38
+#
39
+TF_COLOR=${TF_COLOR:-true}
40
+
41
+#
42
+# Turn on debug mode?
43
+#
44
+TF_DEBUG="${TF_DEBUG:-false}"
45
+
23 46
 #
24 47
 # Location of own directory
25 48
 #
26 49
 TF_DIR=${TF_DIR:-$(dirname "$0")}
27 50
 
28 51
 #
29
-# Location of test suite
52
+# Regex (BRE) to filter subtests based on name
30 53
 #
31
-TF_SUITE="${TF_SUITE:-tests}"
54
+TF_FILTER_SUBTEST=${TF_FILTER_SUBTEST:-}
32 55
 
33 56
 #
34
-# Artifact directory path
57
+# Regex (BRE) to filter tests based on name
35 58
 #
36
-TF_ARTIFACTS="${TF_ARTIFACTS:-artifacts}"
59
+TF_FILTER_TEST=${TF_FILTER_TEST:-}
37 60
 
38 61
 #
39
-# Artifact collection mode
62
+# Location of test suite
40 63
 #
41
-# 'always' to always collect, 'never` to never collect and 'auto'
42
-# to collect only on failed tests.
64
+TF_SUITE="${TF_SUITE:-tests}"
65
+
43 66
 #
44
-TF_COLLECT="${TF_COLLECT:-auto}"
67
+# Turn on verbosity?
68
+#
69
+TF_VERBOSE=${TF_VERBOSE:-true}
45 70
 
46 71
 while true; do case "$1" in
47 72
     -c|--collect)           TF_COLLECT=always;          shift ;;