1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
import std::test;
import std::str;
import std::option;
import std::either;
import std::ivec;
#[test]
fn do_not_run_ignored_tests() {
auto ran = @mutable false;
auto f = bind fn(@mutable bool ran) {
*ran = true;
} (ran);
auto desc = rec(name = "whatever",
fn = f,
ignore = true);
test::run_test(desc);
assert ran == false;
}
#[test]
fn ignored_tests_result_in_ignored() {
fn f() { }
auto desc = rec(name = "whatever",
fn = f,
ignore = true);
auto res = test::run_test(desc);
assert res == test::tr_ignored;
}
#[test]
fn first_free_arg_should_be_a_filter() {
auto args = ~["progname", "filter"];
check ivec::is_not_empty(args);
auto opts = alt test::parse_opts(args) { either::left(?o) { o } };
assert str::eq("filter", option::get(opts.filter));
}
#[test]
fn parse_ignored_flag() {
auto args = ~["progname", "filter", "--ignored"];
check ivec::is_not_empty(args);
auto opts = alt test::parse_opts(args) { either::left(?o) { o } };
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
auto opts = rec(filter = option::none,
run_ignored = true);
auto tests = ~[rec(name = "1",
fn = fn() {},
ignore = true),
rec(name = "2",
fn = fn() {},
ignore = false)];
auto filtered = test::filter_tests(opts, tests);
assert ivec::len(filtered) == 1u;
assert filtered.(0).name == "1";
assert filtered.(0).ignore == false;
}
#[test]
fn sort_tests() {
auto opts = rec(filter = option::none,
run_ignored = false);
auto 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"];
auto tests = {
auto testfn = fn() {};
auto tests = ~[];
for (str name in names) {
auto test = rec(name = name,
fn = testfn,
ignore = false);
tests += ~[test];
}
tests
};
auto filtered = test::filter_tests(opts, tests);
auto 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"];
auto pairs = ivec::zip(expected, filtered);
for (tup(str, test::test_desc) p in pairs) {
assert p._0 == p._1.name;
}
}
// 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:
|