@matheusbsbs / matheus-bagliano / commits / c4c2a96ec7
Fork 0

t4210: detect REG_ILLSEQ dynamically and skip affected tests

7187c7bbb8 (t4210: skip i18n tests that don't work on FreeBSD, 2019-11-27) adds a REG_ILLSEQ prerequisite, and to do that copies the common branch in test-lib and expands it to include it in a special case for FreeBSD. Instead; test for it using a previously added extension to test-tool and use that, together with a function that identifies when regcomp/regexec will be called with broken patterns to avoid any test that would otherwise rely on undefined behaviour. The description of the first test which wasn't accurate has been corrected, and the test rearranged for clarity, including a helper function that avoids overly long lines. Only the affected engines will have their tests suppressed, also including "fixed" if the PCRE optimization that uses LIBPCRE2 since b65abcafc7 (grep: use PCRE v2 for optimized fixed-string search, 2019-07-01) is not available. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Carlo Marcelo Arenas Belón committed May 18, 2020 at 11:44 UTC c4c2a96ec73775b1a4d4d850bb9ae7f50bc6912e
2 files changed +59 -24
t/t4210-log-i18n.sh
+59 -18
@@ -10,6 +10,13 @@ latin1_e=$(printf '\351')
10 # invalid UTF-8
11 invalid_e=$(printf '\303\50)') # ")" at end to close opening "("
12
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 +
20 test_expect_success 'create commits in different encodings' '
21 test_tick &&
22 cat >msg <<-EOF &&
@@ -51,43 +58,77 @@ test_expect_success !MINGW 'log --grep does not find non-reencoded values (utf8)
58 test_must_be_empty actual
59 '
60
54 -test_expect_success !MINGW 'log --grep does not find non-reencoded values (latin1)' '
61 +test_expect_success 'log --grep does not find non-reencoded values (latin1)' '
62 git log --encoding=ISO-8859-1 --format=%s --grep=$utf8_e >actual &&
63 test_must_be_empty actual
64 '
65
66 +triggers_undefined_behaviour () {
67 + local engine=$1
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 () {
88 + local pattern=$1
89 +
90 + LC_ALL=$is_IS_locale git log --encoding=ISO-8859-1 --format=%s \
91 + --grep=$pattern
92 +}
93 +
94 for engine in fixed basic extended perl
95 do
96 prereq=
97 if test $engine = "perl"
98 then
64 - prereq="PCRE"
65 - else
66 - prereq=""
99 + prereq=PCRE
100 fi
101 force_regex=
102 if test $engine != "fixed"
103 then
71 - force_regex=.*
104 + force_regex='.*'
105 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 - "
106
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
107 + test_expect_success $prereq "config grep.patternType=$engine" "
108 + git config grep.patternType $engine
109 "
110
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 &&
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 &&
113 test_must_be_empty actual
114 "
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
132 done
133
134 test_done
t/test-lib.sh
-6
@@ -1454,12 +1454,6 @@ case $uname_s in
1454 test_set_prereq SED_STRIPS_CR
1455 test_set_prereq GREP_STRIPS_CR
1456 ;;
1457 -FreeBSD)
1458 - test_set_prereq REGEX_ILLSEQ
1459 - test_set_prereq POSIXPERM
1460 - test_set_prereq BSLASHPSPEC
1461 - test_set_prereq EXECKEEPSPID
1462 - ;;
1457 *)
1458 test_set_prereq POSIXPERM
1459 test_set_prereq BSLASHPSPEC