trial.reporters.tap 0/29(0%) 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
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
630
640
650
660
670
680
690
700
710
720
730
740
750
760
770
780
790
800
810
820
830
840
850
860
870
880
890
900
910
920
930
940
950
960
970
980
990
1000
1010
1020
1030
1040
1050
1060
1070
1080
1090
1100
1110
1120
1130
1140
1150
1160
1170
1180
1190
1200
1210
1220
1230
1240
1250
1260
1270
1280
1290
1300
1310
1320
1330
1340
1350
1360
1370
1380
1390
1400
1410
1420
1430
1440
1450
1460
1470
1480
1490
1500
1510
1520
1530
1540
1550
1560
1570
1580
1590
1600
1610
1620
1630
1640
1650
1660
1670
1680
1690
1700
1710
1720
1730
1740
1750
1760
1770
1780
1790
1800
1810
1820
1830
1840
1850
1860
1870
1880
1890
1900
1910
1920
1930
1940
1950
1960
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"); }