Skip to content

refactor(config): absl::c_contains + config tests to gmock matchers - #92

Merged
helly25 merged 1 commit into
mainfrom
refactor/config-absl-contains-matchers
Jun 23, 2026
Merged

refactor(config): absl::c_contains + config tests to gmock matchers#92
helly25 merged 1 commit into
mainfrom
refactor/config-absl-contains-matchers

Conversation

@helly25

@helly25 helly25 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Follow-up to #91 (loader core), addressing two review points.

Code

config.cc replaces a hand-rolled Contains(vector, string_view) linear-search helper with absl::c_contains (range-based bool wrapper over c_find; dep @abseil-cpp//absl/algorithm:container).

Tests

All three config-package tests now assert with gmock matchers (EXPECT_THAT + ElementsAre + Field) instead of ASSERT_EQ(size) + indexed EXPECT_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_EQ users (datetime 24, exec 5, regex 4, engine 2) follow in one sweep PR next.

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
helly25 enabled auto-merge (squash) June 23, 2026 00:35
@helly25
helly25 merged commit f0b2676 into main Jun 23, 2026
5 checks passed
@helly25
helly25 deleted the refactor/config-absl-contains-matchers branch June 23, 2026 00:38
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant