./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).