1
0
mirror of https://github.com/git/git.git synced 2024-09-27 14:51:15 +02:00

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>
This commit is contained in:
Patrick Steinhardt 2023-11-29 08:25:05 +01:00 committed by Junio C Hamano
parent 110feb893a
commit 4626269168

View File

@ -178,32 +178,29 @@ process_diffs () {
V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g') V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
while read magic cmd while read magic cmd
do do
status=success
case "$magic" in case "$magic" in
'' | '#'*) '' | '#'*)
continue ;; continue ;;
:*) :noellipses)
magic=${magic#:} magic=noellipses
label="$magic-$cmd" label="$magic-$cmd"
case "$magic" in ;;
noellipses) ;; :*)
failure) BUG "unknown magic $magic"
status=failure ;;
magic=
label="$cmd" ;;
*)
BUG "unknown magic $magic" ;;
esac ;;
*) *)
cmd="$magic $cmd" magic= cmd="$magic $cmd"
label="$cmd" ;; magic=
label="$cmd"
;;
esac esac
test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g') test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
pfx=$(printf "%04d" $test_count) pfx=$(printf "%04d" $test_count)
expect="$TEST_DIRECTORY/t4013/diff.$test" expect="$TEST_DIRECTORY/t4013/diff.$test"
actual="$pfx-diff.$test" actual="$pfx-diff.$test"
test_expect_$status "git $cmd # magic is ${magic:-(not used)}" ' test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
{ {
echo "$ git $cmd" echo "$ git $cmd"
case "$magic" in case "$magic" in