cargo-wdk: gate mockall/mockall_double behind cfg(test), move to dev-… - #719
cargo-wdk: gate mockall/mockall_double behind cfg(test), move to dev-…#719Ksenox (ksenoxhq) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates cargo-wdk to ensure mockall and mockall_double are only pulled in for tests, aligning the provider/consumer mocking pattern with cfg(test) gating so production builds don’t depend on mock crates.
Changes:
- Moved
mockallandmockall_doublefrom[dependencies]to[dev-dependencies]incrates/cargo-wdk/Cargo.toml. - Gated provider-side
mockall::automockusage behind#[cfg(test)]and applied#[cfg_attr(test, automock)]on provider impl blocks. - Gated consumer-side
mockall_double::doubleusage behind#[cfg(test)]and applied#[cfg_attr(test, double)]to provider imports.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/cargo-wdk/Cargo.toml | Moves mock crates to dev-dependencies to avoid shipping them in non-test builds. |
| crates/cargo-wdk/src/providers/exec.rs | Gates automock import and uses cfg_attr(test, automock) for test-only mock generation. |
| crates/cargo-wdk/src/providers/fs.rs | Gates automock import and uses cfg_attr(test, automock) for test-only mock generation. |
| crates/cargo-wdk/src/providers/metadata.rs | Gates automock import and uses cfg_attr(test, automock) for test-only mock generation. |
| crates/cargo-wdk/src/providers/wdk_build.rs | Gates automock import and uses cfg_attr(test, automock) for test-only mock generation. |
| crates/cargo-wdk/src/cli.rs | Gates double import and uses cfg_attr(test, double) for test-only provider doubling. |
| crates/cargo-wdk/src/actions/new/mod.rs | Gates double import and uses cfg_attr(test, double) for test-only provider doubling. |
| crates/cargo-wdk/src/actions/clean/mod.rs | Gates double import and uses cfg_attr(test, double) for test-only provider doubling. |
| crates/cargo-wdk/src/actions/build/mod.rs | Gates double import and uses cfg_attr(test, double) for test-only provider doubling. |
| crates/cargo-wdk/src/actions/build/build_task.rs | Gates double import and uses cfg_attr(test, double) for test-only provider doubling. |
| crates/cargo-wdk/src/actions/build/package_task.rs | Gates double import and uses cfg_attr(test, double) for test-only provider doubling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| use anyhow::Result; | ||
| #[cfg(test)] | ||
| use mockall::automock; |
There was a problem hiding this comment.
Fixed in f49f4af — gated the clippy::ref_option_ref allow behind cfg_attr(test, ...) in exec.rs, since it's only needed for the automock-generated mock code which is now test-only.
…dependencies. Fixes microsoft#651
b663f91 to
cd6eb76
Compare
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Suppressed comments (3)
crates/cargo-wdk/src/providers/wdk_build.rs:11
- Now that
automockis only enabled undercfg(test), the module-wide#![allow(dead_code)]and#![allow(clippy::unused_self)]likely no longer need to apply to non-test builds. Consider changing them to#![cfg_attr(test, allow(...))]so production builds still benefit from these warnings.
// The intellisense confusion seems to come from automock
#![allow(dead_code)]
#![allow(clippy::unused_self)]
#[cfg(test)]
use mockall::automock;
crates/cargo-wdk/src/actions/build/mod.rs:28
cfg(test)is not enabled when this crate is compiled as a dependency of an integration test crate, so integration tests won’t get#[double]/generated doubles with this approach. If integration tests need doubles, consider gating doubles behind a Cargo feature (e.g.cfg_attr(any(test, feature = \"mocks\"), double)) and enabling that feature for integration tests.
#[cfg(test)]
use mockall_double::double;
crates/cargo-wdk/src/actions/build/mod.rs:38
cfg(test)is not enabled when this crate is compiled as a dependency of an integration test crate, so integration tests won’t get#[double]/generated doubles with this approach. If integration tests need doubles, consider gating doubles behind a Cargo feature (e.g.cfg_attr(any(test, feature = \"mocks\"), double)) and enabling that feature for integration tests.
#[cfg_attr(test, double)]
use crate::providers::{exec::CommandExec, fs::Fs, metadata::Metadata, wdk_build::WdkBuild};
| #[cfg(test)] | ||
| use mockall_double::double; |
| #[cfg_attr(test, double)] | ||
| use crate::providers::{exec::CommandExec, fs::Fs, metadata::Metadata, wdk_build::WdkBuild}; |
Moves mockall and mockall_double from [dependencies] to [dev-dependencies] in cargo-wdk, and gates their usage behind cfg(test) / cfg_attr(test, ...) in provider modules (exec.rs, wdk_build.rs, metadata.rs, fs.rs) and consumer modules (build/mod.rs, build_task.rs, package_task.rs, actions/new/mod.rs, actions/clean/mod.rs, cli.rs), following the pattern from PR #476.
Verified:
Fixes #651