2011-07-14 11:29:54 -07:00
|
|
|
import std::test;
|
2011-07-14 16:05:33 -07:00
|
|
|
import std::str;
|
|
|
|
import std::option;
|
|
|
|
import std::either;
|
|
|
|
import std::ivec;
|
2011-07-14 11:29:54 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn do_not_run_ignored_tests() {
|
2011-07-27 14:19:39 +02:00
|
|
|
let ran = @mutable false;
|
|
|
|
let f = bind fn (ran: @mutable bool) { *ran = true; }(ran);
|
2011-07-14 11:29:54 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
let desc = {name: "whatever", fn: f, ignore: true};
|
2011-07-14 11:29:54 -07:00
|
|
|
|
2011-07-26 18:34:29 -07:00
|
|
|
test::run_test(desc, test::default_test_to_task);
|
2011-07-14 11:29:54 -07:00
|
|
|
|
2011-08-12 15:01:13 -07:00
|
|
|
assert (*ran == false);
|
2011-07-14 11:29:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ignored_tests_result_in_ignored() {
|
|
|
|
fn f() { }
|
2011-07-27 14:19:39 +02:00
|
|
|
let desc = {name: "whatever", fn: f, ignore: true};
|
|
|
|
let res = test::run_test(desc, test::default_test_to_task).wait();
|
|
|
|
assert (res == test::tr_ignored);
|
2011-07-14 11:29:54 -07:00
|
|
|
}
|
|
|
|
|
2011-07-14 16:05:33 -07:00
|
|
|
#[test]
|
|
|
|
fn first_free_arg_should_be_a_filter() {
|
2011-07-27 14:19:39 +02:00
|
|
|
let args = ~["progname", "filter"];
|
|
|
|
check (ivec::is_not_empty(args));
|
|
|
|
let opts = alt test::parse_opts(args) { either::left(o) { o } };
|
|
|
|
assert (str::eq("filter", option::get(opts.filter)));
|
2011-07-14 16:05:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_ignored_flag() {
|
2011-07-27 14:19:39 +02:00
|
|
|
let args = ~["progname", "filter", "--ignored"];
|
|
|
|
check (ivec::is_not_empty(args));
|
|
|
|
let opts = alt test::parse_opts(args) { either::left(o) { o } };
|
|
|
|
assert (opts.run_ignored);
|
2011-07-14 16:05:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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
|
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
let opts = {filter: option::none, run_ignored: true};
|
|
|
|
let tests =
|
|
|
|
~[{name: "1", fn: fn () { }, ignore: true},
|
|
|
|
{name: "2", fn: fn () { }, ignore: false}];
|
|
|
|
let filtered = test::filter_tests(opts, tests);
|
|
|
|
|
|
|
|
assert (ivec::len(filtered) == 1u);
|
|
|
|
assert (filtered.(0).name == "1");
|
|
|
|
assert (filtered.(0).ignore == false);
|
2011-07-14 16:05:33 -07:00
|
|
|
}
|
|
|
|
|
2011-07-16 17:04:20 -07:00
|
|
|
#[test]
|
|
|
|
fn sort_tests() {
|
2011-07-27 14:19:39 +02:00
|
|
|
let opts = {filter: option::none, run_ignored: false};
|
|
|
|
|
|
|
|
let names =
|
|
|
|
~["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"];
|
|
|
|
let tests =
|
|
|
|
{
|
|
|
|
let testfn = fn () { };
|
|
|
|
let tests = ~[];
|
|
|
|
for name: str in names {
|
|
|
|
let test = {name: name, fn: testfn, ignore: false};
|
|
|
|
tests += ~[test];
|
|
|
|
}
|
|
|
|
tests
|
|
|
|
};
|
|
|
|
let filtered = test::filter_tests(opts, tests);
|
|
|
|
|
|
|
|
let expected =
|
|
|
|
~["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"];
|
|
|
|
|
|
|
|
let pairs = ivec::zip(expected, filtered);
|
|
|
|
|
|
|
|
|
|
|
|
for p: {_0: str, _1: test::test_desc} in pairs {
|
|
|
|
assert (p._0 == p._1.name);
|
2011-07-16 17:04:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-14 11:29:54 -07:00
|
|
|
// Local Variables:
|
|
|
|
// mode: rust;
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|