Skip to content

Commit 338e51f

Browse files
committed
auto merge of #13948 : huonw/rust/test-regex-filter, r=alexcrichton
The regex change is fully backwards compatible, since test names are Rust identifiers + `:`, and hence not special regex characters. (See commits for details.)
2 parents c600dc0 + 65268a4 commit 338e51f

File tree

5 files changed

+130
-71
lines changed

5 files changed

+130
-71
lines changed

mk/crates.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ DEPS_collections := std rand
7979
DEPS_fourcc := syntax std
8080
DEPS_hexfloat := syntax std
8181
DEPS_num := std rand
82-
DEPS_test := std collections getopts serialize term time
82+
DEPS_test := std collections getopts serialize term time regex
8383
DEPS_time := std serialize
8484
DEPS_rand := std
8585
DEPS_url := std collections

src/compiletest/common.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use regex::Regex;
12+
1113
#[deriving(Clone, Eq)]
1214
pub enum mode {
1315
mode_compile_fail,
@@ -54,7 +56,7 @@ pub struct config {
5456
pub run_ignored: bool,
5557

5658
// Only run tests that match this filter
57-
pub filter: Option<~str>,
59+
pub filter: Option<Regex>,
5860

5961
// Write out a parseable log of tests that were run
6062
pub logfile: Option<Path>,

src/compiletest/compiletest.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ extern crate log;
2424
extern crate green;
2525
extern crate rustuv;
2626

27+
extern crate regex;
28+
2729
use std::os;
2830
use std::io;
2931
use std::io::fs;
@@ -117,6 +119,19 @@ pub fn parse_config(args: Vec<~str> ) -> config {
117119
Path::new(m.opt_str(nm).unwrap())
118120
}
119121

122+
let filter = if !matches.free.is_empty() {
123+
let s = matches.free.get(0).as_slice();
124+
match regex::Regex::new(s) {
125+
Ok(re) => Some(re),
126+
Err(e) => {
127+
println!("failed to parse filter /{}/: {}", s, e);
128+
fail!()
129+
}
130+
}
131+
} else {
132+
None
133+
};
134+
120135
config {
121136
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
122137
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
@@ -129,12 +144,7 @@ pub fn parse_config(args: Vec<~str> ) -> config {
129144
stage_id: matches.opt_str("stage-id").unwrap(),
130145
mode: str_mode(matches.opt_str("mode").unwrap()),
131146
run_ignored: matches.opt_present("ignored"),
132-
filter:
133-
if !matches.free.is_empty() {
134-
Some((*matches.free.get(0)).clone())
135-
} else {
136-
None
137-
},
147+
filter: filter,
138148
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
139149
save_metrics: matches.opt_str("save-metrics").map(|s| Path::new(s)),
140150
ratchet_metrics:
@@ -170,7 +180,7 @@ pub fn log_config(config: &config) {
170180
logv(c, format!("stage_id: {}", config.stage_id));
171181
logv(c, format!("mode: {}", mode_str(config.mode)));
172182
logv(c, format!("run_ignored: {}", config.run_ignored));
173-
logv(c, format!("filter: {}", opt_str(&config.filter)));
183+
logv(c, format!("filter: {}", if config.filter.is_some() { "(regex)" } else { "(none)" }));
174184
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
175185
logv(c, format!("host-rustcflags: {}", opt_str(&config.host_rustcflags)));
176186
logv(c, format!("target-rustcflags: {}", opt_str(&config.target_rustcflags)));

src/doc/guide-testing.md

+27-7
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,15 @@ fn test_out_of_bounds_failure() {
9090
~~~
9191

9292
A test runner built with the `--test` flag supports a limited set of
93-
arguments to control which tests are run: the first free argument
94-
passed to a test runner specifies a filter used to narrow down the set
95-
of tests being run; the `--ignored` flag tells the test runner to run
96-
only tests with the `ignore` attribute.
93+
arguments to control which tests are run:
94+
95+
- the first free argument passed to a test runner is interpreted as a
96+
regular expression
97+
([syntax reference](regex/index.html#syntax))
98+
and is used to narrow down the set of tests being run. Note: a plain
99+
string is a valid regular expression that matches itself.
100+
- the `--ignored` flag tells the test runner to run only tests with the
101+
`ignore` attribute.
97102

98103
## Parallelism
99104

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

147152
### Running a subset of tests
148153

154+
Using a plain string:
155+
156+
~~~ {.notrust}
157+
$ mytests mytest23
158+
159+
running 1 tests
160+
running driver::tests::mytest23 ... ok
161+
162+
result: ok. 1 passed; 0 failed; 0 ignored
163+
~~~
164+
165+
Using some regular expression features:
166+
149167
~~~ {.notrust}
150-
$ mytests mytest1
168+
$ mytests 'mytest[145]'
151169
152-
running 11 tests
170+
running 13 tests
153171
running driver::tests::mytest1 ... ok
172+
running driver::tests::mytest4 ... ok
173+
running driver::tests::mytest5 ... ok
154174
running driver::tests::mytest10 ... ignored
155175
... snip ...
156176
running driver::tests::mytest19 ... ok
157177
158-
result: ok. 11 passed; 0 failed; 1 ignored
178+
result: ok. 13 passed; 0 failed; 1 ignored
159179
~~~
160180

161181
# Microbenchmarking

0 commit comments

Comments
 (0)