Skip to content

Use a regex filter for the test runner & assorted fixes #13948

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

Merged
merged 4 commits into from
May 15, 2014
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
2 changes: 1 addition & 1 deletion mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ DEPS_collections := std rand
DEPS_fourcc := syntax std
DEPS_hexfloat := syntax std
DEPS_num := std rand
DEPS_test := std collections getopts serialize term time
DEPS_test := std collections getopts serialize term time regex
DEPS_time := std serialize
DEPS_rand := std
DEPS_url := std collections
Expand Down
3 changes: 2 additions & 1 deletion src/compiletest/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use std::from_str::FromStr;
use std::fmt;
use regex::Regex;

#[deriving(Clone, Eq)]
pub enum Mode {
Expand Down Expand Up @@ -88,7 +89,7 @@ pub struct Config {
pub run_ignored: bool,

// Only run tests that match this filter
pub filter: Option<~str>,
pub filter: Option<Regex>,

// Write out a parseable log of tests that were run
pub logfile: Option<Path>,
Expand Down
26 changes: 18 additions & 8 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ extern crate log;
extern crate green;
extern crate rustuv;

extern crate regex;

use std::os;
use std::io;
use std::io::fs;
Expand Down Expand Up @@ -113,6 +115,19 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
Path::new(m.opt_str(nm).unwrap())
}

let filter = if !matches.free.is_empty() {
let s = matches.free.get(0).as_slice();
match regex::Regex::new(s) {
Ok(re) => Some(re),
Err(e) => {
println!("failed to parse filter /{}/: {}", s, e);
fail!()
}
}
} else {
None
};

Config {
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
Expand All @@ -125,12 +140,7 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
stage_id: matches.opt_str("stage-id").unwrap(),
mode: FromStr::from_str(matches.opt_str("mode").unwrap()).expect("invalid mode"),
run_ignored: matches.opt_present("ignored"),
filter:
if !matches.free.is_empty() {
Some((*matches.free.get(0)).clone())
} else {
None
},
filter: filter,
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
save_metrics: matches.opt_str("save-metrics").map(|s| Path::new(s)),
ratchet_metrics:
Expand Down Expand Up @@ -169,7 +179,7 @@ pub fn log_config(config: &Config) {
logv(c, format!("stage_id: {}", config.stage_id));
logv(c, format!("mode: {}", config.mode));
logv(c, format!("run_ignored: {}", config.run_ignored));
logv(c, format!("filter: {}", opt_str(&config.filter)));
logv(c, format!("filter: {}", opt_str(&config.filter.as_ref().map(|re| re.to_str()))));
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
logv(c, format!("host-rustcflags: {}", opt_str(&config.host_rustcflags)));
logv(c, format!("target-rustcflags: {}", opt_str(&config.target_rustcflags)));
Expand Down Expand Up @@ -238,7 +248,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
test::TestOpts {
filter: match config.filter {
None => None,
Some(ref filter) => Some(filter.to_strbuf()),
Some(ref filter) => Some(filter.clone()),
},
run_ignored: config.run_ignored,
logfile: config.logfile.clone(),
Expand Down
34 changes: 27 additions & 7 deletions src/doc/guide-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ fn test_out_of_bounds_failure() {
~~~

A test runner built with the `--test` flag supports a limited set of
arguments to control which tests are run: the first free argument
passed to a test runner specifies a filter used to narrow down the set
of tests being run; the `--ignored` flag tells the test runner to run
only tests with the `ignore` attribute.
arguments to control which tests are run:

- the first free argument passed to a test runner is interpreted as a
regular expression
([syntax reference](regex/index.html#syntax))
and is used to narrow down the set of tests being run. Note: a plain
string is a valid regular expression that matches itself.
- the `--ignored` flag tells the test runner to run only tests with the
`ignore` attribute.

## Parallelism

Expand Down Expand Up @@ -146,16 +151,31 @@ result: FAILED. 1 passed; 1 failed; 0 ignored

### Running a subset of tests

Using a plain string:

~~~ {.notrust}
$ mytests mytest23

running 1 tests
running driver::tests::mytest23 ... ok

result: ok. 1 passed; 0 failed; 0 ignored
~~~

Using some regular expression features:

~~~ {.notrust}
$ mytests mytest1
$ mytests 'mytest[145]'

running 11 tests
running 13 tests
running driver::tests::mytest1 ... ok
running driver::tests::mytest4 ... ok
running driver::tests::mytest5 ... ok
running driver::tests::mytest10 ... ignored
... snip ...
running driver::tests::mytest19 ... ok

result: ok. 11 passed; 0 failed; 1 ignored
result: ok. 13 passed; 0 failed; 1 ignored
~~~

# Microbenchmarking
Expand Down
14 changes: 8 additions & 6 deletions src/libstd/unstable/dynamic_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ A simple wrapper over the platform's dynamic library facilities

*/


use c_str::ToCStr;
use iter::Iterator;
use mem;
use ops::*;
use option::*;
use os;
use path::GenericPath;
use path;
use result::*;
use slice::{Vector,OwnedVector};
use slice::Vector;
use str;
use vec::Vec;

Expand Down Expand Up @@ -75,10 +75,12 @@ impl DynamicLibrary {
} else {
("LD_LIBRARY_PATH", ':' as u8)
};
let newenv = os::getenv_as_bytes(envvar).unwrap_or(box []);
let mut newenv = newenv.move_iter().collect::<Vec<_>>();
newenv.push_all(&[sep]);
newenv.push_all(path.as_vec());
let mut newenv = Vec::from_slice(path.as_vec());
newenv.push(sep);
match os::getenv_as_bytes(envvar) {
Some(bytes) => newenv.push_all(bytes),
None => {}
}
os::setenv(envvar, str::from_utf8(newenv.as_slice()).unwrap());
}

Expand Down
Loading