Bladeren bron

Update TFKit to v0.0.14

Alois Mahdal 7 jaren geleden
bovenliggende
commit
628fdc3f55
3 gewijzigde bestanden met toevoegingen van 71 en 49 verwijderingen
  1. 43
    14
      utils/tfkit/doc/README.md
  2. 27
    34
      utils/tfkit/include/harness.sh
  3. 1
    1
      utils/tfkit/runtests

+ 43
- 14
utils/tfkit/doc/README.md Bestand weergeven

@@ -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.

+ 27
- 34
utils/tfkit/include/harness.sh Bestand weergeven

@@ -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")"

+ 1
- 1
utils/tfkit/runtests Bestand weergeven

@@ -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.12"
5
+TF_VERSION="0.0.14"
6 6
 
7 7
 die() {
8 8
     echo "$@" && exit 9