Skip to content
Browse files

make default test reporter console reporter

  • Loading branch information...
1 parent a24cd6a commit 1dc4c9b6fbf869e3321a126cfb27b47e6179cec3 @krukow krukow committed
View
15 dunit/dunit_dsl.dart
@@ -16,16 +16,23 @@ test_case(f [as="Test"]) {
return new ClosureTestCase(f,as);
}
+
run([test=null,
as="Test",
- reporter=const TestReporter(),
runner=const TestRunner()]) {
if (test == null) return;
if (test is Function) {
test = test_case(test, as: as);
}
assert(test is TestCase || test is TestSuite);
- var res = runner.run(test);
- if (reporter is TestReporter) reporter.report(res);
- return res;
+ return runner.run(test);
+}
+
+report([test=null,
+ as="Test",
+ TestRunner runner=const TestRunner(),
+ TestReporter reporter=const TestReporter()]) {
+ reporter.report(run(test:test,
+ as:as,
+ runner:runner));
}
View
39 dunit/examples/console_reporter.dart
@@ -1,39 +0,0 @@
-#import("../dunit_base.dart");
-#import("../dunit_dsl.dart");
-#import("../dunit_reporters.dart");
-#import("../../pprint/pprint.dart");
-
-
-class ATest extends TestCase {
- ATest():super("ATest");
- tests() => {
-
- """Verifies the relationship between object A and b.
- Ensures a """ : testA,
-
- "it should B": testB,
-
- "it should C too": (){ }
- };
-
- testA() {
-
- }
- testB() {
- Expect.equals(42, "42", "but isnt 4242?");
- }
- int hashCode() => 42;
-}
-
-main() {
- run(test: () {
- Expect.equals(2,2);
- },
- as:"Expect two equals two",
- reporter:new ConsoleReporter());
-
- var tr = new TestRunner().run(new ATest());
- new ConsoleReporter().report(tr);
-
-
-}
View
6 dunit/examples/dsl.dart
@@ -6,10 +6,8 @@
main() {
- run(test: () {
- Expect.equals(2,2);
- },
- as:"Expect two equals two");
+ report(test: () { Expect.equals(2,2); },
+ as:"Expect two equals two");
}
View
15 dunit/examples/longer_test_suite.dart
@@ -2,16 +2,15 @@
#import("../dunit_dsl.dart");
#import("../dunit_reporters.dart");
#import("../../pprint/pprint.dart");
-#source("FirstTestCase.dart");
-#source("SecondTestCase.dart");
-#source("ThirdTestCase.dart");
+#source("tests/FirstTestCase.dart");
+#source("tests/SecondTestCase.dart");
+#source("tests/ThirdTestCase.dart");
main() {
- run(test: new TestSuite(name: "Sample Suite",
- tests: [new FirstTestCase(),
- new SecondTestCase(),
- new ThirdTestCase()]),
- reporter:new ConsoleReporter());
+ report(test: new TestSuite(name: "Sample Suite",
+ tests: [new FirstTestCase(),
+ new SecondTestCase(),
+ new ThirdTestCase()]));
}
View
0 dunit/examples/FirstTestCase.dart → dunit/examples/tests/FirstTestCase.dart
File renamed without changes.
View
0 dunit/examples/SecondTestCase.dart → dunit/examples/tests/SecondTestCase.dart
File renamed without changes.
View
0 dunit/examples/ThirdTestCase.dart → dunit/examples/tests/ThirdTestCase.dart
File renamed without changes.
View
106 dunit/src/base/TestReporter.dart
@@ -1,54 +1,66 @@
class TestReporter {
const TestReporter();
- void report(TestResult res) {
- res.results.forEach((k,tr) {
- if (k is TestSuite) {
- print("TestSuite: ${k.name}");
- report(tr['result']);
- }
- if (k is TestCase) {
- print("TestCase: ${k.name}");
- var r = tr['result'];
- var defects = r.defects();
- if (defects.length>0) {
- print("Defects:");
- pp(defects);
- }
- var passed = r.passed();
- if (passed.length>0) {
- print("Passed:");
- pp(passed);
-
- }
-
- }
-
-
- // pp(tr);
- // if (tr['result'] != null) {
- // tr['result'].defects().forEach((k,tr) {
- // pp(tr);
- // if (tr['result'] != null) {
- // pp("Test results:");
- // pp("defects:");
- // pp(tr['result'].defects());
- // pp("passed:");
- // pp(tr['result'].passed());
- // }
- // });
- // pp(" passed:");
- // tr['result'].passed().forEach((k,tr) {
- // pp(tr);
- // if (tr['result'] != null) {
- // pp("Test results:");
- // pp("defects:");
- // pp(tr['result'].defects());
- // pp("passed:");
- // pp(tr['result'].passed());
- // }
- // });
+ color(str,c) {
+ //return '\033[${c}m${str}\033[0m';
+ return str;
+ }
+ red(str) {
+ return color(str,'31');
+ }
+ green(str) {
+ return color(str,'32');
+ }
+ yellow(str) {
+ return color(str,'33');
+ }
+
+ print_defects(defects [indent=""]) {
+ defects.forEach((num, r) {
+ print("${indent}${r['name']}: ${r['outcome']} (${r['time']} us)");
+ print("${indent}${r['message']}");
+ print("${indent}${r['trace']}");
+
});
}
+ print_passed(passed [indent=""]) {
+ passed.forEach((num, r) {
+ print("${indent}${r['name']}: ${r['outcome']} (${r['time']} us)");
+ });
+
+ }
+
+ void report(TestResult res [indent=""]) {
+ var passed = res.passed();
+ var defects = res.defects();
+
+ _print(tests) {
+ tests.forEach((k,tr) {
+ if (k is TestSuite) {
+ print("${indent}TestSuite: ${k.name} (${tr['outcome']})");
+ report(tr['result'],indent:" "+indent);
+ }
+ if (k is TestCase) {
+ print("${indent}TestCase: ${k.name} (${tr['outcome']})");
+ var r = tr['result'];
+ var passed = r.passed();
+ if (passed.length>0) {
+ print("${indent}Passed:");
+ print_passed(passed,indent:" "+indent);
+ }
+
+ var defects = r.defects();
+ if (defects.length>0) {
+ print("${indent}Defects:");
+ print_defects(defects,indent:" "+indent);
+ }
+ }
+ });
+ }
+
+ _print(passed);
+ _print(defects);
+ }
+
}

0 comments on commit 1dc4c9b

Please sign in to comment.
Something went wrong with that request. Please try again.