trial.reporters.tap 59/61(96%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
320
330
340
350
360
370
380
390
400
410
420
435
440
455
460
470
480
490
501
511
520
530
540
550
560
570
580
590
600
610
620
630
640
650
660
670
684
691
700
713
720
730
743
752
761
770
781
790
800
812
820
830
840
850
860
870
880
890
900
916
920
931
940
951
961
971
981
991
1001
1011
1020
1030
1040
1050
1061
1071
1081
1091
1101
1111
1120
1130
1140
1150
1160
1170
1180
1190
1200
1210
1220
1231
1241
1251
1260
1272
1280
1290
1300
1310
1320
1331
1341
1350
1361
1371
1380
1391
1400
1412
1420
1430
1440
1450
1460
1471
1481
1490
1501
1511
1521
1530
1541
1550
1562
1570
1580
1590
1600
1610
1620
1630
1640
1650
1660
1670
1681
1691
1700
1711
1721
1730
1741
1750
1762
1770
1780
1790
1800
1811
1820
1830
1840
1851
1860
1871
1881
1890
1901
1911
1921
1930
1941
1950
1962
1970
1980
1990
2000
2010
2020
2030
2040
2050
2060
2070
2080
/++ A module containing the TAP13 reporter https://testanything.org/ This is an example of how this reporter looks <script type="text/javascript" src="https://asciinema.org/a/135734.js" id="asciicast-135734" async></script> Copyright: © 2017 Szabo Bogdan License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. Authors: Szabo Bogdan +/ module trial.reporters.tap; import std.conv; import std.string; import std.algorithm; version (Have_fluent_asserts) { version = Have_fluent_asserts_core; } version(Have_fluent_asserts_core) { import fluentasserts.core.base; import fluentasserts.core.results; } import trial.interfaces; import trial.reporters.writer; /// This reporter will print the results using thr Test anything protocol version 13 class TapReporter : ILifecycleListener, ITestCaseLifecycleListener { private { ReportWriter writer; } /// this() { writer = defaultWriter; } /// this(ReportWriter writer) { this.writer = writer; } /// void begin(ulong testCount) { writer.writeln("TAP version 13", ReportWriter.Context._default); writer.writeln("1.." ~ testCount.to!string, ReportWriter.Context._default); } /// void update() { } /// void end(SuiteResult[]) { } /// void begin(string, ref TestResult) { } /// void end(string suite, ref TestResult test) { if(test.status == TestResult.Status.success) { writer.writeln("ok - " ~ suite ~ "." ~ test.name, ReportWriter.Context._default); } else { writer.writeln("not ok - " ~ suite ~ "." ~ test.name, ReportWriter.Context._default); version(Have_fluent_asserts_core) { if(test.throwable !is null) { if(cast(TestException) test.throwable !is null) { printTestException(test); } else { printThrowable(test); } writer.writeln(""); } } else { printThrowable(test); } } } version(Have_fluent_asserts_core) { private void printTestException(ref TestResult test) { auto diagnostic = test.throwable.msg.split("\n").map!(a => "# " ~ a).join("\n"); auto msg = test.throwable.msg.split("\n")[0]; writer.writeln(diagnostic, ReportWriter.Context._default); writer.writeln(" ---", ReportWriter.Context._default); writer.writeln(" message: '" ~ msg ~ "'", ReportWriter.Context._default); writer.writeln(" severity: " ~ test.status.to!string, ReportWriter.Context._default); writer.writeln(" location:", ReportWriter.Context._default); writer.writeln(" fileName: '" ~ test.throwable.file.replace("'", "\'") ~ "'", ReportWriter.Context._default); writer.writeln(" line: " ~ test.throwable.line.to!string, ReportWriter.Context._default); } } private void printThrowable(ref TestResult test) { writer.writeln(" ---", ReportWriter.Context._default); writer.writeln(" message: '" ~ test.throwable.msg ~ "'", ReportWriter.Context._default); writer.writeln(" severity: " ~ test.status.to!string, ReportWriter.Context._default); writer.writeln(" location:", ReportWriter.Context._default); writer.writeln(" fileName: '" ~ test.throwable.file.replace("'", "\'") ~ "'", ReportWriter.Context._default); writer.writeln(" line: " ~ test.throwable.line.to!string, ReportWriter.Context._default); } } version(unittest) { version(Have_fluent_asserts_core) { import fluent.asserts; } } /// it should print "The Plan" at the beginning unittest { auto writer = new BufferedWriter; auto reporter = new TapReporter(writer); reporter.begin(10); writer.buffer.should.equal("TAP version 13\n1..10\n"); } /// it should print a sucess test unittest { auto writer = new BufferedWriter; auto reporter = new TapReporter(writer); auto test = new TestResult("other test"); test.status = TestResult.Status.success; reporter.end("some suite", test); writer.buffer.should.equal("ok - some suite.other test\n"); } /// it should print a failing test with a basic throwable unittest { auto writer = new BufferedWriter; auto reporter = new TapReporter(writer); auto test = new TestResult("other's test"); test.status = TestResult.Status.failure; test.throwable = new Exception("Test's failure", "file.d", 42); reporter.end("some suite", test); writer.buffer.should.equal("not ok - some suite.other's test\n" ~ " ---\n" ~ " message: 'Test\'s failure'\n" ~ " severity: failure\n" ~ " location:\n" ~ " fileName: 'file.d'\n" ~ " line: 42\n\n"); } /// it should not print the YAML if the throwable is missing unittest { auto writer = new BufferedWriter; auto reporter = new TapReporter(writer); auto test = new TestResult("other's test"); test.status = TestResult.Status.failure; reporter.end("some suite", test); writer.buffer.should.equal("not ok - some suite.other's test\n"); } /// it should print the results of a TestException unittest { IResult[] results = [ cast(IResult) new MessageResult("message"), cast(IResult) new ExtraMissingResult("a", "b") ]; auto exception = new TestException(results, "unknown", 0); auto writer = new BufferedWriter; auto reporter = new TapReporter(writer); auto test = new TestResult("other's test"); test.status = TestResult.Status.failure; test.throwable = exception; reporter.end("some suite", test); writer.buffer.should.equal("not ok - some suite.other's test\n" ~ "# message\n" ~ "# \n" ~ "# Extra:a\n" ~ "# Missing:b\n" ~ "# \n" ~ " ---\n" ~ " message: 'message'\n" ~ " severity: failure\n" ~ " location:\n" ~ " fileName: 'unknown'\n" ~ " line: 0\n\n"); }