test: replace custom cfg with TEST_SKIP environment variable#372
test: replace custom cfg with TEST_SKIP environment variable#372
cfg with TEST_SKIP environment variable#372Conversation
…` env var The custom cfg flag required `RUSTFLAGS` which forced full recompilation just to skip a test. The new `TEST_SKIP` env var passes `--skip` to the test binary at runtime, avoiding any recompilation. https://claude.ai/code/session_01UBzLwHNmqEC2SafFKjEqYz
Performance Regression Reportscommit: 35df1aa There are no regressions. |
There was a problem hiding this comment.
Pull request overview
This PR migrates the repo’s “skip certain integration tests” workflow from compile-time custom --cfg pdu_test_skip_* flags to a runtime TEST_SKIP environment variable, aiming to avoid recompilation when skipping environment-dependent tests.
Changes:
- Add
TEST_SKIPhandling totest.sh, translating names into libtest--skiparguments. - Update the
fs_errorstest hint to referenceTEST_SKIPand remove the custom cfg-based ignore. - Remove the
Cargo.tomlunexpected_cfgsallowance and update developer/AI docs to the new mechanism.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/cli_errors.rs | Removes cfg-based ignore and updates the root-run hint to use TEST_SKIP. |
| test.sh | Parses TEST_SKIP and conditionally appends libtest --skip args to cargo test. |
| template/ai-instructions/shared.md | Updates guidance to reference TEST_SKIP instead of custom cfg flags. |
| README.md | Documents the new TEST_SKIP environment variable for test.sh. |
| Cargo.toml | Removes unexpected_cfgs configuration for the deleted custom cfg. |
| CONTRIBUTING.md | Updates test-skipping guidance to prefer TEST_SKIP for runtime-environment skips. |
| CLAUDE.md | Syncs AI instructions to reference TEST_SKIP. |
| AGENTS.md | Syncs AI instructions to reference TEST_SKIP. |
| .github/copilot-instructions.md | Syncs AI instructions to reference TEST_SKIP. |
tests/cli_errors.rs
Outdated
| "{}\n{}", | ||
| "error: This test must not be run as root because running with elevated privileges would affect its accuracy.", | ||
| "hint: Either run this test as a non-root user or set `RUSTFLAGS='--cfg pdu_test_skip_fs_errors'` to skip this test.", | ||
| "hint: Either run this test as a non-root user or set `TEST_SKIP='fs_errors'` to skip this test.", |
There was a problem hiding this comment.
The panic hint suggests setting TEST_SKIP='fs_errors', but TEST_SKIP is only interpreted by ./test.sh (and is otherwise ignored by cargo test). Consider adjusting the hint to explicitly mention rerunning via ./test.sh (or alternatively, check TEST_SKIP within the test and return early when it contains fs_errors) so the guidance works regardless of how the test is invoked.
| "hint: Either run this test as a non-root user or set `TEST_SKIP='fs_errors'` to skip this test.", | |
| "hint: Either run this test as a non-root user or rerun via `TEST_SKIP='fs_errors' ./test.sh` to skip this test.", |
The TEST_SKIP variable is only interpreted by test.sh, not by cargo test directly. Update the hint to say "rerun via ./test.sh" so users know exactly how to invoke it. https://claude.ai/code/session_01UBzLwHNmqEC2SafFKjEqYz
Summary
This PR replaces the custom
--cfg pdu_test_skip_*mechanism with a simplerTEST_SKIPenvironment variable for skipping tests at runtime. This avoids unnecessary recompilation when tests need to be skipped based on runtime conditions.Key Changes
TEST_SKIPenvironment variable that accepts space-separated test names and passes them tocargo testvia--skipflags#[cfg_attr(pdu_test_skip_fs_errors, ignore)]and updated the error hint to useTEST_SKIP='fs_errors'instead ofRUSTFLAGS='--cfg pdu_test_skip_fs_errors'[lints.rust]section that declared thepdu_test_skip_fs_errorscfg as expectedTEST_SKIPfor runtime environment conditions and removed the example using custom cfg flagsTEST_SKIPinstead ofRUSTFLAGSand custom cfg flagsImplementation Details
The
test.shscript now:TEST_SKIPenvironment variable as a space-separated list--skipargumentcargo testonly when skip arguments are presentThis approach allows tests to remain compiled on all configurations (catching type errors early) while being skipped at runtime based on environment conditions, without requiring recompilation.
https://claude.ai/code/session_01UBzLwHNmqEC2SafFKjEqYz