The eleventh batch
[git/gitster.git] / t / t7812-grep-icase-non-ascii.sh
blob31c66b63c2cb008979cc64c3f9df203ce5ed1aeb
1 #!/bin/sh
3 test_description='grep icase on non-English locales'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./lib-gettext.sh
8 doalarm () {
9 perl -e 'alarm shift; exec @ARGV' -- "$@"
12 test_expect_success GETTEXT_LOCALE 'setup' '
13 test_write_lines "TILRAUN: Halló Heimur!" >file &&
14 git add file &&
15 LC_ALL="$is_IS_locale" &&
16 export LC_ALL
19 test_expect_success GETTEXT_LOCALE 'setup REGEX_LOCALE prerequisite' '
20 # This "test-tool" invocation is identical...
21 if test-tool regex "HALLÓ" "Halló" ICASE
22 then
23 test_set_prereq REGEX_LOCALE
24 else
26 # ... to this one, but this way "test_must_fail" will
27 # tell a segfault or abort() from the regexec() test
28 # itself
29 test_must_fail test-tool regex "HALLÓ" "Halló" ICASE
33 test_expect_success REGEX_LOCALE 'grep literal string, no -F' '
34 git grep -i "TILRAUN: Halló Heimur!" &&
35 git grep -i "TILRAUN: HALLÓ HEIMUR!"
38 test_expect_success GETTEXT_LOCALE,PCRE 'grep pcre utf-8 icase' '
39 git grep --perl-regexp "TILRAUN: H.lló Heimur!" &&
40 git grep --perl-regexp -i "TILRAUN: H.lló Heimur!" &&
41 git grep --perl-regexp -i "TILRAUN: H.LLÓ HEIMUR!"
44 test_expect_success GETTEXT_LOCALE,PCRE 'grep pcre utf-8 string with "+"' '
45 test_write_lines "TILRAUN: Hallóó Heimur!" >file2 &&
46 git add file2 &&
47 git grep -l --perl-regexp "TILRAUN: H.lló+ Heimur!" >actual &&
48 echo file >expected &&
49 echo file2 >>expected &&
50 test_cmp expected actual
53 test_expect_success REGEX_LOCALE 'grep literal string, with -F' '
54 git grep -i -F "TILRAUN: Halló Heimur!" &&
55 git grep -i -F "TILRAUN: HALLÓ HEIMUR!"
58 test_expect_success REGEX_LOCALE 'grep string with regex, with -F' '
59 test_write_lines "TILRAUN: Halló Heimur [abc]!" >file3 &&
60 git add file3 &&
61 git grep -i -F "TILRAUN: Halló Heimur [abc]!" file3
64 test_expect_success REGEX_LOCALE 'pickaxe -i on non-ascii' '
65 git commit -m first &&
66 git log --format=%f -i -S"TILRAUN: HALLÓ HEIMUR!" >actual &&
67 echo first >expected &&
68 test_cmp expected actual
71 test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: setup invalid UTF-8 data' '
72 printf "\\200\\n" >invalid-0x80 &&
73 echo "ævar" >expected &&
74 cat expected >>invalid-0x80 &&
75 git add invalid-0x80 &&
77 # Test for PCRE2_MATCH_INVALID_UTF bug
78 # https://bugs.exim.org/show_bug.cgi?id=2642
79 printf "\\345Aæ\\n" >invalid-0xe5 &&
80 git add invalid-0xe5
83 test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep ASCII from invalid UTF-8 data' '
84 git grep -h "var" invalid-0x80 >actual &&
85 test_cmp expected actual &&
86 git grep -h "(*NO_JIT)var" invalid-0x80 >actual &&
87 test_cmp expected actual
90 test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep ASCII from invalid UTF-8 data (PCRE2 bug #2642)' '
91 git grep -h "Aæ" invalid-0xe5 >actual &&
92 test_cmp invalid-0xe5 actual &&
93 git grep -h "(*NO_JIT)Aæ" invalid-0xe5 >actual &&
94 test_cmp invalid-0xe5 actual
97 test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep non-ASCII from invalid UTF-8 data' '
98 git grep -h "æ" invalid-0x80 >actual &&
99 test_cmp expected actual &&
100 git grep -h "(*NO_JIT)æ" invalid-0x80 >actual &&
101 test_cmp expected actual
104 test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep non-ASCII from invalid UTF-8 data (PCRE2 bug #2642)' '
105 git grep -h "Aæ" invalid-0xe5 >actual &&
106 test_cmp invalid-0xe5 actual &&
107 git grep -h "(*NO_JIT)Aæ" invalid-0xe5 >actual &&
108 test_cmp invalid-0xe5 actual
111 test_lazy_prereq PCRE2_MATCH_INVALID_UTF '
112 test-tool pcre2-config has-PCRE2_MATCH_INVALID_UTF
115 test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep non-ASCII from invalid UTF-8 data with -i' '
116 test_might_fail git grep -hi "Æ" invalid-0x80 >actual &&
117 test_might_fail git grep -hi "(*NO_JIT)Æ" invalid-0x80 >actual
120 test_expect_success GETTEXT_LOCALE,LIBPCRE2,PCRE2_MATCH_INVALID_UTF 'PCRE v2: grep non-ASCII from invalid UTF-8 data with -i' '
121 git grep -hi "Æ" invalid-0x80 >actual &&
122 test_cmp expected actual &&
123 git grep -hi "(*NO_JIT)Æ" invalid-0x80 >actual &&
124 test_cmp expected actual
127 test_expect_success GETTEXT_LOCALE,LIBPCRE2,PCRE2_MATCH_INVALID_UTF 'PCRE v2: grep non-ASCII from invalid UTF-8 data with -i (PCRE2 bug #2642)' '
128 git grep -hi "Æ" invalid-0xe5 >actual &&
129 test_cmp invalid-0xe5 actual &&
130 git grep -hi "(*NO_JIT)Æ" invalid-0xe5 >actual &&
131 test_cmp invalid-0xe5 actual &&
133 # Only the case of grepping the ASCII part in a way that
134 # relies on -i fails
135 git grep -hi "aÆ" invalid-0xe5 >actual &&
136 test_cmp invalid-0xe5 actual &&
137 git grep -hi "(*NO_JIT)aÆ" invalid-0xe5 >actual &&
138 test_cmp invalid-0xe5 actual
141 test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep non-literal ASCII from UTF-8' '
142 git grep --perl-regexp -h -o -e ll. file >actual &&
143 echo "lló" >expected &&
144 test_cmp expected actual
147 test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep avoid endless loop bug' '
148 echo " Halló" >leading-whitespace &&
149 git add leading-whitespace &&
150 doalarm 1 git grep --perl-regexp "^\s" leading-whitespace
153 test_done