Skip to content

Commit b99b249

Browse files
committed
Add --jobs to test command
1 parent 21c231b commit b99b249

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

crates/tracel-xtask-macros/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,16 @@ fn get_additional_cmd_args_map() -> HashMap<&'static str, proc_macro2::TokenStre
237237
HashMap::from([(
238238
"TestCmdArgs",
239239
quote! {
240-
#[doc = r"Maximum number of parallel test."]
240+
#[doc = r"Maximum number of parallel test crates to execute."]
241241
#[arg(
242-
long = " --test-threads",
242+
long = "jobs",
243+
value_name = "NUMBER OF THREADS",
244+
required = false
245+
)]
246+
pub jobs: Option<u16>,
247+
#[doc = r"Maximum number of parallel test cases within a test crate execution."]
248+
#[arg(
249+
long = "test-threads",
243250
value_name = "NUMBER OF THREADS",
244251
required = false
245252
)]

crates/tracel-xtask/src/commands/test.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,21 @@ pub fn handle_command(args: TestCmdArgs) -> anyhow::Result<()> {
3131
exclude: args.exclude.clone(),
3232
only: args.only.clone(),
3333
threads: args.threads,
34+
jobs: args.jobs,
3435
})
3536
}),
3637
}
3738
}
3839

40+
fn push_optional_args(cmd_args: &mut Vec<String>, args: &TestCmdArgs) {
41+
if let Some(jobs) = &args.jobs {
42+
cmd_args.extend(vec!["--jobs".to_string(), jobs.to_string()]);
43+
};
44+
if let Some(threads) = &args.threads {
45+
cmd_args.extend(vec!["--".to_string(), "--test-threads".to_string(), threads.to_string()]);
46+
};
47+
}
48+
3949
pub fn run_unit(target: &Target, args: &TestCmdArgs) -> Result<()> {
4050
match target {
4151
Target::Workspace => {
@@ -48,15 +58,11 @@ pub fn run_unit(target: &Target, args: &TestCmdArgs) -> Result<()> {
4858
"--examples",
4959
"--color",
5060
"always",
51-
];
52-
let threads_str: String;
53-
if let Some(threads) = &args.threads {
54-
threads_str = threads.to_string();
55-
cmd_args.extend(vec!["--", "--test-threads", &threads_str]);
56-
};
61+
].into_iter().map(|s| s.to_string()).collect::<Vec<String>>();
62+
push_optional_args(&mut cmd_args, args);
5763
run_process_for_workspace(
5864
"cargo",
59-
cmd_args,
65+
cmd_args.iter().map(String::as_str).collect(),
6066
&args.exclude,
6167
Some(r".*target/[^/]+/deps/([^-\s]+)"),
6268
Some("Unit Tests"),
@@ -97,16 +103,12 @@ fn run_unit_test(member: &WorkspaceMember, args: &TestCmdArgs) -> Result<(), any
97103
"--color=always",
98104
"--",
99105
"--color=always",
100-
];
101-
let threads_str: String;
102-
if let Some(threads) = &args.threads {
103-
threads_str = threads.to_string();
104-
cmd_args.extend(vec!["--", "--test-threads", &threads_str]);
105-
};
106+
].into_iter().map(|s| s.to_string()).collect::<Vec<String>>();
107+
push_optional_args(&mut cmd_args, args);
106108
run_process_for_package(
107109
"cargo",
108110
&member.name,
109-
&cmd_args,
111+
&cmd_args.iter().map(String::as_str).collect(),
110112
&args.exclude,
111113
&args.only,
112114
&format!("Failed to execute unit test for '{}'", &member.name),
@@ -131,15 +133,11 @@ pub fn run_integration(target: &Target, args: &TestCmdArgs) -> anyhow::Result<()
131133
"test_*",
132134
"--color",
133135
"always",
134-
];
135-
let threads_str: String;
136-
if let Some(threads) = &args.threads {
137-
threads_str = threads.to_string();
138-
cmd_args.extend(vec!["--", "--test-threads", &threads_str]);
139-
};
136+
].into_iter().map(|s| s.to_string()).collect::<Vec<String>>();
137+
push_optional_args(&mut cmd_args, args);
140138
run_process_for_workspace(
141139
"cargo",
142-
cmd_args,
140+
cmd_args.iter().map(String::as_str).collect(),
143141
&args.exclude,
144142
Some(r".*target/[^/]+/deps/([^-\s]+)"),
145143
Some("Integration Tests"),
@@ -178,16 +176,12 @@ fn run_integration_test(member: &WorkspaceMember, args: &TestCmdArgs) -> Result<
178176
&member.name,
179177
"--color",
180178
"always",
181-
];
182-
let threads_str: String;
183-
if let Some(threads) = &args.threads {
184-
threads_str = threads.to_string();
185-
cmd_args.extend(vec!["--", "--test-threads", &threads_str]);
186-
};
179+
].into_iter().map(|s| s.to_string()).collect::<Vec<String>>();
180+
push_optional_args(&mut cmd_args, args);
187181
run_process_for_package(
188182
"cargo",
189183
&member.name,
190-
&cmd_args,
184+
&cmd_args.iter().map(String::as_str).collect(),
191185
&args.exclude,
192186
&args.only,
193187
&format!("Failed to execute integration test for '{}'", &member.name),

xtask/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition = "2021"
77
strum = { workspace = true }
88
log = { workspace = true }
99
tracel-xtask = { path = "../crates/tracel-xtask" }
10-
rstest.workspace = true
1110

1211
[dev-dependencies]
1312
rstest = { workspace = true }

xtask/src/commands/validate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub fn handle_command() -> anyhow::Result<()> {
2828
exclude: exclude.clone(),
2929
only: only.clone(),
3030
threads: None,
31+
jobs: None,
3132
command: Some(TestSubCommand::All),
3233
})?;
3334

0 commit comments

Comments
 (0)