Browse Source

Update TFKit to v0.0.16

Alois Mahdal 6 years ago
parent
commit
a77a760518

+ 16
- 6
utils/tfkit/doc/README.md View File

1
-Tests
1
+TFKit
2
 =====
2
 =====
3
 
3
 
4
-Running tests is handled by tfkit/runtests:
5
 
4
 
6
-    $ tfkit/runtest [filter]
5
+Installation
6
+------------
7
 
7
 
8
-*filter* is a regular expression to be applied to sub-test name, running
9
-only the matching ones.  See below for details.
8
+The easiest way is to embed TFKit within your repo, ie. clone TFKit and
9
+install it using:
10
+
11
+    make install DESTDIR=/path/to/your/repo
12
+
13
+Now you can run your test suite using *runtests* binary:
14
+
15
+    $ cd /path/to/your/repo
16
+    $ utils/tfkit/runtest
17
+
18
+Note that the above probably won't return any useful results as you still
19
+don't have any tests.
10
 
20
 
11
 
21
 
12
 Writing tests
22
 Writing tests
49
 
59
 
50
 Note that before running, the whole test directory is automatically
60
 Note that before running, the whole test directory is automatically
51
 copied to a temporary location (one per test), and should the test fail,
61
 copied to a temporary location (one per test), and should the test fail,
52
-copied back as a debugging artifact.  For this reason, *do not store
62
+copied back as a debugging relic.  For this reason, *do not store
53
 huge amounts of data here*.  If you really need huge data, consider
63
 huge amounts of data here*.  If you really need huge data, consider
54
 obtaining it (and throwing it away) within runtime of *TF_RUN*.
64
 obtaining it (and throwing it away) within runtime of *TF_RUN*.
55
 
65
 

+ 37
- 0
utils/tfkit/doc/templates/simple/TF_RUN View File

1
+#!/bin/bash
2
+#shellcheck disable=SC1090
3
+
4
+. "$TF_DIR/include/subtest.sh"
5
+. "$TF_DIR/include/tools.sh"
6
+
7
+tf_enum_subtests() {
8
+    echo one
9
+    echo two
10
+    echo three
11
+}
12
+
13
+my_sut() {
14
+    local word=$1
15
+    declare -A map
16
+    map[one]=1
17
+    map[two]=2
18
+    map[three]=33
19
+    echo "${map[$word]}"
20
+}
21
+
22
+mkoracle() {
23
+    mkdir -p oracle
24
+    case $subtest in
25
+        one)    echo 1 ;;
26
+        two)    echo 2 ;;
27
+        three)  echo 3 ;;
28
+    esac > "oracle/$subtest.stdout"
29
+}
30
+
31
+tf_do_subtest() {
32
+    local subtest=$1
33
+    mkoracle
34
+    tf_testflt -n "$subtest" -O "oracle/$subtest.stdout" "my_sut $subtest"
35
+}
36
+
37
+tf_do_subtests

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

29
 TF_COLOR_NONE="\033[1;0m"
29
 TF_COLOR_NONE="\033[1;0m"
30
 
30
 
31
 
31
 
32
+_tf__is_word() {
33
+    #
34
+    # Check if $1 contains only alphanumeric chars or _
35
+    #
36
+    local tainted=$1    # "dirty" version
37
+    local clean         # clean version
38
+    clean=$(tr -c -d '_[:alnum:]' <<< "$tainted")
39
+    test "$tainted" = "$clean"
40
+}
41
+
32
 tf_exit_ok() {
42
 tf_exit_ok() {
33
     #
43
     #
34
     # Exit with OK status
44
     # Exit with OK status
82
     done
92
     done
83
 }
93
 }
84
 
94
 
