test prerequisites: eradicate NOT_FOO
[gitweb.git] / t / t6006-rev-list-format.sh
index 4751d222176d65d0fae82d9798827b2b8d2b9433..88ed3191e871cd9a164c3c903f69b07e7d9cf937 100755 (executable)
@@ -9,18 +9,32 @@ test_description='git rev-list --pretty=format test'
 . "$TEST_DIRECTORY"/lib-terminal.sh
 
 test_tick
-# String "added" in German (translated with Google Translate), encoded in UTF-8,
-# used as a commit log message below.
-added=$(printf "added (hinzugef\303\274gt) foo")
-added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1)
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
+# String "added" in German
+# (translated with Google Translate),
+# encoded in UTF-8, used as a commit log message below.
+added_utf8_part=$(printf "\303\274")
+added_utf8_part_iso88591=$(echo "$added_utf8_part" | iconv -f utf-8 -t $test_encoding)
+added=$(printf "added (hinzugef${added_utf8_part}gt) foo")
+added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding)
 # same but "changed"
-changed=$(printf "changed (ge\303\244ndert) foo")
-changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso8859-1)
+changed_utf8_part=$(printf "\303\244")
+changed_utf8_part_iso88591=$(echo "$changed_utf8_part" | iconv -f utf-8 -t $test_encoding)
+changed=$(printf "changed (ge${changed_utf8_part}ndert) foo")
+changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding)
+
+# Count of char to truncate
+# Number is chosen so, that non-ACSII characters
+# (see $added_utf8_part and $changed_utf8_part)
+# fall into truncated parts of appropriate words both from left and right
+truncate_count=20
 
 test_expect_success 'setup' '
        : >foo &&
        git add foo &&
-       git config i18n.commitEncoding iso8859-1 &&
+       git config i18n.commitEncoding $test_encoding &&
        git commit -m "$added_iso88591" &&
        head1=$(git rev-parse --verify HEAD) &&
        head1_short=$(git rev-parse --verify --short $head1) &&
@@ -35,26 +49,13 @@ test_expect_success 'setup' '
        git config --unset i18n.commitEncoding
 '
 
-# usage: test_format [failure] name format_string <expected_output
+# usage: test_format name format_string [failure] <expected_output
 test_format () {
-       must_fail=0
-       # if parameters count is more than 2 then test must fail
-       if test $# -gt 2
-       then
-               must_fail=1
-               # remove first parameter which is flag for test failure
-               shift
-       fi
        cat >expect.$1
-       name="format $1"
-       command="git rev-list --pretty=format:'$2' master >output.$1 &&
-               test_cmp expect.$1 output.$1"
-       if test $must_fail -eq 1
-       then
-               test_expect_failure "$name" "$command"
-       else
-               test_expect_success "$name" "$command"
-       fi
+       test_expect_${3:-success} "format $1" "
+               git rev-list --pretty=format:'$2' master >output.$1 &&
+               test_cmp expect.$1 output.$1
+       "
 }
 
 # Feed to --format to provide predictable colored sequences.
@@ -136,9 +137,9 @@ EOF
 
 test_format encoding %e <<EOF
 commit $head2
-iso8859-1
+$test_encoding
 commit $head1
-iso8859-1
+$test_encoding
 EOF
 
 test_format subject %s <<EOF
@@ -148,6 +149,13 @@ commit $head1
 $added
 EOF
 
+test_format subject-truncated "%<($truncate_count,trunc)%s" <<EOF
+commit $head2
+changed (ge${changed_utf8_part}ndert)..
+commit $head1
+added (hinzugef${added_utf8_part}gt..
+EOF
+
 test_format body %b <<EOF
 commit $head2
 commit $head1
@@ -202,12 +210,9 @@ test_expect_success '%C(auto) respects --no-color' '
 '
 
 test_expect_success TTY '%C(auto) respects --color=auto (stdout is tty)' '
-       (
-               TERM=vt100 && export TERM &&
-               test_terminal \
-                       git log --format=$AUTO_COLOR -1 --color=auto >actual &&
-               has_color actual
-       )
+       test_terminal env TERM=vt100 \
+               git log --format=$AUTO_COLOR -1 --color=auto >actual &&
+       has_color actual
 '
 
 test_expect_success '%C(auto) respects --color=auto (stdout not tty)' '
@@ -218,54 +223,123 @@ test_expect_success '%C(auto) respects --color=auto (stdout not tty)' '
        )
 '
 
-iconv -f utf-8 -t iso8859-1 > commit-msg <<EOF
+iconv -f utf-8 -t $test_encoding > commit-msg <<EOF
 Test printing of complex bodies
 
 This commit message is much longer than the others,
