Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

./x.py test should be able to run individual tests #49729

Merged
merged 2 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
use toolstate::ToolState;
use flags::Subcommand;

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

Expand Down Expand Up @@ -556,6 +557,7 @@ impl Step for RustdocUi {
target: self.target,
mode: "ui",
suite: "rustdoc-ui",
path: None,
compare_mode: None,
})
}
Expand Down Expand Up @@ -660,7 +662,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 @@ -678,6 +680,7 @@ macro_rules! test_definitions {
target: self.target,
mode: $mode,
suite: $suite,
path: Some($path),
compare_mode: $compare_mode,
})
}
Expand Down Expand Up @@ -850,6 +853,7 @@ struct Compiletest {
target: Interned<String>,
mode: &'static str,
suite: &'static str,
path: Option<&'static str>,
compare_mode: Option<&'static str>,
}

Expand All @@ -872,6 +876,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 @@ -994,7 +1001,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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably error out here if the argument is going to be silently ignored because it's part of our suite yet not a file (and as such we don't know what to do with it).


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

cmd.args(&test_args);

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