refactor(config): absl::c_contains + config tests to gmock matchers - #92
Merged
Conversation
config.cc drops a hand-rolled Contains(vector, string_view) linear-search helper for absl::c_contains (range-based bool wrapper; dep @abseil-cpp//absl/algorithm:container). All three config-package tests now assert via gmock matchers (EXPECT_THAT + ElementsAre + Field) instead of ASSERT_EQ(size) + indexed EXPECT_EQ: config_test gains a FlagIs(flag, source) matcher, xffrc_test an RcLineIs(base, config, flags) matcher, ini_test a PolicyRuleIs(layer, allow, tokens) matcher - each folding count + order + every field into one assertion. Remaining EXPECT_EQ users (datetime/exec/regex/engine tests) follow in a sweep.
helly25
enabled auto-merge (squash)
June 23, 2026 00:35
helly25
added a commit
that referenced
this pull request
Jul 2, 2026
-grep PATTERN is the line-output companion of the -rxc content predicate: for each file it prints every content line matching an RE2 regex as path:line:text (grep's piped form), and returns true iff it printed a line (grep-like exit, so it composes with -o / -q). Non-regular, unreadable, and binary files yield nothing, reusing the content predicates' ContentToSearch (8 KiB NUL sniff). It is self-contained (its own pattern, pre-compiled like -rxc) and composes with the full find predicate set -- xff -mtime -7 -size +1M -grep TODO -- which is the value over piping to grep/rg: find-grade selection fused with the match output in one walk. -content / -rxc stay untouched as file filters. The -grep name, rejected earlier for a *matcher* predicate (grep's regex-flavor baggage), is unambiguous for a pattern-less-flavor output action; the flavor will live in --regextype (#85), not the name. xff-style extension (--config=find rejects it). Deferred to follow-ups: the -grep=FORMAT custom template with {line}/{text} fields, --regextype=EXACT|RE2 mode selection, {match}/{column} (-o), context (-A/-B/-C), and count (-c, #92). Tests: evaluate_test (emit shape + line numbers, regex not literal, no-match is false+silent, binary skip); run_test (path:line:text across the walk); grep_test.sh end-to-end (regex, binary skip, composition, find-style rejection). Self-doc: registry descriptor + kHelpText + design.md. bazel test //... green (39).
helly25
added a commit
that referenced
this pull request
Jul 3, 2026
--count (grep/rg -c; -c is a grep-compatible single-dash alias, like -q/-g) makes -grep print one path:count per file -- its number of matching lines -- instead of the lines, and supersedes -grep=FORMAT. Files with no match emit nothing (rg -c style). Reuses the line-match engine (count = matching lines); -grep still returns true iff it matched, so -q/--exit-match are unaffected. Global, so it precedes the roots like --summary. EvalContext gains grep_count (resolved from --count/-c in run.cc); EvalGrep emits the count and returns early when set. Self-doc: globals.cc (+ -c alias) + kHelpText + design.md. Tests: evaluate_test (count + no-match-silent), run_test (e2e), grep_test.sh (path:count, 0-match omitted, lines suppressed). bazel test //... green (39); both clang-format versions + shfmt clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #91 (loader core), addressing two review points.
Code
config.ccreplaces a hand-rolledContains(vector, string_view)linear-search helper withabsl::c_contains(range-basedboolwrapper overc_find; dep@abseil-cpp//absl/algorithm:container).Tests
All three config-package tests now assert with gmock matchers (
EXPECT_THAT+ElementsAre+Field) instead ofASSERT_EQ(size)+ indexedEXPECT_EQ:config_test->FlagIs(flag, source)xffrc_test->RcLineIs(base, config, flags)ini_test->PolicyRuleIs(layer, allow, tokens)Each helper folds count + order + every field into one assertion.
Green on default +
--config=clang --config=asan; clang-format + no-em-dash clean.Remaining
EXPECT_EQ/ASSERT_EQusers (datetime24,exec5,regex4,engine2) follow in one sweep PR next.