tests: refactor mechanics of testing in a sub test-lib
This will allow us to test the test framework more thoroughly without disrupting the top-level test metrics. Signed-off-by: Adam Spiers <git@adamspiers.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Adam Spiers committed
Dec 16, 2012 at 18:28 UTC
565b6fa87bb0554eb7f1b8ec004df93e55d177a9
1 file changed
+40
-45
t/t0000-basic.sh
+40
-45
@@ -55,39 +55,53 @@ test_expect_failure 'pretend we have a known breakage' '
55
false
56
'
57
58
-test_expect_success 'pretend we have fixed a known breakage (run in sub test-lib)' "
59
- mkdir passing-todo &&
60
- (cd passing-todo &&
61
- cat >passing-todo.sh <<-EOF &&
62
- #!$SHELL_PATH
63
-
64
- test_description='A passing TODO test
65
-
66
- This is run in a sub test-lib so that we do not get incorrect
67
- passing metrics
68
- '
69
-
70
- # Point to the t/test-lib.sh, which isn't in ../ as usual
71
- TEST_DIRECTORY=\"$TEST_DIRECTORY\"
72
- . \"\$TEST_DIRECTORY\"/test-lib.sh
58
+run_sub_test_lib_test () {
59
+ name="$1" descr="$2" # stdin is the body of the test code
60
+ mkdir "$name" &&
61
+ (
62
+ cd "$name" &&
63
+ cat >"$name.sh" <<-EOF &&
64
+ #!$SHELL_PATH
65
+
66
+ test_description='$descr (run in sub test-lib)
67
+
68
+ This is run in a sub test-lib so that we do not get incorrect
69
+ passing metrics
70
+ '
71
+
72
+ # Point to the t/test-lib.sh, which isn't in ../ as usual
73
+ . "\$TEST_DIRECTORY"/test-lib.sh
74
+ EOF
75
+ cat >>"$name.sh" &&
76
+ chmod +x "$name.sh" &&
77
+ export TEST_DIRECTORY &&
78
+ ./"$name.sh" >out 2>err
79
+ )
80
+}
81
74
- test_expect_failure 'pretend we have fixed a known breakage' '
75
- :
76
- '
82
+check_sub_test_lib_test () {
83
+ name="$1" # stdin is the expected output from the test
84
+ (
85
+ cd "$name" &&
86
+ ! test -s err &&
87
+ sed -e 's/^> //' -e 's/Z$//' >expect &&
88
+ test_cmp expect out
89
+ )
90
+}
91
92
+test_expect_success 'pretend we have fixed a known breakage' "
93
+ run_sub_test_lib_test passing-todo 'A passing TODO test' <<-\\EOF &&
94
+ test_expect_failure 'pretend we have fixed a known breakage' 'true'
95
test_done
96
EOF
80
- chmod +x passing-todo.sh &&
81
- ./passing-todo.sh >out 2>err &&
82
- ! test -s err &&
83
- sed -e 's/^> //' >expect <<-\\EOF &&
97
+ check_sub_test_lib_test passing-todo <<-\\EOF
98
> ok 1 - pretend we have fixed a known breakage # TODO known breakage
99
> # fixed 1 known breakage(s)
100
> # passed all 1 test(s)
101
> 1..1
102
EOF
89
- test_cmp expect out)
103
"
104
+
105
test_set_prereq HAVEIT
106
haveit=no
107
test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
@@ -137,19 +151,8 @@ then
151
fi
152
153
test_expect_success 'tests clean up even on failures' "
140
- mkdir failing-cleanup &&
141
- (
142
- cd failing-cleanup &&
143
-
144
- cat >failing-cleanup.sh <<-EOF &&
145
- #!$SHELL_PATH
146
-
147
- test_description='Failing tests with cleanup commands'
148
-
149
- # Point to the t/test-lib.sh, which isn't in ../ as usual
150
- TEST_DIRECTORY=\"$TEST_DIRECTORY\"
151
- . \"\$TEST_DIRECTORY\"/test-lib.sh
152
-
154
+ test_must_fail run_sub_test_lib_test \
155
+ failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF &&
156
test_expect_success 'tests clean up even after a failure' '
157
touch clean-after-failure &&
158
test_when_finished rm clean-after-failure &&
@@ -159,14 +162,8 @@ test_expect_success 'tests clean up even on failures' "
162
test_when_finished \"(exit 2)\"
163
'
164
test_done
162
-
165
EOF
164
-
165
- chmod +x failing-cleanup.sh &&
166
- test_must_fail ./failing-cleanup.sh >out 2>err &&
167
- ! test -s err &&
168
- ! test -f \"trash directory.failing-cleanup/clean-after-failure\" &&
169
- sed -e 's/Z$//' -e 's/^> //' >expect <<-\\EOF &&
166
+ check_sub_test_lib_test failing-cleanup <<-\\EOF
167
> not ok 1 - tests clean up even after a failure
168
> # Z
169
> # touch clean-after-failure &&
@@ -180,8 +177,6 @@ test_expect_success 'tests clean up even on failures' "
177
> # failed 2 among 2 test(s)
178
> 1..2
179
EOF
183
- test_cmp expect out
184
- )
180
"
181
182
################################################################