Skip to content

Commit 0998278

Browse files
committed
Begin adding some test runner types to std. Issue #428
1 parent f72dbec commit 0998278

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/lib/std.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ mod term;
8787
mod time;
8888
mod smallintmap;
8989
mod ptr;
90+
mod test;
9091

9192
// Local Variables:
9293
// mode: rust;

src/lib/test.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Support code for rustc's built in test runner generator. Currently,
2+
// none of this is meant for users. It is intended to support the
3+
// simplest interface possible for representing and running tests
4+
// while providing a base that other test frameworks may build off of.
5+
6+
export test_name;
7+
export test_fn;
8+
export test_desc;
9+
export test_main;
10+
11+
// The name of a test. By convention this follows the rules for rust
12+
// paths, i.e it should be a series of identifiers seperated by double
13+
// colons. This way if some test runner wants to arrange the tests
14+
// heirarchically it may.
15+
type test_name = str;
16+
17+
// A function that runs a test. If the function returns successfully,
18+
// the test succeeds; if the function fails then the test fails. We
19+
// may need to come up with a more clever definition of test in order
20+
// to support isolation of tests into tasks.
21+
type test_fn = fn();
22+
23+
// The definition of a single test. A test runner will run a list of
24+
// these.
25+
type test_desc = rec(test_name name,
26+
test_fn fn);
27+
28+
// The default console test runner. It accepts the command line
29+
// arguments and a vector of test_descs (generated at compile time).
30+
fn test_main(&vec[str] args, &test_desc[] tests) -> int {
31+
if (run_tests(tests)) {
32+
ret 0;
33+
} else {
34+
ret -1;
35+
}
36+
}
37+
38+
fn run_tests(&test_desc[] tests) -> bool {
39+
auto out = io::stdout();
40+
41+
for (test_desc test in tests) {
42+
out.write_line("running " + test.name);
43+
}
44+
45+
ret true;
46+
}
47+
48+
49+
// Local Variables:
50+
// mode: rust;
51+
// fill-column: 78;
52+
// indent-tabs-mode: nil
53+
// c-basic-offset: 4
54+
// buffer-file-coding-system: utf-8-unix
55+
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
56+
// End:

0 commit comments

Comments
 (0)