1
Fork 0

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

trim and pass relative test paths as test-args

use collect for getting test_args

move suite_path to ShouldRun and make Option

append existing args to test_args

use enum for PathSet

handle Suites differently from Paths

Error out if part of test suite but not file

refactor, make requested changes
This commit is contained in:
Collins Abitekaniza 2018-04-12 14:49:31 +03:00 committed by Collins Abitekaniza
parent 898c9f7d71
commit 41ee6fe147
2 changed files with 63 additions and 15 deletions

View file

@ -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)
}
}
}
@ -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);
}
@ -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
}
@ -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
}
@ -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)
@ -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).

View file

@ -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";
@ -556,6 +557,7 @@ impl Step for RustdocUi {
target: self.target,
mode: "ui",
suite: "rustdoc-ui",
path: None,
compare_mode: None,
})
}
@ -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) {
@ -678,6 +680,7 @@ macro_rules! test_definitions {
target: self.target,
mode: $mode,
suite: $suite,
path: Some($path),
compare_mode: $compare_mode,
})
}
@ -850,6 +853,7 @@ struct Compiletest {
target: Interned<String>,
mode: &'static str,
suite: &'static str,
path: Option<&'static str>,
compare_mode: Option<&'static str>,
}
@ -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;
@ -994,7 +1001,23 @@ 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 assert_file = |p: &PathBuf| {
assert!(p.is_file(), "Expected {:?} to be a path to a test file", p);
return true
};
let mut test_args: Vec<&str> = paths.iter().filter(|p| p.starts_with(suite_path) &&
assert_file(p)).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");