Raw
1 #!/bin/sh
2
3 test_description='test log with i18n features'
4
5 . ./lib-gettext.sh
6
7 if ! test_have_prereq ICONV
8 then
9 skip_all='skipping log i18n tests; iconv not available'
10 test_done
11 fi
12
13 # two forms of é
14 utf8_e=$(printf '\303\251')
15 latin1_e=$(printf '\351')
16
17 # invalid UTF-8
18 invalid_e=$(printf '\303\50)') # ")" at end to close opening "("
19
20 have_reg_illseq=
21 if test_have_prereq GETTEXT_LOCALE &&
22 ! LC_ALL=$is_IS_locale test-tool regex --silent $latin1_e
23 then
24 have_reg_illseq=1
25 fi
26
27 test_expect_success 'create commits in different encodings' '
28 test_tick &&
29 cat >msg <<-EOF &&
30 utf8
31
32 t${utf8_e}st
33 EOF
34 git add msg &&
35 git -c i18n.commitencoding=utf8 commit -F msg &&
36 cat >msg <<-EOF &&
37 latin1
38
39 t${latin1_e}st
40 EOF
41 git add msg &&
42 git -c i18n.commitencoding=ISO-8859-1 commit -F msg
43 '
44
45 test_expect_success 'log --grep searches in log output encoding (utf8)' '
46 cat >expect <<-\EOF &&
47 latin1
48 utf8
49 EOF
50 git log --encoding=utf8 --format=%s --grep=$utf8_e >actual &&
51 test_cmp expect actual
52 '
53
54 test_expect_success !MINGW 'log --grep searches in log output encoding (latin1)' '
55 cat >expect <<-\EOF &&
56 latin1
57 utf8
58 EOF
59 git log --encoding=ISO-8859-1 --format=%s --grep=$latin1_e >actual &&
60 test_cmp expect actual
61 '
62
63 test_expect_success !MINGW 'log --grep does not find non-reencoded values (utf8)' '
64 git log --encoding=utf8 --format=%s --grep=$latin1_e >actual &&
65 test_must_be_empty actual
66 '
67
68 test_expect_success 'log --grep does not find non-reencoded values (latin1)' '
69 git log --encoding=ISO-8859-1 --format=%s --grep=$utf8_e >actual &&
70 test_must_be_empty actual
71 '
72
73 triggers_undefined_behaviour () {
74 local engine="$1"
75
76 case $engine in
77 fixed)
78 if test -n "$have_reg_illseq" &&
79 ! test_have_prereq LIBPCRE2
80 then
81 return 0
82 fi
83 ;;
84 basic|extended)
85 if test -n "$have_reg_illseq"
86 then
87 return 0
88 fi
89 ;;
90 esac
91 return 1
92 }
93
94 mismatched_git_log () {
95 local pattern="$1"
96
97 LC_ALL=$is_IS_locale git log --encoding=ISO-8859-1 --format=%s \
98 --grep=$pattern
99 }
100
101 for engine in fixed basic extended perl
102 do
103 prereq=
104 if test $engine = "perl"
105 then
106 prereq=PCRE
107 fi
108 force_regex=
109 if test $engine != "fixed"
110 then
111 force_regex='.*'
112 fi
113
114 test_expect_success $prereq "config grep.patternType=$engine" "
115 git config grep.patternType $engine
116 "
117
118 test_expect_success GETTEXT_LOCALE,$prereq "log --grep does not find non-reencoded values (latin1 + locale)" "
119 mismatched_git_log '$force_regex$utf8_e' >actual &&
120 test_must_be_empty actual
121 "
122
123 if ! triggers_undefined_behaviour $engine
124 then
125 test_expect_success !MINGW,GETTEXT_LOCALE,$prereq "log --grep searches in log output encoding (latin1 + locale)" "
126 cat >expect <<-\EOF &&
127 latin1
128 utf8
129 EOF
130 mismatched_git_log '$force_regex$latin1_e' >actual &&
131 test_cmp expect actual
132 "
133
134 test_expect_success GETTEXT_LOCALE,$prereq "log --grep does not die on invalid UTF-8 value (latin1 + locale + invalid needle)" "
135 mismatched_git_log '$force_regex$invalid_e' >actual &&
136 test_must_be_empty actual
137 "
138 fi
139 done
140
141 test_done