Skip to content

Commit 993b990

Browse files
committed
Unrolled build for #161312 in rollup 162667
Rollup merge of #161312 - joshtriplett:libtest-multi, r=clarfonthey libtest: Allow passing --test-threads and --color multiple times, with later arguments overriding earlier Cargo would like to be able to pass these arguments, without breaking the ability for the user to do the same and override cargo's value. Currently, the option only allows one instance, failing if it sees multiple. Accept `--test-threads=N` and `--color=...` multiple times, and have the last instance win.
2 parents 0fc1413 + ef65ece commit 993b990

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

‎library/test/src/cli.rs‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn optgroups() -> getopts::Options {
6666
"don't capture stdout/stderr of each \
6767
task, allow printing directly",
6868
)
69-
.optopt(
69+
.optmulti(
7070
"",
7171
"test-threads",
7272
"Number of threads used for running tests \
@@ -87,7 +87,7 @@ fn optgroups() -> getopts::Options {
8787
Alias to --format=terse",
8888
)
8989
.optflag("", "exact", "Exactly match filters rather than by substring")
90-
.optopt(
90+
.optmulti(
9191
"",
9292
"color",
9393
"Configure coloring of output:
@@ -383,8 +383,9 @@ fn get_shuffle_seed(matches: &getopts::Matches, allow_unstable: bool) -> OptPart
383383
}
384384

385385
fn get_test_threads(matches: &getopts::Matches) -> OptPartRes<Option<usize>> {
386-
let test_threads = match matches.opt_str("test-threads") {
387-
Some(n_str) => match n_str.parse::<usize>() {
386+
let mut last_test_threads = None;
387+
for n_str in matches.opt_strs("test-threads") {
388+
last_test_threads = match n_str.parse::<usize>() {
388389
Ok(0) => return Err("argument for --test-threads must not be 0".to_string()),
389390
Ok(n) => Some(n),
390391
Err(e) => {
@@ -393,11 +394,10 @@ fn get_test_threads(matches: &getopts::Matches) -> OptPartRes<Option<usize>> {
393394
(error: {e})"
394395
));
395396
}
396-
},
397-
None => None,
398-
};
397+
};
398+
}
399399

400-
Ok(test_threads)
400+
Ok(last_test_threads)
401401
}
402402

403403
fn get_format(
@@ -433,20 +433,21 @@ fn get_format(
433433
}
434434

435435
fn get_color_config(matches: &getopts::Matches) -> OptPartRes<ColorConfig> {
436-
let color = match matches.opt_str("color").as_deref() {
437-
Some("auto") | None => ColorConfig::AutoColor,
438-
Some("always") => ColorConfig::AlwaysColor,
439-
Some("never") => ColorConfig::NeverColor,
440-
441-
Some(v) => {
442-
return Err(format!(
443-
"argument for --color must be auto, always, or never (was \
444-
{v})"
445-
));
446-
}
447-
};
436+
let mut last_color = ColorConfig::AutoColor;
437+
for color in matches.opt_strs("color") {
438+
last_color = match color.as_str() {
439+
"auto" => ColorConfig::AutoColor,
440+
"always" => ColorConfig::AlwaysColor,
441+
"never" => ColorConfig::NeverColor,
442+
v => {
443+
return Err(format!(
444+
"argument for --color must be auto, always, or never (was {v})"
445+
));
446+
}
447+
};
448+
}
448449

449-
Ok(color)
450+
Ok(last_color)
450451
}
451452

452453
fn get_nocapture(matches: &getopts::Matches) -> OptPartRes<bool> {

0 commit comments

Comments
 (0)