95
+tf_debugv() {
96
+    #
97
+    # Emit debug message showing value of each named variable
98
+    #
99
+    local varname
100
+    local declare_str
101
+    for varname in "$@";
102
+    do
103
+        if ! _tf__is_word "$varname";
104
+        then
105
+            tf_warn "tf_debugv: unsafe value skipped: $varname";
106
+            continue
107
+        fi
108
+        if declare_str=$(declare -p "$varname" 2>/dev/null);
109
+        then
110
+            tf_debug "${declare_str#declare ?? }"
111
+        else
112
+            tf_debug "$varname #Unset"
113
+        fi
114
+    done
115
+}
116
+
85
 tf_think() {
117
 tf_think() {
86
     #
118
     #
87
     # Emit status/progress message
119
     # Emit status/progress message

+ 13
- 12
utils/tfkit/include/harness.sh View File

7
 
7
 
8
 __tf_collect_if_needed() {
8
 __tf_collect_if_needed() {
9
     #
9
     #
10
-    # Collect artifact if exit status suggests it
10
+    # Collect relic if exit status suggests it
11
     #
11
     #
12
-    # Use test exit status $1 to help decide if artifacts are
12
+    # Use test exit status $1 to help decide if relics are
13
     # needed, and collect them if so.
13
     # needed, and collect them if so.
14
     #
14
     #
15
     # If TF_COLLECT is set to "always", collect regardless of
15
     # If TF_COLLECT is set to "always", collect regardless of
18
     # or 1 (pass or bailout); in that case do nothing.
18
     # or 1 (pass or bailout); in that case do nothing.
19
     #
19
     #
20
     local tes=$1    # test exit status
20
     local tes=$1    # test exit status
21
-    local will      # should we collect artifacts?
21
+    local will      # should we collect relics?
22
     case "$TF_COLLECT:$tes" in
22
     case "$TF_COLLECT:$tes" in
23
         always:*)   will=true ;;
23
         always:*)   will=true ;;
24
         never:*)    will=false ;;
24
         never:*)    will=false ;;
28
         *)          tf_exit_bailout "bad value of TF_COLLECT: $TF_COLLECT" ;;
28
         *)          tf_exit_bailout "bad value of TF_COLLECT: $TF_COLLECT" ;;
29
     esac
29
     esac
30
     $will || return 0
30
     $will || return 0
