Skip to content

Commit 8ace9b3

Browse files
committed
---
yaml --- r: 3798 b: refs/heads/master c: 64ad592 h: refs/heads/master v: v3
1 parent 9de0944 commit 8ace9b3

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: f666c97e6dec25f1894cf9e39bfe89f2a5d8fde3
2+
refs/heads/master: 64ad5928e7a8171aaf194912a500fd0c1be426d5

trunk/src/lib/test.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,63 @@ fn test_main(&test_desc[] tests) -> int {
3636
}
3737

3838
fn run_tests(&test_desc[] tests) -> bool {
39+
3940
auto out = io::stdout();
4041

42+
auto total = ivec::len(tests);
43+
out.write_line(#fmt("running %u tests", total));
44+
45+
auto passed = 0u;
46+
auto failed = 0u;
47+
4148
for (test_desc test in tests) {
42-
out.write_line("running " + test.name);
49+
out.write_str(#fmt("running %s ... ", test.name));
50+
if (run_test(test)) {
51+
passed += 1u;
52+
write_ok(out);
53+
out.write_line("");
54+
} else {
55+
failed += 1u;
56+
write_failed(out);
57+
out.write_line("");
58+
}
4359
}
4460

61+
assert passed + failed == total;
62+
63+
out.write_str(#fmt("\nresults: %u passed; %u failed\n\n",
64+
passed, failed));
65+
4566
ret true;
67+
68+
fn run_test(&test_desc test) -> bool {
69+
test.fn();
70+
ret true;
71+
}
72+
73+
fn write_ok(&io::writer out) {
74+
if (term::color_supported()) {
75+
term::fg(out.get_buf_writer(), term::color_green);
76+
}
77+
out.write_str("ok");
78+
if (term::color_supported()) {
79+
term::reset(out.get_buf_writer());
80+
}
81+
}
82+
83+
fn write_failed(&io::writer out) {
84+
if (term::color_supported()) {
85+
term::fg(out.get_buf_writer(), term::color_red);
86+
}
87+
out.write_str("FAILED");
88+
if (term::color_supported()) {
89+
term::reset(out.get_buf_writer());
90+
}
91+
}
4692
}
4793

4894

95+
4996
// Local Variables:
5097
// mode: rust;
5198
// fill-column: 78;

0 commit comments

Comments
 (0)