Skip to content

Commit 95d0b9e

Browse files
committed
Auto merge of #49729 - collin5:b48483, r=Mark-Simulacrum
./x.py test should be able to run individual tests Allows user to be able to run individual tests by specifying filename i.e `./x.py test src/test/run-pass/foo.rs` Fixes #48483
2 parents e5f80f2 + 2f8c2a9 commit 95d0b9e

File tree

2 files changed

+59
-15
lines changed

2 files changed

+59
-15
lines changed

src/bootstrap/builder.rs

+38-13
Original file line numberDiff line numberDiff line change
@@ -111,27 +111,34 @@ struct StepDescription {
111111
}
112112

113113
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)]
114-
struct PathSet {
115-
set: BTreeSet<PathBuf>,
114+
pub enum PathSet {
115+
Set (BTreeSet<PathBuf>),
116+
Suite (PathBuf)
116117
}
117118

118119
impl PathSet {
119120
fn empty() -> PathSet {
120-
PathSet { set: BTreeSet::new() }
121+
PathSet::Set(BTreeSet::new())
121122
}
122123

123124
fn one<P: Into<PathBuf>>(path: P) -> PathSet {
124125
let mut set = BTreeSet::new();
125126
set.insert(path.into());
126-
PathSet { set }
127+
PathSet::Set(set)
127128
}
128129

129130
fn has(&self, needle: &Path) -> bool {
130-
self.set.iter().any(|p| p.ends_with(needle))
131+
match self {
132+
PathSet::Set(set) => set.iter().any(|p| p.ends_with(needle)),
133+
PathSet::Suite(_) => false
134+
}
131135
}
132136

133137
fn path(&self, builder: &Builder) -> PathBuf {
134-
self.set.iter().next().unwrap_or(&builder.build.src).to_path_buf()
138+
match self {
139+
PathSet::Set(set) => set.iter().next().unwrap_or(&builder.build.src).to_path_buf(),
140+
PathSet::Suite(path) => PathBuf::from(path)
141+
}
135142
}
136143
}
137144

@@ -203,7 +210,10 @@ impl StepDescription {
203210
for path in paths {
204211
let mut attempted_run = false;
205212
for (desc, should_run) in v.iter().zip(&should_runs) {
206-
if let Some(pathset) = should_run.pathset_for_path(path) {
213+
if let Some(suite) = should_run.is_suite_path(path) {
214+
attempted_run = true;
215+
desc.maybe_run(builder, suite);
216+
} else if let Some(pathset) = should_run.pathset_for_path(path) {
207217
attempted_run = true;
208218
desc.maybe_run(builder, pathset);
209219
}
@@ -250,7 +260,7 @@ impl<'a> ShouldRun<'a> {
250260
for krate in self.builder.in_tree_crates(name) {
251261
set.insert(PathBuf::from(&krate.path));
252262
}
253-
self.paths.insert(PathSet { set });
263+
self.paths.insert(PathSet::Set(set));
254264
self
255265
}
256266

@@ -268,9 +278,21 @@ impl<'a> ShouldRun<'a> {
268278

269279
// multiple aliases for the same job
270280
pub fn paths(mut self, paths: &[&str]) -> Self {
271-
self.paths.insert(PathSet {
272-
set: paths.iter().map(PathBuf::from).collect(),
273-
});
281+
self.paths.insert(PathSet::Set(paths.iter().map(PathBuf::from).collect()));
282+
self
283+
}
284+
285+
pub fn is_suite_path(&self, path: &Path) -> Option<&PathSet> {
286+
self.paths.iter().find(|pathset| {
287+
match pathset {
288+
PathSet::Suite(p) => path.starts_with(p),
289+
PathSet::Set(_) => false
290+
}
291+
})
292+
}
293+
294+
pub fn suite_path(mut self, suite: &str) -> Self {
295+
self.paths.insert(PathSet::Suite(PathBuf::from(suite)));
274296
self
275297
}
276298

@@ -372,8 +394,10 @@ impl<'a> Builder<'a> {
372394
}
373395
let mut help = String::from("Available paths:\n");
374396
for pathset in should_run.paths {
375-
for path in pathset.set {
376-
help.push_str(format!(" ./x.py {} {}\n", subcommand, path.display()).as_str());
397+
if let PathSet::Set(set) = pathset{
398+
set.iter().for_each(|path| help.push_str(
399+
format!(" ./x.py {} {}\n", subcommand, path.display()).as_str()
400+
))
377401
}
378402
}
379403
Some(help)
@@ -404,6 +428,7 @@ impl<'a> Builder<'a> {
404428
parent: Cell::new(None),
405429
};
406430

431+
407432
if kind == Kind::Dist {
408433
assert!(!builder.config.test_miri, "Do not distribute with miri enabled.\n\
409434
The distributed libraries would include all MIR (increasing binary size).

src/bootstrap/test.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use tool::{self, Tool};
3434
use util::{self, dylib_path, dylib_path_var};
3535
use {Mode, DocTests};
3636
use toolstate::ToolState;
37+
use flags::Subcommand;
3738

3839
const ADB_TEST_DIR: &str = "/data/tmp/work";
3940

@@ -559,6 +560,7 @@ impl Step for RustdocUi {
559560
target: self.target,
560561
mode: "ui",
561562
suite: "rustdoc-ui",
563+
path: None,
562564
compare_mode: None,
563565
})
564566
}
@@ -663,7 +665,7 @@ macro_rules! test_definitions {
663665
const ONLY_HOSTS: bool = $host;
664666

665667
fn should_run(run: ShouldRun) -> ShouldRun {
666-
run.path($path)
668+
run.suite_path($path)
667669
}
668670

669671
fn make_run(run: RunConfig) {
@@ -681,6 +683,7 @@ macro_rules! test_definitions {
681683
target: self.target,
682684
mode: $mode,
683685
suite: $suite,
686+
path: Some($path),
684687
compare_mode: $compare_mode,
685688
})
686689
}
@@ -853,6 +856,7 @@ struct Compiletest {
853856
target: Interned<String>,
854857
mode: &'static str,
855858
suite: &'static str,
859+
path: Option<&'static str>,
856860
compare_mode: Option<&'static str>,
857861
}
858862

@@ -875,6 +879,9 @@ impl Step for Compiletest {
875879
let suite = self.suite;
876880
let compare_mode = self.compare_mode;
877881

882+
// Path for test suite
883+
let suite_path = self.path.unwrap_or("");
884+
878885
// Skip codegen tests if they aren't enabled in configuration.
879886
if !builder.config.codegen_tests && suite == "codegen" {
880887
return;
@@ -997,7 +1004,19 @@ impl Step for Compiletest {
9971004
cmd.arg("--lldb-python-dir").arg(dir);
9981005
}
9991006

1000-
cmd.args(&builder.config.cmd.test_args());
1007+
// Get paths from cmd args
1008+
let paths = match &builder.config.cmd {
1009+
Subcommand::Test { ref paths, ..} => &paths[..],
1010+
_ => &[]
1011+
};
1012+
1013+
// Get test-args by striping suite path
1014+
let mut test_args: Vec<&str> = paths.iter().filter(|p| p.starts_with(suite_path) &&
1015+
p.is_file()).map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap()).collect();
1016+
1017+
test_args.append(&mut builder.config.cmd.test_args());
1018+
1019+
cmd.args(&test_args);
10011020

10021021
if builder.is_verbose() {
10031022
cmd.arg("--verbose");

0 commit comments

Comments
 (0)