Skip to content

Commit 62c71cc

Browse files
committed
improve --compare-mode error handling
- show the erroneous value - show the valid values
1 parent f33a8c6 commit 62c71cc

File tree

1 file changed

+12
-5
lines changed
  • src/tools/compiletest/src

1 file changed

+12
-5
lines changed

src/tools/compiletest/src/lib.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ use walkdir::WalkDir;
3737

3838
use self::header::{EarlyProps, make_test_description};
3939
use crate::common::{
40-
Config, Mode, PassMode, TestPaths, UI_EXTENSIONS, expected_output_path, output_base_dir,
41-
output_relative_path,
40+
CompareMode, Config, Mode, PassMode, TestPaths, UI_EXTENSIONS, expected_output_path,
41+
output_base_dir, output_relative_path,
4242
};
4343
use crate::header::HeadersCache;
4444
use crate::util::logv;
@@ -273,6 +273,15 @@ pub fn parse_config(args: Vec<String>) -> Config {
273273
} else {
274274
matches.free.clone()
275275
};
276+
let compare_mode = matches.opt_str("compare-mode").map(|s| {
277+
s.parse().unwrap_or_else(|_| {
278+
let variants: Vec<_> = CompareMode::STR_VARIANTS.iter().copied().collect();
279+
panic!(
280+
"`{s}` is not a valid value for `--compare-mode`, it should be one of: {}",
281+
variants.join(", ")
282+
);
283+
})
284+
});
276285
Config {
277286
bless: matches.opt_present("bless"),
278287
compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")),
@@ -342,9 +351,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
342351
only_modified: matches.opt_present("only-modified"),
343352
color,
344353
remote_test_client: matches.opt_str("remote-test-client").map(PathBuf::from),
345-
compare_mode: matches
346-
.opt_str("compare-mode")
347-
.map(|s| s.parse().expect("invalid --compare-mode provided")),
354+
compare_mode,
348355
rustfix_coverage: matches.opt_present("rustfix-coverage"),
349356
has_html_tidy,
350357
has_enzyme,

0 commit comments

Comments
 (0)