feat: add text-matching assertions (expect_matches, expect_output_contains, expect_pcre_matches); bump to 0.5.0 - #23
Merged
Conversation
helly25
force-pushed
the
feat/expect-matches-output-contains
branch
from
July 2, 2026 22:14
e516dd2 to
6aed53e
Compare
Add six new matchers for asserting on captured (multi-line) command output, closing the gap that forced users to hand-roll `printf '%s' "$out" | grep -qE ...` pipelines - a footgun under `set -o pipefail` (which bashtest mandates): `grep -q` exits on first match, the producer takes SIGPIPE, and pipefail turns that into a flaky failure. * expect_output_contains / expect_output_not_contains: literal substring via `[[ == *x* ]]` (glob metacharacters inert). * expect_matches / expect_not_matches: ERE via bash built-in `[[ =~ ]]` - zero subprocess, so it cannot SIGPIPE. `^`/`$` anchor the whole text, not individual lines (documented). * expect_pcre_matches / expect_pcre_not_matches: PCRE via an external tool (grep -P, ggrep -P, pcre2grep, or pcregrep; detected once and cached), fed through a here-string so no pipe is involved. Fails with an actionable install hint when no backend is available. Also document the SIGPIPE-under-pipefail pitfall in the README and extend the built-in help output.
helly25
force-pushed
the
feat/expect-matches-output-contains
branch
from
July 2, 2026 22:15
6aed53e to
9c1a727
Compare
Fab-Cat
approved these changes
Jul 2, 2026
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.
Why
bashtest had no matcher for "does this (multi-line) captured text match a substring/regex" — the existing string matchers are exact-equality (
expect_eq/expect_ne) and array-membership (expect_contains). That gap forces users of CLI-output tests to hand-rollprintf '%s' "$out" | grep -qE ..., which is a footgun underset -o pipefail(whichbashtest.shsets and its examples mandate for test scripts):grep -qexits on the first match, the producer takes SIGPIPE, and pipefail flips a passing test into a flaky failure on large output.What
Six new matchers, all following the existing matcher conventions (verbose-on-success,
_BASHTEST_HAS_ERROR+ actionable stderr on failure, 50-char display truncation):expect_output_contains/expect_output_not_contains[[ == *x* ]]expect_matches/expect_not_matches[[ =~ ]](ERE)^/$anchor the whole text, not per line (documented in the help text and doc comments)expect_pcre_matches/expect_pcre_not_matchesgrep -P→ggrep -P→pcre2grep→pcregreponce and caches; text is fed via a here-string (no pipe); fails with an install hint when no backend existsDesign notes:
expect_matchesstays dependency-free/portable, and PCRE (\d, lookahead, non-greedy) is an explicit opt-in.output_prefix on the substring matchers avoids collision with the array-membershipexpect_contains.bazel run //bashtest:bashtest_help.Backwards-compatible API addition → minor bump to 0.5.0 (MODULE.bazel + CHANGELOG).
Testing
test::functions inbashtest_test.shmirroring the existing pattern (positive/negative cases, runner-counter integrity checks). PCRE cases gate on backend availability: positive-path assertions where a backend exists (Linux CI), graceful-failure assertion on stock macOS (BSD grep has no-P).^SECONDagainst$'a\nSECOND\nc'correctly does not match), literal-glob inertness, and the positive PCRE path viapcre2grep.bazel test //...: 3/3 pass. shellcheck 0.11.0 clean; all pre-commit hooks pass.