Skip to content

refactor(test): prefer cfg_attr(ignore) over cfg for conditional test skipping#369

Merged
KSXGitHub merged 3 commits into
masterfrom
claude/fix-test-skip-attributes-8qzK2
Mar 23, 2026
Merged

refactor(test): prefer cfg_attr(ignore) over cfg for conditional test skipping#369
KSXGitHub merged 3 commits into
masterfrom
claude/fix-test-skip-attributes-8qzK2

Conversation

@KSXGitHub

Copy link
Copy Markdown
Owner

Summary

This PR updates the codebase to follow a better practice for conditionally skipping tests: using #[cfg_attr(..., ignore)] instead of #[cfg(...)] to ensure tests compile on all platforms while being skipped at runtime when conditions aren't met.

Key Changes

  • Documentation: Added comprehensive guidance in CONTRIBUTING.md explaining when to use #[cfg_attr(..., ignore)] vs #[cfg(...)] for tests, with clear examples of good and bad patterns
  • Test module visibility: Removed #[cfg(unix)] from the test_remove_overlapping_paths module declaration in src/app/overlapping_arguments.rs so the module compiles on all platforms
  • Individual test attributes: Added #[cfg_attr(not(unix), ignore = "only one path separator style is tested")] to 7 tests in src/app/overlapping_arguments/test_remove_overlapping_paths.rs that use hardcoded Unix paths but don't reference Unix-only types
  • Feature-gated test: Converted fs_errors test in tests/cli_errors.rs from #[cfg(not(pdu_test_skip_fs_errors))] to #[cfg_attr(pdu_test_skip_fs_errors, ignore = "...")], allowing it to compile in all configurations
  • Cleanup: Removed unnecessary #[cfg(not(pdu_test_skip_fs_errors))] guards from imports and helper functions in tests/cli_errors.rs that are now always available
  • AI instructions: Updated all AI instruction files (CLAUDE.md, AGENTS.md, shared.md, copilot-instructions.md) to include the new test skipping guideline

Implementation Details

The key principle: tests should compile everywhere to catch type errors and regressions early, but skip at runtime when conditions aren't met. Use #[cfg] on tests only when the code literally cannot compile under certain conditions (e.g., references platform-specific types that don't exist).

All changes maintain backward compatibility while improving test coverage visibility across all platforms.

https://claude.ai/code/session_0184ceZayyCwvK7PEF9iB7K3

claude added 2 commits March 23, 2026 02:00
…test skipping

Use `#[cfg_attr(..., ignore = "reason")]` instead of `#[cfg(not(...))]` on
tests that can still compile under the skipped condition. This keeps the
tests compiled on all configurations, catching type errors early while
only skipping execution at runtime.

Changes:
- cli_errors::fs_errors: replace `#[cfg(not(pdu_test_skip_fs_errors))]`
  with `#[cfg_attr(pdu_test_skip_fs_errors, ignore)]`; remove the same
  gate from its imports and helper function
- test_remove_overlapping_paths: remove `#[cfg(unix)]` from module
  declaration; add `#[cfg_attr(not(unix), ignore)]` to each test
- Add "Conditional Test Skipping" section to CONTRIBUTING.md
- Add guideline bullet to AI instruction templates

https://claude.ai/code/session_0184ceZayyCwvK7PEF9iB7K3
- Change ignore reason to "only one path separator style is tested"
- Reorder attributes: place #[cfg_attr(..., ignore)] below #[test]
- Revert hint message in fs_errors back to "skip"
- Soften "Always" to "Prefer" for reason strings in CONTRIBUTING.md
- Rephrase CONTRIBUTING.md to mention tests are "still compiled"

https://claude.ai/code/session_0184ceZayyCwvK7PEF9iB7K3

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors conditional test skipping to prefer #[cfg_attr(..., ignore = "...")] over #[cfg(...)], so tests still compile across configurations/platforms while being skipped at runtime when appropriate.

Changes:

  • Documented the recommended patterns for conditional test skipping in CONTRIBUTING.md (with good/bad examples).
  • Updated unit/integration tests to compile unconditionally where possible, switching from #[cfg(not(...))] to #[cfg_attr(..., ignore = "...")].
  • Propagated the new guideline into the AI instruction templates and generated instruction files.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/cli_errors.rs Converts fs_errors to cfg_attr(..., ignore) and removes now-unnecessary cfg(not(...)) gating around supporting imports/helpers.
src/app/overlapping_arguments.rs Removes #[cfg(unix)] from the test module so it compiles on all platforms under cfg(test).
src/app/overlapping_arguments/test_remove_overlapping_paths.rs Adds cfg_attr(not(unix), ignore = "...") to Unix-path-style tests to keep them compiling everywhere but skipped where not applicable.
CONTRIBUTING.md Adds a dedicated section clarifying when to use #[cfg] vs #[cfg_attr(..., ignore)] for tests.
template/ai-instructions/shared.md Adds the new conditional test skipping guideline to the shared AI-instructions template.
CLAUDE.md Updates generated AI instructions to include the new guideline.
AGENTS.md Updates generated AI instructions to include the new guideline.
.github/copilot-instructions.md Updates generated AI instructions to include the new guideline.

@github-actions

github-actions Bot commented Mar 23, 2026

Copy link
Copy Markdown

Performance Regression Reports

commit: 2a5a78e

There are no regressions.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@KSXGitHub KSXGitHub marked this pull request as ready for review March 23, 2026 03:30
@KSXGitHub KSXGitHub merged commit 8cb61b0 into master Mar 23, 2026
17 checks passed
@KSXGitHub KSXGitHub deleted the claude/fix-test-skip-attributes-8qzK2 branch March 23, 2026 03:36
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.

3 participants