31
-    mkdir -p "$artifact_dir/$stamp"
32
-    cp -r "$tmpdir"/* "$artifact_dir/$stamp"
31
+    mkdir -p "$relic_dir/$stamp"
32
+    cp -r "$tmpdir"/* "$relic_dir/$stamp"
33
 }
33
 }
34
 
34
 
35
 __tf_header() {
35
 __tf_header() {
90
     local tmpdir=""     # test temporary dir
90
     local tmpdir=""     # test temporary dir
91
     local tname=""      # test name
91
     local tname=""      # test name
92
     local tes=0         # test result
92
     local tes=0         # test result
93
-    local stamp=""      # test stamp to use as artifact name
94
-    local tf_dir tf_suite   # to keep absolute paths for TF_RUN
95
-    local artifact_dir  # where to keep artifacts
96
-    artifact_dir="$(readlink -f "$TF_ARTIFACTS")"
93
+    local stamp=""      # test stamp to use as relic name
94
+    local tf_dir        # to keep absolute path for TF_RUN
95
+    local relic_dir     # where to keep relics
96
+    relic_dir="$(readlink -f "$TF_RELICS")"
97
     __tf_header
97
     __tf_header
98
     tf_debug "TF_VERSION='$TF_VERSION'"
98
     tf_debug "TF_VERSION='$TF_VERSION'"
99
     tf_dir="$(readlink -f "$TF_DIR")"
99
     tf_dir="$(readlink -f "$TF_DIR")"
100
-    tf_suite="$(readlink -f "$TF_SUITE")"
101
     es=0
100
     es=0
102
     for tname in $(tf_enum_tests | grep -e "$TF_FILTER_TEST");
101
     for tname in $(tf_enum_tests | grep -e "$TF_FILTER_TEST");
103
     do
102
     do
104
         tf_think "... $tname"
103
         tf_think "... $tname"
105
         tmpdir=$(mktemp -d)
104
         tmpdir=$(mktemp -d)
106
-        stamp=$(date "+artifacts-$tname-%Y%m%d-%H%M%S")
105
+        stamp=$(date "+relics-$tname-%Y%m%d-%H%M%S")
107
         cp -r "$TF_SUITE/$tname/"* "$tmpdir"
106
         cp -r "$TF_SUITE/$tname/"* "$tmpdir"
108
         pushd "$tmpdir" >/dev/null
107
         pushd "$tmpdir" >/dev/null
109
-            TF_DIR="$tf_dir" TF_SUITE=$tf_suite TF_TNAME="$tname" \
108
+            TF_DEBUG=$TF_DEBUG TF_VERBOSE=$TF_VERBOSE \
109
+            TF_DIR="$tf_dir" TF_TEST="$tname" \
110
+            TF_FILTER_SUBTEST=$TF_FILTER_SUBTEST \
110
                 ./TF_RUN
111
                 ./TF_RUN
111
             tes=$?
112
             tes=$?
112
             __tf_collect_if_needed $tes
113
             __tf_collect_if_needed $tes

+ 3
- 4
utils/tfkit/include/subtest.sh View File

73
 
73
 
74
     for subtname in $(<$fltrd);
74
     for subtname in $(<$fltrd);
75
     do
75
     do
76
-        export TF_SUBTNAME=$subtname
77
-        tf_think "::: $TF_TNAME::$TF_SUBTNAME"
78
-        _tf_do_subtest "$TF_SUBTNAME";
76
+        tf_think "::: $TF_TEST::$subtname"
77
+        TF_SUBTEST=$subtname _tf_do_subtest "$subtname";
79
         tes=$?
78
         tes=$?
80
         test $tes -gt $es              && es=$tes
79
         test $tes -gt $es              && es=$tes
81
-        test $tes -gt "$TF_ES_OK"      && tf_warn "!!! $TF_TNAME::$TF_SUBTNAME ($tes)"
80
+        test $tes -gt "$TF_ES_OK"      && tf_warn "!!! $TF_TEST::$subtname ($tes)"
82
         test $tes -gt "$TF_ES_BAILOUT" && break
81
         test $tes -gt "$TF_ES_BAILOUT" && break
83
     done
82
     done
84
     return $es
83
     return $es

+ 24
- 27
utils/tfkit/runtests View File

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.14"
5
+TF_VERSION="0.0.16"
6
 
6
 
7
 die() {
7
 die() {
8
     echo "$@" && exit 9
8
     echo "$@" && exit 9
18
     exit 0
18
     exit 0
19
 }
19
 }
20
 
20
 
21
-LC_ALL=C
22
-
23
 #
21
 #
24
-# Artifact directory path
22
+# Relic directory path
25
 #
23
 #
26
-TF_ARTIFACTS="${TF_ARTIFACTS:-artifacts}"
24
+TF_RELICS="${TF_RELICS:-relics}"
27
 
25
 
28
 #
26
 #
29
-# Artifact collection mode
27
+# Relic collection mode
30
 #
28
 #
31
 # 'always' to always collect, 'never` to never collect and 'auto'
29
 # 'always' to always collect, 'never` to never collect and 'auto'
32
 # to collect only on failed tests.
30
 # to collect only on failed tests.
68
 #
66
 #
69
 TF_VERBOSE=${TF_VERBOSE:-true}
67
 TF_VERBOSE=${TF_VERBOSE:-true}
70
 
68
 
71
-while true; do case "$1" in
72
-    -c|--collect)           TF_COLLECT=always;          shift ;;
73
-    -C|--no-collect)        TF_COLLECT=never;           shift ;;
74
-    -d|--debug)             TF_DEBUG=true;              shift ;;
75
-    -p|--prefix)            export PATH="$(readlink -f "$2")/bin:$PATH"
76
-                                                        shift 2 || usage ;;
77
-    -s|--filter-subtest)    TF_FILTER_SUBTEST="$2";     shift 2 || usage ;;
78
-    -t|--filter-test)       TF_FILTER_TEST="$2";        shift 2 || usage ;;
79
-    -v|--verbose)           TF_VERBOSE=true;            shift ;;
80
-    --version-semver)       echo "$TF_VERSION"; exit 0 ;;
81
-    --version)              version ;;
82
-    "") break ;;
83
-    *)  usage ;;
84
-esac done
85
-
86
-export LC_ALL
87
-export TF_DIR TF_SUITE TF_ARTIFACTS
88
-export TF_COLLECT TF_FILTER_SUBTEST TF_FILTER_TEST
89
-export TF_DEBUG TF_VERBOSE
90
-export TF_VERSION
91
 
69
 
92
 . "$TF_DIR/include/harness.sh" \
70
 . "$TF_DIR/include/harness.sh" \
93
  || die "cannot import harness; is TF_DIR set properly?: $TF_DIR"
71
  || die "cannot import harness; is TF_DIR set properly?: $TF_DIR"
94
 
72
 
95
-time tf_run_tests
73
+main() {
74
+    while true; do case "$1" in
75
+        -c|--collect)           TF_COLLECT=always;          shift ;;
76
+        -C|--no-collect)        TF_COLLECT=never;           shift ;;
77
+        -d|--debug)             TF_DEBUG=true;              shift ;;
78
+        -p|--prefix)            export PATH="$(readlink -f "$2")/bin:$PATH"
79
+                                                            shift 2 || usage ;;
80
+        -s|--filter-subtest)    TF_FILTER_SUBTEST="$2";     shift 2 || usage ;;
81
+        -t|--filter-test)       TF_FILTER_TEST="$2";        shift 2 || usage ;;
82
+        -v|--verbose)           TF_VERBOSE=true;            shift ;;
83
+        --version-semver)       echo "$TF_VERSION"; exit 0 ;;
84
+        --version)              version ;;
85
+        "") break ;;
86
+        *)  usage ;;
87
+    esac done
88
+    export LC_ALL=C
89
+    time tf_run_tests
90
+}
91
+
92
+main "$@"