t4013: simplify magic parsing and drop "failure"

In t14013, we have various different tests that verify whether certain diffs are generated as expected. As much of the logic is the same across many of the tests we some common code in there that generates the actual test cases for us. As some diffs are more special than others depending on the command line parameters passed to git-diff(1), these tests need to adapt behaviour to the specific test case sometimes. This is done via colon-prefixed magic commands, of which we currently know "failure" and "noellipses". The logic to parse this magic is a bit convoluted though and hard to grasp, also due to the rather unnecessary nesting. Un-nest the cases so that it becomes a bit more straightfoward. The logic is further simplified by removing support for the "failure" magic, which is not actually used anymore. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Nov 29, 2023 at 08:25 UTC 46262691686d302e77bfaf8e27b7fd3792705aeb
1 file changed +12 -15
t/t4013-diff-various.sh
+12 -15
@@ -178,32 +178,29 @@ process_diffs () {
178 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
179 while read magic cmd
180 do
181 - status=success
181 case "$magic" in
182 '' | '#'*)
183 continue ;;
185 - :*)
186 - magic=${magic#:}
184 + :noellipses)
185 + magic=noellipses
186 label="$magic-$cmd"
188 - case "$magic" in
189 - noellipses) ;;
190 - failure)
191 - status=failure
192 - magic=
193 - label="$cmd" ;;
194 - *)
195 - BUG "unknown magic $magic" ;;
196 - esac ;;
187 + ;;
188 + :*)
189 + BUG "unknown magic $magic"
190 + ;;
191 *)
198 - cmd="$magic $cmd" magic=
199 - label="$cmd" ;;
192 + cmd="$magic $cmd"
193 + magic=
194 + label="$cmd"
195 + ;;
196 esac
197 +
198 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
199 pfx=$(printf "%04d" $test_count)
200 expect="$TEST_DIRECTORY/t4013/diff.$test"
201 actual="$pfx-diff.$test"
202
206 - test_expect_$status "git $cmd # magic is ${magic:-(not used)}" '
203 + test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
204 {
205 echo "$ git $cmd"
206 case "$magic" in