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