Skip to content

Commit

Permalink
auto merge of #13948 : huonw/rust/test-regex-filter, r=alexcrichton
Browse files Browse the repository at this point in the history
The regex change is fully backwards compatible, since test names are Rust
identifiers + `:`, and hence not special regex characters.

(See commits for details.)
  • Loading branch information
bors committed May 6, 2014
2 parents c600dc0 + 65268a4 commit 338e51f
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 71 deletions.
2 changes: 1 addition & 1 deletion mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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
4 changes: 3 additions & 1 deletion src/compiletest/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use regex::Regex;

#[deriving(Clone, Eq)]
pub enum mode {
mode_compile_fail,
Expand Down Expand Up @@ -54,7 +56,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
24 changes: 17 additions & 7 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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 @@ -117,6 +119,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 @@ -129,12 +144,7 @@ pub fn parse_config(args: Vec<~str> ) -> config {
stage_id: matches.opt_str("stage-id").unwrap(),
mode: str_mode(matches.opt_str("mode").unwrap()),
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 @@ -170,7 +180,7 @@ pub fn log_config(config: &config) {
logv(c, format!("stage_id: {}", config.stage_id));
logv(c, format!("mode: {}", mode_str(config.mode)));
logv(c, format!("run_ignored: {}", config.run_ignored));
logv(c, format!("filter: {}", opt_str(&config.filter)));
logv(c, format!("filter: {}", if config.filter.is_some() { "(regex)" } else { "(none)" }));
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
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
Loading

0 comments on commit 338e51f

Please sign in to comment.