Skip to content

Commit

Permalink
Auto merge of #49729 - collin5:b48483, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
./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
  • Loading branch information
bors committed May 10, 2018
2 parents e5f80f2 + 2f8c2a9 commit 95d0b9e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
51 changes: 38 additions & 13 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,34 @@ struct StepDescription {
}

#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)]
struct PathSet {
set: BTreeSet<PathBuf>,
pub enum PathSet {
Set (BTreeSet<PathBuf>),
Suite (PathBuf)
}

impl PathSet {
fn empty() -> PathSet {
PathSet { set: BTreeSet::new() }
PathSet::Set(BTreeSet::new())
}

fn one<P: Into<PathBuf>>(path: P) -> PathSet {
let mut set = BTreeSet::new();
set.insert(path.into());
PathSet { set }
PathSet::Set(set)
}

fn has(&self, needle: &Path) -> bool {
self.set.iter().any(|p| p.ends_with(needle))
match self {
PathSet::Set(set) => set.iter().any(|p| p.ends_with(needle)),
PathSet::Suite(_) => false
}
}

fn path(&self, builder: &Builder) -> PathBuf {
self.set.iter().next().unwrap_or(&builder.build.src).to_path_buf()
match self {
PathSet::Set(set) => set.iter().next().unwrap_or(&builder.build.src).to_path_buf(),
PathSet::Suite(path) => PathBuf::from(path)
}
}
}

Expand Down Expand Up @@ -203,7 +210,10 @@ impl StepDescription {
for path in paths {
let mut attempted_run = false;
for (desc, should_run) in v.iter().zip(&should_runs) {
if let Some(pathset) = should_run.pathset_for_path(path) {
if let Some(suite) = should_run.is_suite_path(path) {
attempted_run = true;
desc.maybe_run(builder, suite);
} else if let Some(pathset) = should_run.pathset_for_path(path) {
attempted_run = true;
desc.maybe_run(builder, pathset);
}
Expand Down Expand Up @@ -250,7 +260,7 @@ impl<'a> ShouldRun<'a> {
for krate in self.builder.in_tree_crates(name) {
set.insert(PathBuf::from(&krate.path));
}
self.paths.insert(PathSet { set });
self.paths.insert(PathSet::Set(set));
self
}

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

// multiple aliases for the same job
pub fn paths(mut self, paths: &[&str]) -> Self {
self.paths.insert(PathSet {
set: paths.iter().map(PathBuf::from).collect(),
});
self.paths.insert(PathSet::Set(paths.iter().map(PathBuf::from).collect()));
self
}

pub fn is_suite_path(&self, path: &Path) -> Option<&PathSet> {
self.paths.iter().find(|pathset| {
match pathset {
PathSet::Suite(p) => path.starts_with(p),
PathSet::Set(_) => false
}
})
}

pub fn suite_path(mut self, suite: &str) -> Self {
self.paths.insert(PathSet::Suite(PathBuf::from(suite)));
self
}

Expand Down Expand Up @@ -372,8 +394,10 @@ impl<'a> Builder<'a> {
}
let mut help = String::from("Available paths:\n");
for pathset in should_run.paths {
for path in pathset.set {
help.push_str(format!(" ./x.py {} {}\n", subcommand, path.display()).as_str());
if let PathSet::Set(set) = pathset{
set.iter().for_each(|path| help.push_str(
format!(" ./x.py {} {}\n", subcommand, path.display()).as_str()
))
}
}
Some(help)
Expand Down Expand Up @@ -404,6 +428,7 @@ impl<'a> Builder<'a> {
parent: Cell::new(None),
};


if kind == Kind::Dist {
assert!(!builder.config.test_miri, "Do not distribute with miri enabled.\n\
The distributed libraries would include all MIR (increasing binary size).
Expand Down
23 changes: 21 additions & 2 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use tool::{self, Tool};
use util::{self, dylib_path, dylib_path_var};
use {Mode, DocTests};
use toolstate::ToolState;
use flags::Subcommand;

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

Expand Down Expand Up @@ -559,6 +560,7 @@ impl Step for RustdocUi {
target: self.target,
mode: "ui",
suite: "rustdoc-ui",
path: None,
compare_mode: None,
})
}
Expand Down Expand Up @@ -663,7 +665,7 @@ macro_rules! test_definitions {
const ONLY_HOSTS: bool = $host;

fn should_run(run: ShouldRun) -> ShouldRun {
run.path($path)
run.suite_path($path)
}

fn make_run(run: RunConfig) {
Expand All @@ -681,6 +683,7 @@ macro_rules! test_definitions {
target: self.target,
mode: $mode,
suite: $suite,
path: Some($path),
compare_mode: $compare_mode,
})
}
Expand Down Expand Up @@ -853,6 +856,7 @@ struct Compiletest {
target: Interned<String>,
mode: &'static str,
suite: &'static str,
path: Option<&'static str>,
compare_mode: Option<&'static str>,
}

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

// Path for test suite
let suite_path = self.path.unwrap_or("");

// Skip codegen tests if they aren't enabled in configuration.
if !builder.config.codegen_tests && suite == "codegen" {
return;
Expand Down Expand Up @@ -997,7 +1004,19 @@ impl Step for Compiletest {
cmd.arg("--lldb-python-dir").arg(dir);
}

cmd.args(&builder.config.cmd.test_args());
// Get paths from cmd args
let paths = match &builder.config.cmd {
Subcommand::Test { ref paths, ..} => &paths[..],
_ => &[]
};

// Get test-args by striping suite path
let mut test_args: Vec<&str> = paths.iter().filter(|p| p.starts_with(suite_path) &&
p.is_file()).map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap()).collect();

test_args.append(&mut builder.config.cmd.test_args());

cmd.args(&test_args);

if builder.is_verbose() {
cmd.arg("--verbose");
Expand Down

0 comments on commit 95d0b9e

Please sign in to comment.