From 77a6815d7d5be7031324788f9935587bdb00de60 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Wed, 26 Jun 2013 14:19:46 +0400 Subject: t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs The expected SHA-1 digests are always available in variables. Use them instead of hardcoding. Signed-off-by: Alexey Shumkin Signed-off-by: Junio C Hamano --- t/t6006-rev-list-format.sh | 140 +++++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 63 deletions(-) (limited to 't/t6006-rev-list-format.sh') diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 0393c9fd0b..cc1008d024 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -7,8 +7,19 @@ test_description='git rev-list --pretty=format test' test_tick test_expect_success 'setup' ' -touch foo && git add foo && git commit -m "added foo" && - echo changed >foo && git commit -a -m "changed foo" + : >foo && + git add foo && + git commit -m "added foo" && + head1=$(git rev-parse --verify HEAD) && + head1_short=$(git rev-parse --verify --short $head1) && + tree1=$(git rev-parse --verify HEAD:) && + tree1_short=$(git rev-parse --verify --short $tree1) && + echo changed >foo && + git commit -a -m "changed foo" && + head2=$(git rev-parse --verify HEAD) && + head2_short=$(git rev-parse --verify --short $head2) && + tree2=$(git rev-parse --verify HEAD:) && + tree2_short=$(git rev-parse --verify --short $tree2) ' # usage: test_format name format_string foo && git commit -a -F commit-msg + git config i18n.commitencoding iso8859-1 && + echo change2 >foo && git commit -a -F commit-msg && + head3=$(git rev-parse --verify HEAD) && + head3_short=$(git rev-parse --short $head3) ' -test_format complex-encoding %e <<'EOF' -commit 1ed88da4a5b5ed8c449114ac131efc62178734c3 +test_format complex-encoding %e <expect commit 1ed88da4a5b5ed8c449114ac131efc62178734c3 && + echo >expect commit $head3 && echo >>expect fooQbar && git rev-list -1 --format=foo%x00bar HEAD >actual.nul && nul_to_q actual && -- cgit v1.2.3 From de6029a2d7734a93a9e27b9c4471862a47dd8123 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Wed, 26 Jun 2013 14:19:49 +0400 Subject: pretty: Add failing tests: --format output should honor logOutputEncoding One can set an alias $ git config alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit --date=local" to see the log as a pretty tree (like *gitk* but in a terminal). However, log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted even when i18n.logOutputEncoding and terminal encoding are the same (e.g. log messages committed on a Cygwin box with Windows-1251 encoding seen on a Linux box with a UTF-8 encoding and vice versa). To simplify an example we can say the following two commands are expected to give the same output to a terminal: $ git log --oneline --no-color $ git log --pretty=format:'%h %s' However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it formats "%s". The same corruption is true for $ git diff --submodule=log and $ git rev-list --pretty=format:%s HEAD and $ git reset --hard This patch adds failing tests for the next patch that fixes them. Signed-off-by: Alexey Shumkin Signed-off-by: Junio C Hamano --- t/t6006-rev-list-format.sh | 83 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 24 deletions(-) (limited to 't/t6006-rev-list-format.sh') diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index cc1008d024..c66a07f8da 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -1,34 +1,60 @@ #!/bin/sh +# Copyright (c) 2009 Jens Lehmann +# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests) + test_description='git rev-list --pretty=format test' . ./test-lib.sh . "$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 iso-8859-1) +# same but "changed" +changed=$(printf "changed (ge\303\244ndert) foo") +changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso-8859-1) + test_expect_success 'setup' ' : >foo && git add foo && - git commit -m "added foo" && + git config i18n.commitEncoding iso-8859-1 && + git commit -m "$added_iso88591" && head1=$(git rev-parse --verify HEAD) && head1_short=$(git rev-parse --verify --short $head1) && tree1=$(git rev-parse --verify HEAD:) && tree1_short=$(git rev-parse --verify --short $tree1) && - echo changed >foo && - git commit -a -m "changed foo" && + echo "$changed" > foo && + git commit -a -m "$changed_iso88591" && head2=$(git rev-parse --verify HEAD) && head2_short=$(git rev-parse --verify --short $head2) && tree2=$(git rev-parse --verify HEAD:) && tree2_short=$(git rev-parse --verify --short $tree2) + git config --unset i18n.commitEncoding ' -# usage: test_format name format_string expect.$1 - test_expect_success "format $1" " - git rev-list --pretty=format:'$2' master >output.$1 && - test_cmp expect.$1 output.$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 } # Feed to --format to provide predictable colored sequences. @@ -110,14 +136,16 @@ EOF test_format encoding %e <commit-msg <<'EOF' +iconv -f utf-8 -t iso8859-1 > commit-msg <foo && git commit -a -F commit-msg && head3=$(git rev-parse --verify HEAD) && - head3_short=$(git rev-parse --short $head3) + 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 + ' test_format complex-encoding %e <actual && - test $(wc -w actual && - test $(wc -w Date: Wed, 26 Jun 2013 14:19:50 +0400 Subject: pretty: --format output should honor logOutputEncoding One can set an alias $ git config [--global] alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit --date=local" to see the log as a pretty tree (like *gitk* but in a terminal). However, log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted even when i18n.logOutputEncoding and terminal encoding are the same (e.g. log messages committed on a Cygwin box with Windows-1251 encoding seen on a Linux box with a UTF-8 encoding and vice versa). To simplify an example we can say the following two commands are expected to give the same output to a terminal: $ git log --oneline --no-color $ git log --pretty=format:'%h %s' However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it formats "%s". The same corruption is true for $ git diff --submodule=log and $ git rev-list --pretty=format:%s HEAD and $ git reset --hard This patch makes pretty --format honor logOutputEncoding when it formats log message. Signed-off-by: Alexey Shumkin Signed-off-by: Junio C Hamano --- t/t6006-rev-list-format.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 't/t6006-rev-list-format.sh') diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index c66a07f8da..380c85bf12 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -141,7 +141,7 @@ commit $head1 iso-8859-1 EOF -test_format failure subject %s < Date: Thu, 4 Jul 2013 16:45:46 +0400 Subject: t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1 Both "iso8859-1" and "iso-8859-1" are understood as latin-1 by modern platforms, but the latter is not understood by older platforms;update tests to use the former. This is in line with 3994e8a9 (t4201: use ISO8859-1 rather than ISO-8859-1, 2009-12-03), which did the same. Signed-off-by: Alexey Shumkin Reviewed-by: Johannes Sixt Signed-off-by: Junio C Hamano --- t/t6006-rev-list-format.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 't/t6006-rev-list-format.sh') diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 380c85bf12..4751d22217 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -12,15 +12,15 @@ 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 iso-8859-1) +added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1) # same but "changed" changed=$(printf "changed (ge\303\244ndert) foo") -changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso-8859-1) +changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso8859-1) test_expect_success 'setup' ' : >foo && git add foo && - git config i18n.commitEncoding iso-8859-1 && + git config i18n.commitEncoding iso8859-1 && git commit -m "$added_iso88591" && head1=$(git rev-parse --verify HEAD) && head1_short=$(git rev-parse --verify --short $head1) && @@ -136,9 +136,9 @@ EOF test_format encoding %e < Date: Fri, 5 Jul 2013 16:01:48 +0400 Subject: t4205, t6006, t7102: make functions better readable Function 'test_format' has become harder to read after its change in de6029a2 (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26). Simplify it by moving its "should we expect it to fail?" parameter to the end. Note, current code does not use this last parameter as far as there are no tests expected to fail. We can keep that for future use. Also, reformat comments. Signed-off-by: Alexey Shumkin Improved-by: Johannes Sixt Signed-off-by: Junio C Hamano --- t/t6006-rev-list-format.sh | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) (limited to 't/t6006-rev-list-format.sh') diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 4751d22217..b32405a760 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -9,8 +9,9 @@ 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. +# 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) # same but "changed" @@ -35,26 +36,13 @@ test_expect_success 'setup' ' git config --unset i18n.commitEncoding ' -# usage: test_format [failure] name format_string 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. -- cgit v1.2.3 From 0fe6df3ce8e6373536d1a9016cac9126a1aed0da Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Fri, 5 Jul 2013 16:01:49 +0400 Subject: t6006 (rev-list-format): add tests for "%b" and "%s" for the case i18n.commitEncoding is not set In de6029a (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26) 'complex-subject' test was changed. Revert it back, because that change actually removed tests for "%b" and "%s" with i18n.commitEncoding set. Also, add two more tests for mentioned above "%b" and "%s" to test encoding conversions with no i18n.commitEncoding set. Signed-off-by: Alexey Shumkin Suggested-by: Johannes Sixt Signed-off-by: Junio C Hamano --- t/t6006-rev-list-format.sh | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 't/t6006-rev-list-format.sh') diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index b32405a760..98744038ec 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -218,12 +218,7 @@ test_expect_success 'setup complex body' ' git config i18n.commitencoding iso8859-1 && 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 <expected.utf-8 && + 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! + + commit $head2 + commit $head1 + EOF + iconv -f utf-8 -t iso8859-1 expected.utf-8 >expected.iso8859-1 +' + +test_format complex-body %b expect commit $head3 && echo >>expect fooQbar && -- cgit v1.2.3