GitHub

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:

Read the original on github.com ↗