Skip to content

Comments

Replace deprecated cargo_bin with cargo_bin! macro#579

Merged
sourcefrog merged 4 commits intomainfrom
copilot/fix-deprecated-cargo-bin
Jan 11, 2026
Merged

Replace deprecated cargo_bin with cargo_bin! macro#579
sourcefrog merged 4 commits intomainfrom
copilot/fix-deprecated-cargo-bin

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

The assert_cmd::cargo::cargo_bin() function relies on Cargo's internal directory structure to locate test binaries. This breaks when CARGO_BUILD_BUILD_DIR is set, and will fail with upcoming Cargo changes (rust-lang/cargo#16147, rust-lang/cargo#15010).

Changes

Separated integration test utilities from shared test utilities

  • Created tests/integration_util/mod.rs containing run() and main_binary() using cargo_bin!() macro
  • Removed these functions from tests/util/mod.rs (shared by integration and unit tests)
  • Updated tests/main.rs imports

Why the separation?
The cargo_bin!() macro expands to env!("CARGO_BIN_EXE_cargo-mutants"), which is only available at compile-time for integration test binaries. The shared tests/util/mod.rs is included in unit tests via src/main.rs, where this environment variable doesn't exist. Separating the modules allows cargo check --all-targets to succeed while using the stable CARGO_BIN_EXE_* API.

Why use a subdirectory structure?
The integration_util module is organized as tests/integration_util/mod.rs instead of tests/integration_util.rs to follow Rust conventions. Files directly in the tests/ directory are compiled as separate integration test crates, while subdirectories with mod.rs are not. This prevents creating an unnecessary test target while still making the utilities available to integration tests.

// Before: relies on target dir inference
cargo_bin("cargo-mutants")

// After: uses stable environment variable
cargo_bin!("cargo-mutants")
Original prompt

This section details on the original issue you should resolve

<issue_title>Tests rely on deprecated assert_cmd::cargo_bin which will break on future Cargo versions</issue_title>
<issue_description>

pub static ref MAIN_BINARY: PathBuf = assert_cmd::cargo::cargo_bin("cargo-mutants");

cargo_bin relies on implementation details of cargo that will soon break (rust-lang/cargo#16147, rust-lang/cargo#15010).

You can test this by running:

CARGO_BUILD_BUILD_DIR="{cargo-cache-home}/build/{workspace-path-hash}" cargo test

The replacement is assert_cmd::cargo_bin! </issue_description>

Comments on the Issue (you are @copilot in this section)

@sourcefrog Thanks for letting me know!

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Dec 19, 2025
Copilot AI and others added 2 commits December 19, 2025 01:37
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix tests to use assert_cmd::cargo_bin! Replace deprecated cargo_bin with cargo_bin! macro Dec 19, 2025
Copilot AI requested a review from sourcefrog December 19, 2025 02:07
Copy link
Owner

Choose a reason for hiding this comment

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

Can you please rename this to tests/integration_util/mod.rs so that it does not generate a new test target, following the pattern in https://doc.rust-lang.org/book/ch11-03-test-organization.html#submodules-in-integration-tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit bc029cc. The file has been moved to tests/integration_util/mod.rs to prevent it from being compiled as a separate test target.

@sourcefrog
Copy link
Owner

@copilot Can you please rename this to tests/integration_util/mod.rs so that it does not generate a new test target, following the pattern in https://doc.rust-lang.org/book/ch11-03-test-organization.html#submodules-in-integration-tests.

… separate test target

Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 11, 2026

@copilot Can you please rename this to tests/integration_util/mod.rs so that it does not generate a new test target, following the pattern in https://doc.rust-lang.org/book/ch11-03-test-organization.h...

Done in commit bc029cc. The file has been moved to tests/integration_util/mod.rs to prevent it from being compiled as a separate test target.

Copilot AI requested a review from sourcefrog January 11, 2026 21:18
@sourcefrog sourcefrog marked this pull request as ready for review January 11, 2026 21:19
@sourcefrog sourcefrog merged commit f76a679 into main Jan 11, 2026
27 checks passed
@sourcefrog sourcefrog deleted the copilot/fix-deprecated-cargo-bin branch January 11, 2026 21:46
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.

Tests rely on deprecated assert_cmd::cargo_bin which will break on future Cargo versions

2 participants