OSDK check and clippy with cfg(ktest)

This commit is contained in:
Zhang Junyang
2024-08-15 15:17:59 +08:00
committed by Tate, Hongliang Tian
parent be3492d7f0
commit d76c7a5b1e
16 changed files with 48 additions and 39 deletions

View File

@ -49,9 +49,9 @@ pub fn main() {
OsdkSubcommand::Test(test_args) => {
execute_test_command(&load_config(&test_args.common_args), test_args);
}
OsdkSubcommand::Check(args) => execute_forwarded_command("check", &args.args),
OsdkSubcommand::Clippy(args) => execute_forwarded_command("clippy", &args.args),
OsdkSubcommand::Doc(args) => execute_forwarded_command("doc", &args.args),
OsdkSubcommand::Check(args) => execute_forwarded_command("check", &args.args, true),
OsdkSubcommand::Clippy(args) => execute_forwarded_command("clippy", &args.args, true),
OsdkSubcommand::Doc(args) => execute_forwarded_command("doc", &args.args, false),
}
}

View File

@ -16,8 +16,10 @@ pub use self::{
use crate::arch::get_default_arch;
/// Execute the forwarded cargo command with args containing the subcommand and its arguments.
pub fn execute_forwarded_command(subcommand: &str, args: &Vec<String>) -> ! {
/// Execute the forwarded cargo command with arguments.
///
/// The `cfg_ktest` parameter controls whether `cfg(ktest)` is enabled.
pub fn execute_forwarded_command(subcommand: &str, args: &Vec<String>, cfg_ktest: bool) -> ! {
let mut cargo = util::cargo();
cargo.arg(subcommand).args(util::COMMON_CARGO_ARGS);
if !args.contains(&"--target".to_owned()) {
@ -27,6 +29,11 @@ pub fn execute_forwarded_command(subcommand: &str, args: &Vec<String>) -> ! {
let env_rustflags = std::env::var("RUSTFLAGS").unwrap_or_default();
let rustflags = env_rustflags + " --check-cfg cfg(ktest)";
let rustflags = if cfg_ktest {
rustflags + " --cfg ktest"
} else {
rustflags
};
cargo.env("RUSTFLAGS", rustflags);

View File

@ -221,9 +221,7 @@ mod tests {
macro_rules! gen_test_case {
() => {{
fn dummy_fn() {
()
}
fn dummy_fn() {}
let mut tree = KtestTree::new();
let new = |m: &'static str, f: &'static str, p: &'static str| {
KtestItem::new(
@ -295,7 +293,7 @@ mod tests {
for mov in crate_.iter() {
let module = mov;
for test in module.iter() {
collection.push(&test);
collection.push(test);
}
}
}