Commit Graph

29 Commits

Author SHA1 Message Date
Sylvestre Ledru be51c04c08 grep: support GREP_COLORS 'mt' and warn on deprecated GREP_COLOR
Two color-handling gaps vs GNU: the 'mt' capability in GREP_COLORS (which
sets both the selected- and context-match colors) was ignored, and the
deprecated GREP_COLOR variable produced no warning. Handle 'mt', and emit
GNU's 'GREP_COLOR=... is deprecated; use GREP_COLORS=mt=...' warning when
color output is actually produced. Fixes the GNU testsuite 'color-colors'
test.
2026-05-30 18:55:55 +02:00
Sylvestre Ledru da32a63663 grep: map invalid back-reference errors to GNU's wording
A back-reference to a non-existent group, e.g. (.)\2, makes oniguruma
fail with 'invalid backref number/name'. GNU words this per engine:
'reference to non-existent subpattern' under -P (PCRE2) and 'Invalid
back reference' for basic/extended (gnulib regex). Translate
ONIGERR_INVALID_BACKREF accordingly (gnu_error_message now takes the
regex mode). Fixes the GNU testsuite 'pcre-wx-backref' test.

Also drop pipe_in() from the compile-error tests added in the previous
commits: those patterns are rejected before stdin is read, so feeding
input raced with the child exiting and intermittently panicked the test
harness with a broken pipe under parallel execution.
2026-05-30 18:02:32 +02:00
Sylvestre Ledru 9c21a7d2f0 grep: handle regex backtracking-limit instead of panicking
A pathological pattern such as -P '((a+)*)+$' makes oniguruma exceed its
match retry limit. The onig crate's search_with_encoding/match_with_encoding
panic on that error, so uu_grep aborted with a Rust panic. Switch to the
fallible *_with_param variants and propagate the error: match_line/is_match
now return io::Result, the failure is mapped to GNU's wording ('exceeded
PCRE's backtracking limit') and surfaces as a normal exit-code-2 diagnostic.
Fixes the GNU testsuite 'pcre-abort' test.
2026-05-30 17:55:31 +02:00
Sylvestre Ledru e767a30c1a grep: emit GNU's 'Invalid range end' for reversed bracket ranges
A reversed range like [b-a] makes oniguruma fail with 'empty range in
char class', which uu_grep wrapped as 'invalid pattern "[b-a]": ...'.
GNU grep instead prints the bare POSIX diagnostic 'Invalid range end'
and exits 2. Translate the oniguruma error code
(ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS) to GNU's wording, leaving other
compile errors to fall back to oniguruma's text. Fixes the GNU testsuite
'reversed-range-endpoints' test.
2026-05-30 17:50:02 +02:00
Sylvestre Ledru 1a3e8a391d grep: reject confusing [:name:] bracket syntax like GNU
GNU grep flags a bracket expression of the form [:name:] (an almost
certain misspelling of [[:name:]]) with a dedicated diagnostic and exit
code 2, whereas oniguruma silently treats it as the character set
{':','n','a','m','e'}. Port GNU's colon_warning_state logic from
parse_bracket_exp (gnulib dfa.c) so basic/extended patterns produce the
same error. Fixes the GNU testsuite 'warn-char-classes' test.
2026-05-30 17:39:29 +02:00
Sylvestre Ledru 98e6bb6f53 Merge pull request #10 from uutils/improv-cov
Improve the code coverage
2026-05-30 14:25:50 +02:00
Sylvestre Ledru da0ada8a37 test: use platform-specific expected message for nonexistent-file error 2026-05-30 11:33:47 +02:00
Sylvestre Ledru fcf46d8f56 test: cover -D skip on an explicit special-file argument 2026-05-30 11:28:04 +02:00
Sylvestre Ledru 55cb643545 test: cover strip_dot_prefix for implicit-cwd recursive search 2026-05-30 11:28:04 +02:00
Sylvestre Ledru 89aec4a45a test: cover -T line-number width on the file (not stdin) path 2026-05-30 11:28:03 +02:00
Sylvestre Ledru 6c5b7dc9e3 test: cover -L listing when the pattern matches one file 2026-05-30 11:28:03 +02:00
Sylvestre Ledru ff918e4a63 grep: strip trailing (os error N) from file error messages to match GNU (#6) 2026-05-29 22:24:20 +02:00
Sylvestre Ledru c50c0458cb fix: accept repeated options like GNU grep (#2)
GNU grep tolerates options given more than once (boolean flags are
idempotent, value options take the last occurrence), but clap rejected
them with "cannot be used multiple times" (exit 2). Set
args_override_self(true) so clap replaces rather than errors; args with
ArgAction::Append (-e/-f/--include/--exclude) still accumulate.

Found by the differential fuzzer (e.g. `grep -e .* -E -n -o -n -x`).

Add a regression test covering repeated booleans, repeated value options
(last wins), and that -e still accumulates patterns.
2026-05-29 22:21:27 +02:00
Sylvestre Ledru f7813500c9 Merge pull request #8 from uutils/gnu-test
run the gnu testsuite in the ci
2026-05-29 21:43:41 +02:00
Leonard Hecker 05d167b8d5 Fix support for Python-style named backreferences 2026-05-29 21:12:19 +02:00
Sylvestre Ledru 41b92b3cc1 Merge pull request #5 from uutils/fix-coverage-profraw-path
ci: use absolute LLVM_PROFILE_FILE path to fix 0% coverage
2026-05-29 20:46:10 +02:00
Sylvestre Ledru e885f66523 ci: post GNU grep testsuite comparison as a PR comment
Add a GnuComment workflow that runs after GnuTests completes on a pull
request, downloads the 'comment' artifact (PR number + comparison text), and
posts it as a PR comment. Mirrors ../sed's GnuComment workflow.
2026-05-29 18:43:11 +02:00
Sylvestre Ledru 10bfa405dc ci: add GnuTests workflow running the GNU grep testsuite
Add a GnuTests workflow that, on push and PR, fetches the GNU grep release
tarball, builds the Rust grep binary, runs util/run-gnu-testsuite.sh, and
uploads the JSON results. An aggregate job compares the run against the
reference summary from the default branch (util/compare_test_results.py,
borrowed from ../sed) and fails only on new, non-intermittent regressions;
known-flaky tests are listed in .github/workflows/ignore-intermittent.txt.
2026-05-29 18:43:11 +02:00
Sylvestre Ledru f0ae449d11 tests: run the GNU grep testsuite against uu_grep
Add util/fetch-gnu.sh (downloads the GNU grep 3.12 release tarball from
ftp.gnu.org) and util/run-gnu-testsuite.sh, which reuses the gnulib test
framework shipped in the tarball (tests/init.sh + init.cfg) and injects the
Rust grep binary via PATH, replicating tests/Makefile.am's TESTS_ENVIRONMENT.
Each test is classified by its gnulib exit code (0=PASS, 77=SKIP, else FAIL)
and results are emitted as JSON.

Modelled on ../sed (lightweight PATH-injection runner) and ../coreutils
(release-tarball fetch). Current baseline: 61 pass / 39 fail / 28 skip of 128
tests -- the failures quantify the remaining GNU-compatibility gap.
2026-05-29 18:43:11 +02:00
Sylvestre Ledru 79db36edbe add license headers 2026-05-29 10:12:38 +02:00
Sylvestre Ledru 3bf91e530e ci: use absolute LLVM_PROFILE_FILE path to fix 0% coverage
The test suite spawns the grep binary inside per-test temporary
directories (via uutests). With a relative LLVM_PROFILE_FILE, each
subprocess wrote its .profraw into that tempdir, which gets deleted
when the test ends, so the binary executing the src/ code left no
coverage data and grcov reported every line as a miss (0%).

Anchoring the path to the workspace root makes the profraw files
survive, raising reported coverage from 0% to ~96%.
2026-05-29 00:02:47 +02:00
Leonard Hecker 80e1fb8043 Fix repository URLs 2026-05-28 22:37:01 +02:00
Leonard Hecker ebe62e0cf7 Fix flaky tests 2026-05-28 22:32:49 +02:00
Sylvestre Ledru 017285060a Mention lack of localization support in README
Added note about lack of localization support.
2026-05-28 22:03:25 +02:00
Sylvestre Ledru bcbb5ac477 docs: add status badges to README 2026-05-28 21:20:19 +02:00