Skip to content

test(config): cover the _ZO_* env readers with shimforge - #1

Open
tanglearncode wants to merge 4 commits into
mainfrom
shimforge-config-tests
Open

tanglearncode wants to merge 4 commits into
mainfrom
shimforge-config-tests

Conversation

@tanglearncode

@tanglearncode tanglearncode commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Problem

src/config.rs has no tests. Its seven readers parse and validate real input — _ZO_MAXAGE must be a number, _ZO_DATA_DIR must be absolute, _ZO_EXCLUDE_DIRS must be valid globs — and every error path is uncovered.

The reason is the environment itself. Testing these needs a chosen value for one variable, and env::set_var is unsafe in the 2024 edition and writes to the whole process, so parallel tests read each other's values. The usual ways out are an env lock, serialized tests, or changing the functions to take parameters.

Changes

  • Add five tests for previously uncovered paths in config.rs: the _ZO_MAXAGE default, a parsed value, a non-numeric value, a relative _ZO_DATA_DIR, and the _ZO_RESOLVE_SYMLINKS opt-in.
  • Mock env::var_os per thread with shimforge instead of writing the environment. No unsafe, no lock, no serialization, and the tests run in parallel with the rest of the suite.
  • Add shimforge as a pinned dev-dependency with its lock entries, and a fork-only workflow that verifies the tests.

config.rs itself is unchanged — that is the point of the approach.

How did you test this code?

Verified on the fork: run 35046566443, green at zoxide's own MSRV, 1.88.0.

  • The five config tests run 20 times at --test-threads=8: 5 passed every time. Nothing is serialized and no environment lock is involved.
  • The full suite passes with the mocks in place: 21 tests, the 16 existing ones plus these 5.
  • Every cargo call uses --locked, so the committed lockfile is what cargo resolves, not a hand-patched approximation.
  • The project's own ci gate passes with the change: cargo fmt --check, clippy --all-features --all-targets -- -Dwarnings, cargo msrv verify, cargo udeps and nextest, all in the repo's nix shell. udeps passing also shows the new dependency is used rather than merely declared.

Unchecked: platforms other than x86-64 Linux.

Note on the dependency

shimforge is source-available under PolyForm, not an OSI license. It is free for noncommercial use, which covers a hobby project, and free for companies under 100 people and 1M USD revenue; anything above that needs a commercial license. That is a real consideration for a widely packaged project, since it reaches contributors and packagers who run the suite. This PR is a demonstration of the technique on a fork, not a request to take the dependency.

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