2012-03-07 20:17:30 -06:00
|
|
|
#[doc(hidden)];
|
|
|
|
|
2011-07-09 18:08:03 -05:00
|
|
|
// Support code for rustc's built in test runner generator. Currently,
|
|
|
|
// none of this is meant for users. It is intended to support the
|
|
|
|
// simplest interface possible for representing and running tests
|
|
|
|
// while providing a base that other test frameworks may build off of.
|
|
|
|
|
2012-08-14 18:54:13 -05:00
|
|
|
import either::Either;
|
2012-01-11 08:15:54 -06:00
|
|
|
import result::{ok, err};
|
2012-08-14 15:38:35 -05:00
|
|
|
import io::WriterUtil;
|
2012-06-04 19:26:17 -05:00
|
|
|
import libc::size_t;
|
2012-08-15 16:10:46 -05:00
|
|
|
import task::TaskBuilder;
|
2012-08-14 16:17:27 -05:00
|
|
|
import comm = core::comm;
|
2011-07-16 19:04:20 -05:00
|
|
|
|
2011-07-09 18:08:03 -05:00
|
|
|
export test_name;
|
|
|
|
export test_fn;
|
|
|
|
export test_desc;
|
|
|
|
export test_main;
|
2011-07-14 13:29:54 -05:00
|
|
|
export test_result;
|
2011-07-14 18:05:33 -05:00
|
|
|
export test_opts;
|
2011-07-14 13:29:54 -05:00
|
|
|
export tr_ok;
|
|
|
|
export tr_failed;
|
|
|
|
export tr_ignored;
|
The Big Test Suite Overhaul
This replaces the make-based test runner with a set of Rust-based test
runners. I believe that all existing functionality has been
preserved. The primary objective is to dogfood the Rust test
framework.
A few main things happen here:
1) The run-pass/lib-* tests are all moved into src/test/stdtest. This
is a standalone test crate intended for all standard library tests. It
compiles to build/test/stdtest.stageN.
2) rustc now compiles into yet another build artifact, this one a test
runner that runs any tests contained directly in the rustc crate. This
allows much more fine-grained unit testing of the compiler. It
compiles to build/test/rustctest.stageN.
3) There is a new custom test runner crate at src/test/compiletest
that reproduces all the functionality for running the compile-fail,
run-fail, run-pass and bench tests while integrating with Rust's test
framework. It compiles to build/test/compiletest.stageN.
4) The build rules have been completely changed to use the new test
runners, while also being less redundant, following the example of the
recent stageN.mk rewrite.
It adds two new features to the cfail/rfail/rpass/bench tests:
1) Tests can specify multiple 'error-pattern' directives which must be
satisfied in order.
2) Tests can specify a 'compile-flags' directive which will make the
test runner provide additional command line arguments to rustc.
There are some downsides, the primary being that Rust has to be
functioning pretty well just to run _any_ tests, which I imagine will
be the source of some frustration when the entire test suite
breaks. Will also cause some headaches during porting.
Not having individual make rules, each rpass, etc test no longer
remembers between runs whether it completed successfully. As a result,
it's not possible to incrementally fix multiple tests by just running
'make check', fixing a test, and repeating without re-running all the
tests contained in the test runner. Instead you can filter just the
tests you want to run by using the TESTNAME environment variable.
This also dispenses with the ability to run stage0 tests, but they
tended to be broken more often than not anyway.
2011-07-12 21:01:09 -05:00
|
|
|
export run_tests_console;
|
2011-07-09 18:08:03 -05:00
|
|
|
|
2011-11-16 22:49:38 -06:00
|
|
|
#[abi = "cdecl"]
|
2012-07-03 18:11:00 -05:00
|
|
|
extern mod rustrt {
|
2012-03-12 22:04:27 -05:00
|
|
|
fn sched_threads() -> libc::size_t;
|
2011-07-25 20:07:25 -05:00
|
|
|
}
|
|
|
|
|
2011-07-09 18:08:03 -05:00
|
|
|
// The name of a test. By convention this follows the rules for rust
|
2011-09-26 12:51:23 -05:00
|
|
|
// paths; i.e. it should be a series of identifiers seperated by double
|
2011-07-09 18:08:03 -05:00
|
|
|
// colons. This way if some test runner wants to arrange the tests
|
2011-09-26 12:51:23 -05:00
|
|
|
// hierarchically it may.
|
2012-07-14 00:57:48 -05:00
|
|
|
type test_name = ~str;
|
2011-07-09 18:08:03 -05:00
|
|
|
|
|
|
|
// A function that runs a test. If the function returns successfully,
|
|
|
|
// the test succeeds; if the function fails then the test fails. We
|
|
|
|
// may need to come up with a more clever definition of test in order
|
|
|
|
// to support isolation of tests into tasks.
|
2012-01-19 15:00:30 -06:00
|
|
|
type test_fn = fn~();
|
2011-07-09 18:08:03 -05:00
|
|
|
|
|
|
|
// The definition of a single test. A test runner will run a list of
|
|
|
|
// these.
|
2012-01-19 15:00:30 -06:00
|
|
|
type test_desc = {
|
2011-10-13 18:42:43 -05:00
|
|
|
name: test_name,
|
2012-01-19 15:00:30 -06:00
|
|
|
fn: test_fn,
|
2011-11-01 12:31:23 -05:00
|
|
|
ignore: bool,
|
|
|
|
should_fail: bool
|
2011-10-13 18:42:43 -05:00
|
|
|
};
|
2011-07-09 18:08:03 -05:00
|
|
|
|
|
|
|
// The default console test runner. It accepts the command line
|
|
|
|
// arguments and a vector of test_descs (generated at compile time).
|
2012-07-14 00:57:48 -05:00
|
|
|
fn test_main(args: ~[~str], tests: ~[test_desc]) {
|
2011-07-27 07:19:39 -05:00
|
|
|
let opts =
|
2012-08-06 14:34:08 -05:00
|
|
|
match parse_opts(args) {
|
2012-08-14 18:54:13 -05:00
|
|
|
either::Left(o) => o,
|
|
|
|
either::Right(m) => fail m
|
2011-07-27 07:19:39 -05:00
|
|
|
};
|
2012-07-14 00:57:48 -05:00
|
|
|
if !run_tests_console(opts, tests) { fail ~"Some tests failed"; }
|
2011-07-09 18:08:03 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
type test_opts = {filter: option<~str>, run_ignored: bool,
|
|
|
|
logfile: option<~str>};
|
2011-07-14 18:05:33 -05:00
|
|
|
|
2012-08-14 18:54:13 -05:00
|
|
|
type opt_res = Either<test_opts, ~str>;
|
2011-07-14 18:05:33 -05:00
|
|
|
|
|
|
|
// Parses command line arguments into test options
|
2012-07-14 00:57:48 -05:00
|
|
|
fn parse_opts(args: ~[~str]) -> opt_res {
|
2011-08-31 18:56:38 -05:00
|
|
|
let args_ = vec::tail(args);
|
2012-07-14 00:57:48 -05:00
|
|
|
let opts = ~[getopts::optflag(~"ignored"), getopts::optopt(~"logfile")];
|
2012-07-31 18:38:41 -05:00
|
|
|
let matches =
|
2012-08-06 14:34:08 -05:00
|
|
|
match getopts::getopts(args_, opts) {
|
2012-08-03 21:59:04 -05:00
|
|
|
ok(m) => m,
|
2012-08-14 18:54:13 -05:00
|
|
|
err(f) => return either::Right(getopts::fail_str(f))
|
2011-07-27 07:19:39 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
let filter =
|
2012-07-31 18:38:41 -05:00
|
|
|
if vec::len(matches.free) > 0u {
|
|
|
|
option::some(matches.free[0])
|
2011-07-27 07:19:39 -05:00
|
|
|
} else { option::none };
|
2011-07-14 18:05:33 -05:00
|
|
|
|
2012-07-31 18:38:41 -05:00
|
|
|
let run_ignored = getopts::opt_present(matches, ~"ignored");
|
|
|
|
let logfile = getopts::opt_maybe_str(matches, ~"logfile");
|
2011-07-14 18:05:33 -05:00
|
|
|
|
2012-04-03 10:27:51 -05:00
|
|
|
let test_opts = {filter: filter, run_ignored: run_ignored,
|
2012-05-24 16:49:39 -05:00
|
|
|
logfile: logfile};
|
2011-07-11 18:33:21 -05:00
|
|
|
|
2012-08-14 18:54:13 -05:00
|
|
|
return either::Left(test_opts);
|
2011-07-11 18:33:21 -05:00
|
|
|
}
|
|
|
|
|
2012-01-19 19:55:34 -06:00
|
|
|
enum test_result { tr_ok, tr_failed, tr_ignored, }
|
2011-07-14 13:29:54 -05:00
|
|
|
|
2012-03-12 19:31:03 -05:00
|
|
|
type console_test_state =
|
2012-08-14 15:38:35 -05:00
|
|
|
@{out: io::Writer,
|
|
|
|
log_out: option<io::Writer>,
|
2012-04-13 05:34:41 -05:00
|
|
|
use_color: bool,
|
2012-03-26 20:35:18 -05:00
|
|
|
mut total: uint,
|
|
|
|
mut passed: uint,
|
|
|
|
mut failed: uint,
|
|
|
|
mut ignored: uint,
|
2012-06-29 18:26:56 -05:00
|
|
|
mut failures: ~[test_desc]};
|
2012-03-12 19:31:03 -05:00
|
|
|
|
2011-07-11 18:33:21 -05:00
|
|
|
// A simple console test runner
|
2011-10-13 18:42:43 -05:00
|
|
|
fn run_tests_console(opts: test_opts,
|
2012-06-29 18:26:56 -05:00
|
|
|
tests: ~[test_desc]) -> bool {
|
2011-07-11 18:33:21 -05:00
|
|
|
|
2012-04-13 05:34:45 -05:00
|
|
|
fn callback(event: testevent, st: console_test_state) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match event {
|
2012-08-03 21:59:04 -05:00
|
|
|
te_filtered(filtered_tests) => {
|
2011-08-15 18:38:23 -05:00
|
|
|
st.total = vec::len(filtered_tests);
|
2012-07-14 00:57:48 -05:00
|
|
|
let noun = if st.total != 1u { ~"tests" } else { ~"test" };
|
2012-08-22 19:24:52 -05:00
|
|
|
st.out.write_line(fmt!("\nrunning %u %s", st.total, noun));
|
2011-08-01 13:26:29 -05:00
|
|
|
}
|
2012-08-22 19:24:52 -05:00
|
|
|
te_wait(test) => st.out.write_str(fmt!("test %s ... ", test.name)),
|
2012-08-03 21:59:04 -05:00
|
|
|
te_result(test, result) => {
|
2012-08-06 14:34:08 -05:00
|
|
|
match st.log_out {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(f) => write_log(f, result, test),
|
|
|
|
none => ()
|
2012-04-03 10:27:51 -05:00
|
|
|
}
|
2012-08-06 14:34:08 -05:00
|
|
|
match result {
|
2012-08-03 21:59:04 -05:00
|
|
|
tr_ok => {
|
2011-07-29 21:54:05 -05:00
|
|
|
st.passed += 1u;
|
2012-04-13 05:34:41 -05:00
|
|
|
write_ok(st.out, st.use_color);
|
2012-07-14 00:57:48 -05:00
|
|
|
st.out.write_line(~"");
|
2011-07-29 21:54:05 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
tr_failed => {
|
2011-07-29 21:54:05 -05:00
|
|
|
st.failed += 1u;
|
2012-04-13 05:34:41 -05:00
|
|
|
write_failed(st.out, st.use_color);
|
2012-07-14 00:57:48 -05:00
|
|
|
st.out.write_line(~"");
|
2012-06-28 00:49:05 -05:00
|
|
|
vec::push(st.failures, copy test);
|
2011-07-29 21:54:05 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
tr_ignored => {
|
2011-07-29 21:54:05 -05:00
|
|
|
st.ignored += 1u;
|
2012-04-13 05:34:41 -05:00
|
|
|
write_ignored(st.out, st.use_color);
|
2012-07-14 00:57:48 -05:00
|
|
|
st.out.write_line(~"");
|
2011-07-29 21:54:05 -05:00
|
|
|
}
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-07-11 13:19:32 -05:00
|
|
|
}
|
2011-07-09 18:08:03 -05:00
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
let log_out = match opts.logfile {
|
|
|
|
some(path) => match io::file_writer(path,
|
2012-08-14 15:38:35 -05:00
|
|
|
~[io::Create, io::Truncate]) {
|
2012-08-03 21:59:04 -05:00
|
|
|
result::ok(w) => some(w),
|
|
|
|
result::err(s) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
fail(fmt!("can't open output file: %s", s))
|
2012-08-03 21:59:04 -05:00
|
|
|
}
|
2012-08-06 19:14:32 -05:00
|
|
|
},
|
2012-08-03 21:59:04 -05:00
|
|
|
none => none
|
2012-04-13 05:34:45 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
let st =
|
|
|
|
@{out: io::stdout(),
|
|
|
|
log_out: log_out,
|
|
|
|
use_color: use_color(),
|
|
|
|
mut total: 0u,
|
|
|
|
mut passed: 0u,
|
|
|
|
mut failed: 0u,
|
|
|
|
mut ignored: 0u,
|
2012-06-29 18:26:56 -05:00
|
|
|
mut failures: ~[]};
|
2012-04-13 05:34:45 -05:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
run_tests(opts, tests, |x| callback(x, st));
|
2012-04-13 05:34:45 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
assert (st.passed + st.failed + st.ignored == st.total);
|
2011-07-29 21:54:05 -05:00
|
|
|
let success = st.failed == 0u;
|
2011-07-11 13:19:32 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
if !success {
|
2012-03-12 19:31:03 -05:00
|
|
|
print_failures(st);
|
2011-07-22 00:26:53 -05:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
st.out.write_str(fmt!("\nresult: "));
|
2012-04-13 05:34:41 -05:00
|
|
|
if success {
|
2012-04-13 05:34:45 -05:00
|
|
|
// There's no parallelism at this point so it's safe to use color
|
2012-04-13 05:34:41 -05:00
|
|
|
write_ok(st.out, true);
|
|
|
|
} else { write_failed(st.out, true); }
|
2012-08-22 19:24:52 -05:00
|
|
|
st.out.write_str(fmt!(". %u passed; %u failed; %u ignored\n\n", st.passed,
|
|
|
|
st.failed, st.ignored));
|
2011-07-11 13:19:32 -05:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
return success;
|
2011-07-11 13:19:32 -05:00
|
|
|
|
2012-08-14 15:38:35 -05:00
|
|
|
fn write_log(out: io::Writer, result: test_result, test: test_desc) {
|
2012-08-22 19:24:52 -05:00
|
|
|
out.write_line(fmt!("%s %s",
|
2012-08-06 14:34:08 -05:00
|
|
|
match result {
|
2012-08-03 21:59:04 -05:00
|
|
|
tr_ok => ~"ok",
|
|
|
|
tr_failed => ~"failed",
|
|
|
|
tr_ignored => ~"ignored"
|
2012-08-22 19:24:52 -05:00
|
|
|
}, test.name));
|
2012-04-03 10:27:51 -05:00
|
|
|
}
|
|
|
|
|
2012-08-14 15:38:35 -05:00
|
|
|
fn write_ok(out: io::Writer, use_color: bool) {
|
2012-07-14 00:57:48 -05:00
|
|
|
write_pretty(out, ~"ok", term::color_green, use_color);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-07-11 13:19:32 -05:00
|
|
|
|
2012-08-14 15:38:35 -05:00
|
|
|
fn write_failed(out: io::Writer, use_color: bool) {
|
2012-07-14 00:57:48 -05:00
|
|
|
write_pretty(out, ~"FAILED", term::color_red, use_color);
|
2011-07-11 13:19:32 -05:00
|
|
|
}
|
2011-07-14 13:29:54 -05:00
|
|
|
|
2012-08-14 15:38:35 -05:00
|
|
|
fn write_ignored(out: io::Writer, use_color: bool) {
|
2012-07-14 00:57:48 -05:00
|
|
|
write_pretty(out, ~"ignored", term::color_yellow, use_color);
|
2011-07-15 02:31:00 -05:00
|
|
|
}
|
|
|
|
|
2012-08-14 15:38:35 -05:00
|
|
|
fn write_pretty(out: io::Writer, word: ~str, color: u8, use_color: bool) {
|
2012-04-13 05:34:41 -05:00
|
|
|
if use_color && term::color_supported() {
|
2012-01-11 08:15:54 -06:00
|
|
|
term::fg(out, color);
|
2011-07-14 13:29:54 -05:00
|
|
|
}
|
2011-09-01 01:46:44 -05:00
|
|
|
out.write_str(word);
|
2012-04-13 05:34:41 -05:00
|
|
|
if use_color && term::color_supported() {
|
2012-01-11 08:15:54 -06:00
|
|
|
term::reset(out);
|
2011-07-14 13:29:54 -05:00
|
|
|
}
|
|
|
|
}
|
2011-07-09 18:08:03 -05:00
|
|
|
}
|
|
|
|
|
2012-03-12 19:31:03 -05:00
|
|
|
fn print_failures(st: console_test_state) {
|
2012-07-14 00:57:48 -05:00
|
|
|
st.out.write_line(~"\nfailures:");
|
2012-05-18 12:40:54 -05:00
|
|
|
let failures = copy st.failures;
|
2012-06-30 18:19:07 -05:00
|
|
|
let failures = vec::map(failures, |test| test.name);
|
2012-03-12 19:31:03 -05:00
|
|
|
let failures = sort::merge_sort(str::le, failures);
|
2012-06-30 18:19:07 -05:00
|
|
|
for vec::each(failures) |name| {
|
2012-08-22 19:24:52 -05:00
|
|
|
st.out.write_line(fmt!(" %s", name));
|
2012-03-12 19:31:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_sort_failures_before_printing_them() {
|
2012-03-13 09:55:45 -05:00
|
|
|
let buffer = io::mem_buffer();
|
2012-03-12 19:31:03 -05:00
|
|
|
let writer = io::mem_buffer_writer(buffer);
|
|
|
|
|
|
|
|
let test_a = {
|
2012-07-14 00:57:48 -05:00
|
|
|
name: ~"a",
|
2012-03-12 19:31:03 -05:00
|
|
|
fn: fn~() { },
|
|
|
|
ignore: false,
|
|
|
|
should_fail: false
|
|
|
|
};
|
|
|
|
|
|
|
|
let test_b = {
|
2012-07-14 00:57:48 -05:00
|
|
|
name: ~"b",
|
2012-03-12 19:31:03 -05:00
|
|
|
fn: fn~() { },
|
|
|
|
ignore: false,
|
|
|
|
should_fail: false
|
|
|
|
};
|
|
|
|
|
|
|
|
let st =
|
|
|
|
@{out: writer,
|
2012-04-03 10:27:51 -05:00
|
|
|
log_out: option::none,
|
2012-04-13 05:34:41 -05:00
|
|
|
use_color: false,
|
2012-03-26 20:35:18 -05:00
|
|
|
mut total: 0u,
|
|
|
|
mut passed: 0u,
|
|
|
|
mut failed: 0u,
|
|
|
|
mut ignored: 0u,
|
2012-06-29 18:26:56 -05:00
|
|
|
mut failures: ~[test_b, test_a]};
|
2012-03-12 19:31:03 -05:00
|
|
|
|
|
|
|
print_failures(st);
|
|
|
|
|
|
|
|
let s = io::mem_buffer_str(buffer);
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let apos = option::get(str::find_str(s, ~"a"));
|
|
|
|
let bpos = option::get(str::find_str(s, ~"b"));
|
2012-03-12 19:31:03 -05:00
|
|
|
assert apos < bpos;
|
|
|
|
}
|
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
fn use_color() -> bool { return get_concurrency() == 1u; }
|
2012-04-13 05:34:41 -05:00
|
|
|
|
2012-01-19 17:20:57 -06:00
|
|
|
enum testevent {
|
2012-06-29 18:26:56 -05:00
|
|
|
te_filtered(~[test_desc]),
|
2012-01-19 19:55:34 -06:00
|
|
|
te_wait(test_desc),
|
|
|
|
te_result(test_desc, test_result),
|
2011-07-29 21:54:05 -05:00
|
|
|
}
|
|
|
|
|
2012-01-19 16:36:11 -06:00
|
|
|
type monitor_msg = (test_desc, test_result);
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn run_tests(opts: test_opts, tests: ~[test_desc],
|
2012-04-13 05:34:45 -05:00
|
|
|
callback: fn@(testevent)) {
|
2011-07-29 21:54:05 -05:00
|
|
|
|
2012-03-14 13:03:56 -05:00
|
|
|
let mut filtered_tests = filter_tests(opts, tests);
|
2012-05-24 16:49:39 -05:00
|
|
|
callback(te_filtered(copy filtered_tests));
|
2011-07-29 21:54:05 -05:00
|
|
|
|
2012-01-19 15:44:07 -06:00
|
|
|
// It's tempting to just spawn all the tests at once, but since we have
|
|
|
|
// many tests that run in other processes we would be making a big mess.
|
2011-07-29 21:54:05 -05:00
|
|
|
let concurrency = get_concurrency();
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("using %u test tasks", concurrency);
|
2012-01-19 16:36:11 -06:00
|
|
|
|
2011-08-15 18:38:23 -05:00
|
|
|
let total = vec::len(filtered_tests);
|
2012-03-14 13:03:56 -05:00
|
|
|
let mut run_idx = 0u;
|
|
|
|
let mut wait_idx = 0u;
|
|
|
|
let mut done_idx = 0u;
|
2011-07-29 21:54:05 -05:00
|
|
|
|
2012-08-14 16:17:27 -05:00
|
|
|
let p = core::comm::port();
|
|
|
|
let ch = core::comm::chan(p);
|
2012-01-19 16:36:11 -06:00
|
|
|
|
|
|
|
while done_idx < total {
|
|
|
|
while wait_idx < concurrency && run_idx < total {
|
2012-06-04 16:31:25 -05:00
|
|
|
let test = copy filtered_tests[run_idx];
|
2012-02-18 18:30:07 -06:00
|
|
|
if concurrency == 1u {
|
|
|
|
// We are doing one test at a time so we can print the name
|
|
|
|
// of the test before we run it. Useful for debugging tests
|
|
|
|
// that hang forever.
|
2012-05-24 16:49:39 -05:00
|
|
|
callback(te_wait(copy test));
|
2012-02-18 18:30:07 -06:00
|
|
|
}
|
|
|
|
run_test(test, ch);
|
2012-01-19 16:36:11 -06:00
|
|
|
wait_idx += 1u;
|
2011-07-29 21:54:05 -05:00
|
|
|
run_idx += 1u;
|
|
|
|
}
|
|
|
|
|
2012-08-14 16:17:27 -05:00
|
|
|
let (test, result) = core::comm::recv(p);
|
2012-02-18 18:30:07 -06:00
|
|
|
if concurrency != 1u {
|
2012-05-24 16:49:39 -05:00
|
|
|
callback(te_wait(copy test));
|
2012-02-18 18:30:07 -06:00
|
|
|
}
|
2012-04-13 05:34:45 -05:00
|
|
|
callback(te_result(test, result));
|
2012-01-19 16:36:11 -06:00
|
|
|
wait_idx -= 1u;
|
|
|
|
done_idx += 1u;
|
2011-07-29 21:54:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-07 20:55:02 -06:00
|
|
|
// Windows tends to dislike being overloaded with threads.
|
2012-06-07 23:38:25 -05:00
|
|
|
#[cfg(windows)]
|
2012-02-07 20:55:02 -06:00
|
|
|
const sched_overcommit : uint = 1u;
|
|
|
|
|
2012-06-07 23:38:25 -05:00
|
|
|
#[cfg(unix)]
|
2012-02-07 20:55:02 -06:00
|
|
|
const sched_overcommit : uint = 4u;
|
|
|
|
|
2012-01-19 16:43:56 -06:00
|
|
|
fn get_concurrency() -> uint {
|
2012-06-04 19:26:17 -05:00
|
|
|
let threads = rustrt::sched_threads() as uint;
|
2012-01-19 16:43:56 -06:00
|
|
|
if threads == 1u { 1u }
|
2012-02-07 20:55:02 -06:00
|
|
|
else { threads * sched_overcommit }
|
2012-01-19 16:43:56 -06:00
|
|
|
}
|
2011-07-25 17:21:36 -05:00
|
|
|
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
#[allow(non_implicitly_copyable_typarams)]
|
2012-01-19 15:00:30 -06:00
|
|
|
fn filter_tests(opts: test_opts,
|
2012-06-29 18:26:56 -05:00
|
|
|
tests: ~[test_desc]) -> ~[test_desc] {
|
2012-05-24 16:49:39 -05:00
|
|
|
let mut filtered = copy tests;
|
2011-07-11 18:33:21 -05:00
|
|
|
|
2011-07-16 19:04:20 -05:00
|
|
|
// Remove tests that don't match the test filter
|
2011-10-13 18:42:43 -05:00
|
|
|
filtered = if option::is_none(opts.filter) {
|
|
|
|
filtered
|
|
|
|
} else {
|
|
|
|
let filter_str =
|
2012-08-06 14:34:08 -05:00
|
|
|
match opts.filter {
|
2012-08-03 21:59:04 -05:00
|
|
|
option::some(f) => f,
|
|
|
|
option::none => ~""
|
2011-07-27 07:19:39 -05:00
|
|
|
};
|
2011-07-14 18:05:33 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn filter_fn(test: test_desc, filter_str: ~str) ->
|
2012-01-31 19:05:20 -06:00
|
|
|
option<test_desc> {
|
2012-02-13 00:00:56 -06:00
|
|
|
if str::contains(test.name, filter_str) {
|
2012-08-01 19:30:05 -05:00
|
|
|
return option::some(copy test);
|
|
|
|
} else { return option::none; }
|
2011-10-13 18:42:43 -05:00
|
|
|
}
|
|
|
|
|
2012-08-10 20:15:08 -05:00
|
|
|
vec::filter_map(filtered, |x| filter_fn(x, filter_str))
|
2011-10-13 18:42:43 -05:00
|
|
|
};
|
|
|
|
|
2011-07-16 19:04:20 -05:00
|
|
|
// Maybe pull out the ignored test and unignore them
|
2011-10-13 18:42:43 -05:00
|
|
|
filtered = if !opts.run_ignored {
|
|
|
|
filtered
|
|
|
|
} else {
|
2012-01-31 19:05:20 -06:00
|
|
|
fn filter(test: test_desc) -> option<test_desc> {
|
2011-10-13 18:42:43 -05:00
|
|
|
if test.ignore {
|
2012-08-01 19:30:05 -05:00
|
|
|
return option::some({name: test.name,
|
2012-05-24 16:49:39 -05:00
|
|
|
fn: copy test.fn,
|
2011-11-01 12:31:23 -05:00
|
|
|
ignore: false,
|
|
|
|
should_fail: test.should_fail});
|
2012-08-01 19:30:05 -05:00
|
|
|
} else { return option::none; }
|
2011-07-14 18:05:33 -05:00
|
|
|
};
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
vec::filter_map(filtered, |x| filter(x))
|
2011-10-13 18:42:43 -05:00
|
|
|
};
|
|
|
|
|
2011-07-16 19:04:20 -05:00
|
|
|
// Sort the tests alphabetically
|
2012-08-02 17:42:56 -05:00
|
|
|
filtered = {
|
|
|
|
pure fn lteq(t1: &test_desc, t2: &test_desc) -> bool {
|
|
|
|
str::le(&t1.name, &t2.name)
|
|
|
|
}
|
|
|
|
sort::merge_sort(lteq, filtered)
|
|
|
|
};
|
2011-07-11 18:33:21 -05:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
return filtered;
|
2011-07-11 18:33:21 -05:00
|
|
|
}
|
2011-07-09 18:08:03 -05:00
|
|
|
|
2012-01-19 15:00:30 -06:00
|
|
|
type test_future = {test: test_desc, wait: fn@() -> test_result};
|
2011-07-25 17:21:36 -05:00
|
|
|
|
2012-08-15 16:10:46 -05:00
|
|
|
fn run_test(+test: test_desc, monitor_ch: comm::Chan<monitor_msg>) {
|
2011-11-01 12:31:23 -05:00
|
|
|
if test.ignore {
|
2012-08-14 16:17:27 -05:00
|
|
|
core::comm::send(monitor_ch, (copy test, tr_ignored));
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-11-01 12:31:23 -05:00
|
|
|
}
|
|
|
|
|
2012-07-04 14:04:28 -05:00
|
|
|
do task::spawn {
|
2012-05-24 16:49:39 -05:00
|
|
|
let testfn = copy test.fn;
|
2012-07-23 19:00:43 -05:00
|
|
|
let mut result_future = none; // task::future_result(builder);
|
2012-08-07 13:26:03 -05:00
|
|
|
task::task().unlinked().future_result(|+r| {
|
2012-07-23 19:00:43 -05:00
|
|
|
result_future = some(r);
|
|
|
|
}).spawn(testfn);
|
2012-08-13 21:06:57 -05:00
|
|
|
let task_result = future::get(&option::unwrap(result_future));
|
2012-08-15 16:10:46 -05:00
|
|
|
let test_result = calc_result(test, task_result == task::Success);
|
2012-05-24 16:49:39 -05:00
|
|
|
comm::send(monitor_ch, (copy test, test_result));
|
2012-01-19 16:36:11 -06:00
|
|
|
};
|
2011-07-14 13:29:54 -05:00
|
|
|
}
|
|
|
|
|
2012-01-19 16:36:11 -06:00
|
|
|
fn calc_result(test: test_desc, task_succeeded: bool) -> test_result {
|
|
|
|
if task_succeeded {
|
|
|
|
if test.should_fail { tr_failed }
|
|
|
|
else { tr_ok }
|
|
|
|
} else {
|
|
|
|
if test.should_fail { tr_ok }
|
|
|
|
else { tr_failed }
|
|
|
|
}
|
2011-07-15 00:24:19 -05:00
|
|
|
}
|
|
|
|
|
2012-01-17 21:05:07 -06:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn do_not_run_ignored_tests() {
|
|
|
|
fn f() { fail; }
|
|
|
|
let desc = {
|
2012-07-14 00:57:48 -05:00
|
|
|
name: ~"whatever",
|
2012-01-17 21:05:07 -06:00
|
|
|
fn: f,
|
|
|
|
ignore: true,
|
|
|
|
should_fail: false
|
|
|
|
};
|
2012-08-14 16:17:27 -05:00
|
|
|
let p = core::comm::port();
|
|
|
|
let ch = core::comm::chan(p);
|
2012-01-19 16:36:11 -06:00
|
|
|
run_test(desc, ch);
|
2012-08-14 16:17:27 -05:00
|
|
|
let (_, res) = core::comm::recv(p);
|
2012-01-19 16:36:11 -06:00
|
|
|
assert res != tr_ok;
|
2012-01-17 21:05:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ignored_tests_result_in_ignored() {
|
|
|
|
fn f() { }
|
|
|
|
let desc = {
|
2012-07-14 00:57:48 -05:00
|
|
|
name: ~"whatever",
|
2012-01-17 21:05:07 -06:00
|
|
|
fn: f,
|
|
|
|
ignore: true,
|
|
|
|
should_fail: false
|
|
|
|
};
|
2012-08-14 16:17:27 -05:00
|
|
|
let p = core::comm::port();
|
|
|
|
let ch = core::comm::chan(p);
|
2012-01-19 16:36:11 -06:00
|
|
|
run_test(desc, ch);
|
2012-08-14 16:17:27 -05:00
|
|
|
let (_, res) = core::comm::recv(p);
|
2012-01-19 16:36:11 -06:00
|
|
|
assert res == tr_ignored;
|
2012-01-17 21:05:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2012-06-07 23:38:25 -05:00
|
|
|
#[ignore(cfg(windows))]
|
2012-01-17 21:05:07 -06:00
|
|
|
fn test_should_fail() {
|
|
|
|
fn f() { fail; }
|
|
|
|
let desc = {
|
2012-07-14 00:57:48 -05:00
|
|
|
name: ~"whatever",
|
2012-01-17 21:05:07 -06:00
|
|
|
fn: f,
|
|
|
|
ignore: false,
|
|
|
|
should_fail: true
|
|
|
|
};
|
2012-08-14 16:17:27 -05:00
|
|
|
let p = core::comm::port();
|
|
|
|
let ch = core::comm::chan(p);
|
2012-01-19 16:36:11 -06:00
|
|
|
run_test(desc, ch);
|
2012-08-14 16:17:27 -05:00
|
|
|
let (_, res) = core::comm::recv(p);
|
2012-01-19 15:00:30 -06:00
|
|
|
assert res == tr_ok;
|
2012-01-17 21:05:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_should_fail_but_succeeds() {
|
|
|
|
fn f() { }
|
|
|
|
let desc = {
|
2012-07-14 00:57:48 -05:00
|
|
|
name: ~"whatever",
|
2012-01-17 21:05:07 -06:00
|
|
|
fn: f,
|
|
|
|
ignore: false,
|
|
|
|
should_fail: true
|
|
|
|
};
|
2012-08-14 16:17:27 -05:00
|
|
|
let p = core::comm::port();
|
|
|
|
let ch = core::comm::chan(p);
|
2012-01-19 16:36:11 -06:00
|
|
|
run_test(desc, ch);
|
2012-08-14 16:17:27 -05:00
|
|
|
let (_, res) = core::comm::recv(p);
|
2012-01-19 15:00:30 -06:00
|
|
|
assert res == tr_failed;
|
2012-01-17 21:05:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn first_free_arg_should_be_a_filter() {
|
2012-07-14 00:57:48 -05:00
|
|
|
let args = ~[~"progname", ~"filter"];
|
2012-08-06 14:34:08 -05:00
|
|
|
let opts = match parse_opts(args) {
|
2012-08-14 18:54:13 -05:00
|
|
|
either::Left(o) => o,
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => fail ~"Malformed arg in first_free_arg_should_be_a_filter"
|
|
|
|
};
|
2012-08-02 17:42:56 -05:00
|
|
|
assert ~"filter" == option::get(opts.filter);
|
2012-01-17 21:05:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_ignored_flag() {
|
2012-07-14 00:57:48 -05:00
|
|
|
let args = ~[~"progname", ~"filter", ~"--ignored"];
|
2012-08-06 14:34:08 -05:00
|
|
|
let opts = match parse_opts(args) {
|
2012-08-14 18:54:13 -05:00
|
|
|
either::Left(o) => o,
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => fail ~"Malformed arg in parse_ignored_flag"
|
|
|
|
};
|
2012-01-17 21:05:07 -06:00
|
|
|
assert (opts.run_ignored);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn filter_for_ignored_option() {
|
|
|
|
// When we run ignored tests the test filter should filter out all the
|
|
|
|
// unignored tests and flip the ignore flag on the rest to false
|
|
|
|
|
2012-04-03 10:27:51 -05:00
|
|
|
let opts = {filter: option::none, run_ignored: true,
|
|
|
|
logfile: option::none};
|
2012-01-17 21:05:07 -06:00
|
|
|
let tests =
|
2012-07-14 00:57:48 -05:00
|
|
|
~[{name: ~"1", fn: fn~() { }, ignore: true, should_fail: false},
|
|
|
|
{name: ~"2", fn: fn~() { }, ignore: false, should_fail: false}];
|
2012-01-19 15:00:30 -06:00
|
|
|
let filtered = filter_tests(opts, tests);
|
2012-01-17 21:05:07 -06:00
|
|
|
|
|
|
|
assert (vec::len(filtered) == 1u);
|
2012-07-14 00:57:48 -05:00
|
|
|
assert (filtered[0].name == ~"1");
|
2012-01-17 21:05:07 -06:00
|
|
|
assert (filtered[0].ignore == false);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sort_tests() {
|
2012-04-03 10:27:51 -05:00
|
|
|
let opts = {filter: option::none, run_ignored: false,
|
|
|
|
logfile: option::none};
|
2012-01-17 21:05:07 -06:00
|
|
|
|
|
|
|
let names =
|
2012-07-14 00:57:48 -05:00
|
|
|
~[~"sha1::test", ~"int::test_to_str", ~"int::test_pow",
|
|
|
|
~"test::do_not_run_ignored_tests",
|
|
|
|
~"test::ignored_tests_result_in_ignored",
|
|
|
|
~"test::first_free_arg_should_be_a_filter",
|
|
|
|
~"test::parse_ignored_flag", ~"test::filter_for_ignored_option",
|
|
|
|
~"test::sort_tests"];
|
2012-01-17 21:05:07 -06:00
|
|
|
let tests =
|
|
|
|
{
|
2012-01-19 15:00:30 -06:00
|
|
|
let testfn = fn~() { };
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut tests = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for vec::each(names) |name| {
|
2012-06-01 13:10:27 -05:00
|
|
|
let test = {name: name, fn: copy testfn, ignore: false,
|
2012-01-17 21:05:07 -06:00
|
|
|
should_fail: false};
|
2012-06-29 18:26:56 -05:00
|
|
|
tests += ~[test];
|
2012-01-17 21:05:07 -06:00
|
|
|
}
|
|
|
|
tests
|
|
|
|
};
|
2012-01-19 15:00:30 -06:00
|
|
|
let filtered = filter_tests(opts, tests);
|
2012-01-17 21:05:07 -06:00
|
|
|
|
|
|
|
let expected =
|
2012-07-14 00:57:48 -05:00
|
|
|
~[~"int::test_pow", ~"int::test_to_str", ~"sha1::test",
|
|
|
|
~"test::do_not_run_ignored_tests",
|
|
|
|
~"test::filter_for_ignored_option",
|
|
|
|
~"test::first_free_arg_should_be_a_filter",
|
|
|
|
~"test::ignored_tests_result_in_ignored",
|
|
|
|
~"test::parse_ignored_flag",
|
|
|
|
~"test::sort_tests"];
|
2012-01-17 21:05:07 -06:00
|
|
|
|
|
|
|
let pairs = vec::zip(expected, filtered);
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
for vec::each(pairs) |p| { let (a, b) = copy p; assert (a == b.name); }
|
2012-02-22 04:44:11 -06:00
|
|
|
}
|
2012-01-17 21:05:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-09 18:08:03 -05:00
|
|
|
// Local Variables:
|
|
|
|
// mode: rust;
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|