Merge branch 'cb/avoid-colliding-with-netbsd-hmac'
[git] / t / t4210-log-i18n.sh
1 #!/bin/sh
2
3 test_description='test log with i18n features'
4 . ./lib-gettext.sh
5
6 # two forms of é
7 utf8_e=$(printf '\303\251')
8 latin1_e=$(printf '\351')
9
10 # invalid UTF-8
11 invalid_e=$(printf '\303\50)') # ")" at end to close opening "("
12
13 test_expect_success 'create commits in different encodings' '
14         test_tick &&
15         cat >msg <<-EOF &&
16         utf8
17
18         t${utf8_e}st
19         EOF
20         git add msg &&
21         git -c i18n.commitencoding=utf8 commit -F msg &&
22         cat >msg <<-EOF &&
23         latin1
24
25         t${latin1_e}st
26         EOF
27         git add msg &&
28         git -c i18n.commitencoding=ISO-8859-1 commit -F msg
29 '
30
31 test_expect_success 'log --grep searches in log output encoding (utf8)' '
32         cat >expect <<-\EOF &&
33         latin1
34         utf8
35         EOF
36         git log --encoding=utf8 --format=%s --grep=$utf8_e >actual &&
37         test_cmp expect actual
38 '
39
40 test_expect_success !MINGW 'log --grep searches in log output encoding (latin1)' '
41         cat >expect <<-\EOF &&
42         latin1
43         utf8
44         EOF
45         git log --encoding=ISO-8859-1 --format=%s --grep=$latin1_e >actual &&
46         test_cmp expect actual
47 '
48
49 test_expect_success !MINGW 'log --grep does not find non-reencoded values (utf8)' '
50         git log --encoding=utf8 --format=%s --grep=$latin1_e >actual &&
51         test_must_be_empty actual
52 '
53
54 test_expect_success !MINGW 'log --grep does not find non-reencoded values (latin1)' '
55         git log --encoding=ISO-8859-1 --format=%s --grep=$utf8_e >actual &&
56         test_must_be_empty actual
57 '
58
59 for engine in fixed basic extended perl
60 do
61         prereq=
62         if test $engine = "perl"
63         then
64                 prereq="PCRE"
65         else
66                 prereq=""
67         fi
68         force_regex=
69         if test $engine != "fixed"
70         then
71             force_regex=.*
72         fi
73         test_expect_success !MINGW,!REGEX_ILLSEQ,GETTEXT_LOCALE,$prereq "-c grep.patternType=$engine log --grep does not find non-reencoded values (latin1 + locale)" "
74                 cat >expect <<-\EOF &&
75                 latin1
76                 utf8
77                 EOF
78                 LC_ALL=\"$is_IS_locale\" git -c grep.patternType=$engine log --encoding=ISO-8859-1 --format=%s --grep=\"$force_regex$latin1_e\" >actual &&
79                 test_cmp expect actual
80         "
81
82         test_expect_success !MINGW,GETTEXT_LOCALE,$prereq "-c grep.patternType=$engine log --grep does not find non-reencoded values (latin1 + locale)" "
83                 LC_ALL=\"$is_IS_locale\" git -c grep.patternType=$engine log --encoding=ISO-8859-1 --format=%s --grep=\"$force_regex$utf8_e\" >actual &&
84                 test_must_be_empty actual
85         "
86
87         test_expect_success !MINGW,!REGEX_ILLSEQ,GETTEXT_LOCALE,$prereq "-c grep.patternType=$engine log --grep does not die on invalid UTF-8 value (latin1 + locale + invalid needle)" "
88                 LC_ALL=\"$is_IS_locale\" git -c grep.patternType=$engine log --encoding=ISO-8859-1 --format=%s --grep=\"$force_regex$invalid_e\" >actual &&
89                 test_must_be_empty actual
90         "
91 done
92
93 test_done