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
395
400
415
420
430
440
450
461
471
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
630
644
651
660
673
680
690
703
712
721
730
741
750
760
772
780
790
800
810
820
830
840
850
860
876
880
891
900
911
921
931
941
951
961
971
980
990
1000
1010
1021
1031
1041
1051
1061
1071
1080
1090
1100
1110
1120
1130
1140
1150
1160
1170
1180
1191
1201
1211
1220
1232
1240
1250
1260
1270
1280
1291
1301
1310
1321
1331
1340
1351
1360
1372
1380
1390
1400
1410
1420
1431
1441
1450
1461
1471
1481
1490
1501
1510
1522
1530
1540
1550
1560
1570
1580
1590
1600
1610
1620
1630
1641
1651
1660
1671
1681
1690
1701
1710
1722
1730
1740
1750
1760
1771
1780
1790
1800
1811
1820
1831
1841
1850
1861
1871
1881
1890
1901
1910
1922
1930
1940
1950
1960
1970
1980
1990
2000
2010
2020
2030
2040
/++ 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) { 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) { 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) { 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) { 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"); }