@@ -55,39 +55,53 @@ test_expect_failure 'pretend we have a known breakage' '
55
55
false
56
56
'
57
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
+ }
73
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
+ }
77
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'
78
95
test_done
79
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
84
98
> ok 1 - pretend we have fixed a known breakage # TODO known breakage
85
99
> # fixed 1 known breakage(s)
86
100
> # passed all 1 test(s)
87
101
> 1..1
88
102
EOF
89
- test_cmp expect out)
90
103
"
104
+
91
105
test_set_prereq HAVEIT
92
106
haveit=no
93
107
test_expect_success HAVEIT ' test runs if prerequisite is satisfied' '
@@ -137,19 +151,8 @@ then
137
151
fi
138
152
139
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 &&
153
156
test_expect_success 'tests clean up even after a failure' '
154
157
touch clean-after-failure &&
155
158
test_when_finished rm clean-after-failure &&
@@ -159,14 +162,8 @@ test_expect_success 'tests clean up even on failures' "
159
162
test_when_finished \" (exit 2)\"
160
163
'
161
164
test_done
162
-
163
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
170
167
> not ok 1 - tests clean up even after a failure
171
168
> # Z
172
169
> # touch clean-after-failure &&
@@ -180,8 +177,6 @@ test_expect_success 'tests clean up even on failures' "
180
177
> # failed 2 among 2 test(s)
181
178
> 1..2
182
179
EOF
183
- test_cmp expect out
184
- )
185
180
"
186
181
187
182
# ###############################################################
0 commit comments