Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/cargo-wdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ clap = { features = ["derive"], workspace = true }
clap-cargo = { features = ["cargo_metadata"], workspace = true }
clap-verbosity-flag.workspace = true
include_dir.workspace = true
mockall.workspace = true
mockall_double.workspace = true
serde_json.workspace = true
thiserror.workspace = true
tracing.workspace = true
Expand All @@ -33,6 +31,8 @@ windows = { features = [
[dev-dependencies]
assert_cmd.workspace = true
assert_fs.workspace = true
mockall.workspace = true
mockall_double.workspace = true
predicates.workspace = true
regex.workspace = true
sha2.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/cargo-wdk/src/actions/build/build_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ use std::path::{Path, PathBuf};
use anyhow::Result;
use cargo_metadata::Message;
use clap_cargo::Features;
#[cfg(test)]
use mockall_double::double;
use tracing::debug;
use wdk_build::CpuArchitecture;

use super::{Profile, error::BuildTaskError, features_to_cargo_args, to_target_triple};
#[double]
#[cfg_attr(test, double)]
use crate::providers::exec::CommandExec;
use crate::{providers::error::CommandError, trace};

Expand Down
3 changes: 2 additions & 1 deletion crates/cargo-wdk/src/actions/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use build_task::{BuildTask, BuildTaskParams};
use cargo_metadata::{CrateType, Message, Metadata as CargoMetadata, Package, TargetKind};
use clap_cargo::Features;
use error::BuildActionError;
#[cfg(test)]
use mockall_double::double;
Comment on lines +27 to 28
use package_task::{PackageTask, PackageTaskParams};
pub use package_task::{SignMode, TargetPlatform};
Expand All @@ -33,7 +34,7 @@ use wdk_build::{
metadata::{TryFromCargoMetadataError, Wdk},
};

#[double]
#[cfg_attr(test, double)]
use crate::providers::{exec::CommandExec, fs::Fs, metadata::Metadata, wdk_build::WdkBuild};
Comment on lines +37 to 38

const X86_64_TARGET_TRIPLE_NAME: &str = "x86_64-pc-windows-msvc";
Expand Down
3 changes: 2 additions & 1 deletion crates/cargo-wdk/src/actions/build/package_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::{
result::Result,
};

#[cfg(test)]
use mockall_double::double;
use tracing::{debug, info, warn};
use wdk_build::{CpuArchitecture, DriverConfig};
Expand All @@ -26,7 +27,7 @@ use windows::{
core::{Error as WinError, PCSTR},
};

#[double]
#[cfg_attr(test, double)]
use crate::providers::{exec::CommandExec, fs::Fs, wdk_build::WdkBuild};
use crate::{actions::build::error::PackageTaskError, providers::error::FileError};

Expand Down
3 changes: 2 additions & 1 deletion crates/cargo-wdk/src/actions/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ use std::path::{Path, PathBuf, absolute};

use anyhow::Result;
use error::CleanActionError;
#[cfg(test)]
use mockall_double::double;
use tracing::{debug, error as err, info};

#[double]
#[cfg_attr(test, double)]
use crate::providers::{exec::CommandExec, fs::Fs};
use crate::trace;

Expand Down
3 changes: 2 additions & 1 deletion crates/cargo-wdk/src/actions/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ use std::{
use clap_verbosity_flag::Verbosity;
use error::NewActionError;
use include_dir::{Dir, include_dir};
#[cfg(test)]
use mockall_double::double;
use tracing::{debug, info};

#[double]
#[cfg_attr(test, double)]
use crate::providers::{exec::CommandExec, fs::Fs};
use crate::trace;

Expand Down
3 changes: 2 additions & 1 deletion crates/cargo-wdk/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use anyhow::Result;
use clap::{ArgGroup, Args, CommandFactory, Parser, Subcommand, ValueEnum, error::ErrorKind};
use clap_cargo::Features;
use clap_verbosity_flag::Verbosity;
#[cfg(test)]
use mockall_double::double;
use wdk_build::CpuArchitecture;

Expand All @@ -17,7 +18,7 @@ use crate::actions::{
clean::CleanAction,
new::{DriverType, KMDF_STR, NewAction, UMDF_STR, WDM_STR},
};
#[double]
#[cfg_attr(test, double)]
use crate::providers::{exec::CommandExec, fs::Fs, metadata::Metadata, wdk_build::WdkBuild};

const ABOUT_STRING: &str = "cargo-wdk is a cargo extension that can be used to create and build \
Expand Down
5 changes: 3 additions & 2 deletions crates/cargo-wdk/src/providers/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! enables mocking the `CommandExec` struct for unit testing.

// Suppression added for mockall as it generates mocks with env_vars: &Option
#![allow(clippy::ref_option_ref)]
#![cfg_attr(test, allow(clippy::ref_option_ref))]
// Warns the run method is not used, however it is used.
// The intellisense confusion seems to come from automock
#![allow(dead_code)]
Expand All @@ -19,6 +19,7 @@ use std::{
};

use anyhow::Result;
#[cfg(test)]
use mockall::automock;
Comment on lines 21 to 23

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

use tracing::debug;

Expand All @@ -28,7 +29,7 @@ use super::error::CommandError;
#[derive(Debug, Default)]
pub struct CommandExec {}

#[automock]
#[cfg_attr(test, automock)]
impl CommandExec {
// The `'a` lifetime is required by mockall's `#[automock]` to generate the
// mock impl
Expand Down
3 changes: 2 additions & 1 deletion crates/cargo-wdk/src/providers/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::{
path::{Path, PathBuf},
};

#[cfg(test)]
use mockall::automock;

use super::error::FileError;
Expand All @@ -37,7 +38,7 @@ pub struct DirEntryInfo {
#[derive(Default)]
pub struct Fs {}

#[automock]
#[cfg_attr(test, automock)]
impl Fs {
pub fn copy(&self, src: &Path, dest: &Path) -> Result<u64, FileError> {
copy(src, dest).map_err(|e| FileError::CopyError(src.to_owned(), dest.to_owned(), e))
Expand Down
3 changes: 2 additions & 1 deletion crates/cargo-wdk/src/providers/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
use std::path::Path;

use clap_cargo::Features;
#[cfg(test)]
use mockall::automock;

#[derive(Default)]
pub struct Metadata {}

#[automock]
#[cfg_attr(test, automock)]
impl Metadata {
/// Get the Cargo metadata at a given path.
///
Expand Down
3 changes: 2 additions & 1 deletion crates/cargo-wdk/src/providers/wdk_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
// The intellisense confusion seems to come from automock
#![allow(dead_code)]
#![allow(clippy::unused_self)]
#[cfg(test)]
use mockall::automock;

/// Provides limited access to wdk-build crate methods
#[derive(Default)]
pub struct WdkBuild {}

#[automock]
#[cfg_attr(test, automock)]
impl WdkBuild {
pub fn detect_wdk_build_number(&self) -> Result<u32, wdk_build::ConfigError> {
wdk_build::detect_wdk_build_number()
Expand Down