summaryrefslogtreecommitdiff
path: root/tests/filename-lineno.pl
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2020-09-07 17:20:11 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2020-09-07 19:49:33 -0700
commit33e4602c96e639ec7d56b92ffe3614aa700d3d76 (patch)
treedd2a886a01d60d2ea22a2eade588ff6a8dc3bc53 /tests/filename-lineno.pl
parent7ded8efd721ce2abf2b781931e0a0bdd46b156d7 (diff)
downloadgrep-33e4602c96e639ec7d56b92ffe3614aa700d3d76.tar.gz
Omit duplicate regexps
Do not pass two copies of the same regexp to the regular-expression engine. Although the engines should perform nearly as well even with the copies, in practice they do not. Problem reported by Luca Borzacchiello (Bug#43040). * bootstrap.conf (gnulib_modules): Add hash. * src/grep.c: Include stdint.h, for SIZE_WIDTH. Include hash.h. (struct patloc, patloc, patlocs_allocated, patlocs_used): Rename from struct FL_pair, fl_pair, n_fl_pair_slots, n_pattern_files, respectively, since the data type is no longer a pair. All uses changed. (struct patloc): New member FILELINE. The lineno member is now ptrdiff_t since nowadays we prefer signed types. (pattern_array, patterns_table): New static vars. (count_nl_bytes, fl_add): Remove; no longer used. (hash_pattern, compare_patterns, update_patterns): New functions. update_patterns does what fl_add used to do, plus remove dups. (pattern_file_name): Adjust to change from fl_pair to patloc. (main): Move some variables to inner blocks for clarity. Maintain the pattern_table hash of all patterns. Update pattern_array to match keys, and use update_patterns instead of fl_add to remove duplicate keys. * tests/filename-lineno.pl (invalid-re-2-files) (invalid-re-2-files2, invalid-re-2e): Ensure regexps are unique in tests so that dups aren’t removed in diagnostics. (invalid-re-line-numbers): New test.
Diffstat (limited to 'tests/filename-lineno.pl')
-rwxr-xr-xtests/filename-lineno.pl19
1 files changed, 16 insertions, 3 deletions
diff --git a/tests/filename-lineno.pl b/tests/filename-lineno.pl
index 998af73d..8940b1c7 100755
--- a/tests/filename-lineno.pl
+++ b/tests/filename-lineno.pl
@@ -48,7 +48,7 @@ my @Tests =
# Show that with two or more errors, grep now prints all diagnostics:
['invalid-re-2-files', '-f g -f h', {EXIT=>2},
{AUX=>{g=>"1\n2[[\n3\n4[[\n"}},
- {AUX=>{h=>"\n\n[[\n"}},
+ {AUX=>{h=>"5\n6\n7[[\n"}},
$err_subst,
{ERR => "$prog: g:2: Unmatched [...\n"
. "$prog: g:4: Unmatched [...\n"
@@ -59,7 +59,7 @@ my @Tests =
# Like the above, but on the other lines.
['invalid-re-2-files2', '-f g -f h', {EXIT=>2},
{AUX=>{g=>"1[[\n2\n3[[\n4\n"}},
- {AUX=>{h=>"[[\n[[\n\n"}},
+ {AUX=>{h=>"5[[\n6[[\n7\n"}},
$err_subst,
{ERR => "$prog: g:1: Unmatched [...\n"
. "$prog: g:3: Unmatched [...\n"
@@ -68,9 +68,22 @@ my @Tests =
},
],
+ # Make sure the line numbers are right when some regexps are duplicates.
+ ['invalid-re-line-numbers', '-f g -f h', {EXIT=>2},
+ {AUX=>{g=>"1[[\n\n3[[\n\n5[[\n"}},
+ {AUX=>{h=>"1[[\n\n\n4[[\n\n6[[\n"}},
+ $err_subst,
+ {ERR => "$prog: g:1: Unmatched [...\n"
+ . "$prog: g:3: Unmatched [...\n"
+ . "$prog: g:5: Unmatched [...\n"
+ . "$prog: h:4: Unmatched [...\n"
+ . "$prog: h:6: Unmatched [...\n"
+ },
+ ],
+
# Show that with two '-e'-specified erroneous regexps,
# there is no file name or line number.
- ['invalid-re-2e', '-e "[[" -e "[["', {EXIT=>2},
+ ['invalid-re-2e', '-e "1[[" -e "2[["', {EXIT=>2},
$err_subst,
{ERR => "$prog: Unmatched [...\n" x 2},
],