Skip to content

Commit fca6dbd

Browse files
committed
Add tests for fixed bugs
1 parent 0da0a21 commit fca6dbd

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

src/bootstrap/builder.rs

+4
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,11 @@ impl StepDescription {
348348
eprintln!(
349349
"note: if you are adding a new Step to bootstrap itself, make sure you register it with `describe!`"
350350
);
351+
#[cfg(not(test))]
351352
std::process::exit(1);
353+
#[cfg(test)]
354+
// so we can use #[should_panic]
355+
panic!()
352356
}
353357
}
354358
}

src/bootstrap/builder/tests.rs

+36-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ use crate::config::{Config, TargetSelection};
33
use std::thread;
44

55
fn configure(cmd: &str, host: &[&str], target: &[&str]) -> Config {
6-
let mut config = Config::parse(&[cmd.to_owned()]);
6+
configure_with_args(&[cmd.to_owned()], host, target)
7+
}
8+
9+
fn configure_with_args(cmd: &[String], host: &[&str], target: &[&str]) -> Config {
10+
let mut config = Config::parse(cmd);
711
// don't save toolstates
812
config.save_toolstates = None;
913
config.dry_run = true;
@@ -46,11 +50,39 @@ fn run_build(paths: &[PathBuf], config: Config) -> Cache {
4650
builder.cache
4751
}
4852

53+
fn check_cli<const N: usize>(paths: [&str; N]) {
54+
run_build(
55+
&paths.map(PathBuf::from),
56+
configure_with_args(&paths.map(String::from), &["A"], &["A"]),
57+
);
58+
}
59+
60+
#[test]
61+
fn test_valid() {
62+
// make sure multi suite paths are accepted
63+
check_cli(["test", "src/test/ui/attr-start.rs", "src/test/ui/attr-shebang.rs"]);
64+
}
65+
66+
#[test]
67+
#[should_panic]
68+
fn test_invalid() {
69+
// make sure that invalid paths are caught, even when combined with valid paths
70+
check_cli(["test", "library/std", "x"]);
71+
}
72+
4973
#[test]
5074
fn test_intersection() {
51-
let set = PathSet::Set(["library/core", "library/alloc", "library/std"].into_iter().map(TaskPath::parse).collect());
52-
let subset = set.intersection(&[Path::new("library/core"), Path::new("library/alloc"), Path::new("library/stdarch")], None);
53-
assert_eq!(subset, PathSet::Set(["library/core", "library/alloc"].into_iter().map(TaskPath::parse).collect()));
75+
let set = PathSet::Set(
76+
["library/core", "library/alloc", "library/std"].into_iter().map(TaskPath::parse).collect(),
77+
);
78+
let mut command_paths =
79+
vec![Path::new("library/core"), Path::new("library/alloc"), Path::new("library/stdarch")];
80+
let subset = set.intersection_removing_matches(&mut command_paths, None);
81+
assert_eq!(
82+
subset,
83+
PathSet::Set(["library/core", "library/alloc"].into_iter().map(TaskPath::parse).collect())
84+
);
85+
assert_eq!(command_paths, vec![Path::new("library/stdarch")]);
5486
}
5587

5688
#[test]

0 commit comments

Comments
 (0)