-and it will be encoded in iso8859-1. We should therefore
-include an iso8859 character: ¡bueno!
+and it will be encoded in $test_encoding. We should therefore
+include an ISO8859 character: ¡bueno!
 EOF
 
 test_expect_success 'setup complex body' '
-       git config i18n.commitencoding iso8859-1 &&
+       git config i18n.commitencoding $test_encoding &&
        echo change2 >foo && git commit -a -F commit-msg &&
        head3=$(git rev-parse --verify HEAD) &&
-       head3_short=$(git rev-parse --short $head3) &&
-       # unset commit encoding config
-       # otherwise %e does not print encoding value
-       # and following test fails
-       git config --unset i18n.commitEncoding
-
+       head3_short=$(git rev-parse --short $head3)
 '
 
 test_format complex-encoding %e <<EOF
 commit $head3
-iso8859-1
+$test_encoding
 commit $head2
-iso8859-1
+$test_encoding
 commit $head1
-iso8859-1
+$test_encoding
 EOF
 
 test_format complex-subject %s <<EOF
 commit $head3
 Test printing of complex bodies
 commit $head2
+$changed_iso88591
+commit $head1
+$added_iso88591
+EOF
+
+test_format complex-subject-trunc "%<($truncate_count,trunc)%s" <<EOF
+commit $head3
+Test printing of c..
+commit $head2
+changed (ge${changed_utf8_part_iso88591}ndert)..
+commit $head1
+added (hinzugef${added_utf8_part_iso88591}gt..
+EOF
+
+test_format complex-subject-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF
+commit $head3
+Test prin..ex bodies
+commit $head2
+changed (..dert) foo
+commit $head1
+added (hi..f${added_utf8_part_iso88591}gt) foo
+EOF
+
+test_format complex-subject-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF
+commit $head3
+.. of complex bodies
+commit $head2
+..ged (ge${changed_utf8_part_iso88591}ndert) foo
+commit $head1
+.. (hinzugef${added_utf8_part_iso88591}gt) foo
+EOF
+
+test_expect_success 'prepare expected messages (for test %b)' '
+       cat <<-EOF >expected.utf-8 &&
+       commit $head3
+       This commit message is much longer than the others,
+       and it will be encoded in $test_encoding. We should therefore
+       include an ISO8859 character: ¡bueno!
+
+       commit $head2
+       commit $head1
+       EOF
+       iconv -f utf-8 -t $test_encoding expected.utf-8 >expected.ISO8859-1
+'
+
+test_format complex-body %b <expected.ISO8859-1
+
+# Git uses i18n.commitEncoding if no i18n.logOutputEncoding set
+# so unset i18n.commitEncoding to test encoding conversion
+git config --unset i18n.commitEncoding
+
+test_format complex-subject-commitencoding-unset %s <<EOF
+commit $head3
+Test printing of complex bodies
+commit $head2
 $changed
 commit $head1
 $added
 EOF
 
-test_format complex-body %b <<EOF
+test_format complex-subject-commitencoding-unset-trunc "%<($truncate_count,trunc)%s" <<EOF
 commit $head3
-This commit message is much longer than the others,
-and it will be encoded in iso8859-1. We should therefore
-include an iso8859 character: ¡bueno!
+Test printing of c..
+commit $head2
+changed (ge${changed_utf8_part}ndert)..
+commit $head1
+added (hinzugef${added_utf8_part}gt..
+EOF
+
+test_format complex-subject-commitencoding-unset-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF
+commit $head3
+Test prin..ex bodies
+commit $head2
+changed (..dert) foo
+commit $head1
+added (hi..f${added_utf8_part}gt) foo
+EOF
 
+test_format complex-subject-commitencoding-unset-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF
+commit $head3
+.. of complex bodies
 commit $head2
+..ged (ge${changed_utf8_part}ndert) foo
 commit $head1
+.. (hinzugef${added_utf8_part}gt) foo
 EOF
 
+test_format complex-body-commitencoding-unset %b <expected.utf-8
+
 test_expect_success '%x00 shows NUL' '
        echo  >expect commit $head3 &&
        echo >>expect fooQbar &&
@@ -394,4 +468,10 @@ test_expect_success 'single-character name is parsed correctly' '
        test_cmp expect actual
 '
 
+test_expect_success 'unused %G placeholders are passed through' '
+       echo "%GX %G" >expect &&
+       git log -1 --format="%GX %G" >actual &&
+       test_cmp expect actual
+'
+
 test_done