setup: merge configuration of repository formats
[git/gitster.git] / t / t4210-log-i18n.sh
blob7120030b5c650d91da5cf9ab9e3e0d6782936521
1 #!/bin/sh
3 test_description='test log with i18n features'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./lib-gettext.sh
8 # two forms of é
9 utf8_e=$(printf '\303\251')
10 latin1_e=$(printf '\351')
12 # invalid UTF-8
13 invalid_e=$(printf '\303\50)') # ")" at end to close opening "("
15 have_reg_illseq=
16 if test_have_prereq GETTEXT_LOCALE &&
17 ! LC_ALL=$is_IS_locale test-tool regex --silent $latin1_e
18 then
19 have_reg_illseq=1
22 test_expect_success 'create commits in different encodings' '
23 test_tick &&
24 cat >msg <<-EOF &&
25 utf8
27 t${utf8_e}st
28 EOF
29 git add msg &&
30 git -c i18n.commitencoding=utf8 commit -F msg &&
31 cat >msg <<-EOF &&
32 latin1
34 t${latin1_e}st
35 EOF
36 git add msg &&
37 git -c i18n.commitencoding=ISO-8859-1 commit -F msg
40 test_expect_success 'log --grep searches in log output encoding (utf8)' '
41 cat >expect <<-\EOF &&
42 latin1
43 utf8
44 EOF
45 git log --encoding=utf8 --format=%s --grep=$utf8_e >actual &&
46 test_cmp expect actual
49 test_expect_success !MINGW 'log --grep searches in log output encoding (latin1)' '
50 cat >expect <<-\EOF &&
51 latin1
52 utf8
53 EOF
54 git log --encoding=ISO-8859-1 --format=%s --grep=$latin1_e >actual &&
55 test_cmp expect actual
58 test_expect_success !MINGW 'log --grep does not find non-reencoded values (utf8)' '
59 git log --encoding=utf8 --format=%s --grep=$latin1_e >actual &&
60 test_must_be_empty actual
63 test_expect_success 'log --grep does not find non-reencoded values (latin1)' '
64 git log --encoding=ISO-8859-1 --format=%s --grep=$utf8_e >actual &&
65 test_must_be_empty actual
68 triggers_undefined_behaviour () {
69 local engine="$1"
71 case $engine in
72 fixed)
73 if test -n "$have_reg_illseq" &&
74 ! test_have_prereq LIBPCRE2
75 then
76 return 0
79 basic|extended)
80 if test -n "$have_reg_illseq"
81 then
82 return 0
85 esac
86 return 1
89 mismatched_git_log () {
90 local pattern="$1"
92 LC_ALL=$is_IS_locale git log --encoding=ISO-8859-1 --format=%s \
93 --grep=$pattern
96 for engine in fixed basic extended perl
98 prereq=
99 if test $engine = "perl"
100 then
101 prereq=PCRE
103 force_regex=
104 if test $engine != "fixed"
105 then
106 force_regex='.*'
109 test_expect_success $prereq "config grep.patternType=$engine" "
110 git config grep.patternType $engine
113 test_expect_success GETTEXT_LOCALE,$prereq "log --grep does not find non-reencoded values (latin1 + locale)" "
114 mismatched_git_log '$force_regex$utf8_e' >actual &&
115 test_must_be_empty actual
118 if ! triggers_undefined_behaviour $engine
119 then
120 test_expect_success !MINGW,GETTEXT_LOCALE,$prereq "log --grep searches in log output encoding (latin1 + locale)" "
121 cat >expect <<-\EOF &&
122 latin1
123 utf8
125 mismatched_git_log '$force_regex$latin1_e' >actual &&
126 test_cmp expect actual
129 test_expect_success GETTEXT_LOCALE,$prereq "log --grep does not die on invalid UTF-8 value (latin1 + locale + invalid needle)" "
130 mismatched_git_log '$force_regex$invalid_e' >actual &&
131 test_must_be_empty actual
134 done
136 test_done