trial.reporters.visualtrial 70/72(97%) 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
386
390
406
410
420
430
440
451
461
470
480
490
500
510
520
530
540
550
560
570
581
591
601
611
621
631
641
653
661
671
680
690
700
710
720
734
744
754
760
774
783
792
802
812
822
832
840
850
860
874
880
894
904
910
920
930
940
950
960
970
980
990
1001
1011
1021
1030
1042
1050
1060
1070
1080
1090
1101
1111
1120
1131
1141
1151
1161
1171
1180
1191
1200
1212
1220
1230
1240
1250
1260
1270
1280
1290
1300
1310
1320
1331
1341
1350
1361
1371
1381
1391
1400
1411
1420
1432
1440
1450
1460
1470
1480
1491
1501
1510
1521
1531
1541
1550
1561
1570
1582
1590
1600
1610
1620
1630
1640
1650
1660
1670
1680
1691
1701
1710
1721
1731
1740
1751
1760
1772
1780
1790
1800
1810
1821
1830
1840
1850
1861
1870
1881
1891
1900
1911
1921
1931
1940
1951
1960
1972
1980
1990
2000
2010
2020
2030
2040
2050
/++ A module containing the Visual Trial reporter used to send data to the Visual Studio Code plugin 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.visualtrial; import std.conv; import std.string; import std.algorithm; import std.stdio; 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 VisualTrialReporter : ILifecycleListener, ITestCaseLifecycleListener { private { ReportWriter writer; } /// this() { writer = defaultWriter; } /// this(ReportWriter writer) { this.writer = writer; } /// void begin(ulong testCount) { writer.writeln("", ReportWriter.Context._default); writer.writeln("", ReportWriter.Context._default); } /// void update() { } /// void end(SuiteResult[]) { } /// void begin(string suite, ref TestResult result) { std.stdio.stdout.flush; std.stdio.stderr.flush; writer.writeln("BEGIN TEST;", ReportWriter.Context._default); writer.writeln("suite:" ~ suite, ReportWriter.Context._default); writer.writeln("test:" ~ result.name, ReportWriter.Context._default); writer.writeln("file:" ~ result.fileName, ReportWriter.Context._default); writer.writeln("line:" ~ result.line.to!string, ReportWriter.Context._default); writer.writeln("labels:[" ~ result.labels.map!(a => a.toString).join(", ") ~ "]", ReportWriter.Context._default); std.stdio.stdout.flush; std.stdio.stderr.flush; } /// void end(string suite, ref TestResult test) { std.stdio.stdout.flush; std.stdio.stderr.flush; writer.writeln("status:" ~ test.status.to!string, ReportWriter.Context._default); if(test.status != TestResult.Status.success) { if(test.throwable !is null) { writer.writeln("errorFile:" ~ test.throwable.file, ReportWriter.Context._default); writer.writeln("errorLine:" ~ test.throwable.line.to!string, ReportWriter.Context._default); writer.writeln("message:" ~ test.throwable.msg.split("\n")[0], ReportWriter.Context._default); writer.write("error:", ReportWriter.Context._default); writer.writeln(test.throwable.toString, ReportWriter.Context._default); } } writer.writeln("END TEST;", ReportWriter.Context._default); std.stdio.stdout.flush; std.stdio.stderr.flush; } } version(unittest) { import fluent.asserts; } /// it should print "The Plan" at the beginning unittest { auto writer = new BufferedWriter; auto reporter = new VisualTrialReporter(writer); reporter.begin(10); writer.buffer.should.equal("\n\n"); } /// it should print the test location unittest { auto writer = new BufferedWriter; auto reporter = new VisualTrialReporter(writer); auto test = new TestResult("other test"); test.fileName = "someFile.d"; test.line = 100; test.labels = [ Label("name", "value"), Label("name1", "value1") ]; test.status = TestResult.Status.success; reporter.begin("some suite", test); writer.buffer.should.equal("BEGIN TEST;\n" ~ "suite:some suite\n" ~ "test:other test\n" ~ "file:someFile.d\n" ~ "line:100\n" ~ `labels:[{ "name": "name", "value": "value" }, { "name": "name1", "value": "value1" }]` ~ "\n"); } /// it should print a sucess test unittest { auto writer = new BufferedWriter; auto reporter = new VisualTrialReporter(writer); auto test = new TestResult("other test"); test.fileName = "someFile.d"; test.line = 100; test.status = TestResult.Status.success; reporter.end("some suite", test); writer.buffer.should.equal("status:success\nEND TEST;\n"); } /// it should print a failing test with a basic throwable unittest { auto writer = new BufferedWriter; auto reporter = new VisualTrialReporter(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("status:failure\n" ~ "errorFile:file.d\n" ~ "errorLine:42\n" ~ "message:Test's failure\n" ~ "error:object.Exception@file.d(42): Test's failure\n" ~ "END TEST;\n"); } /// it should not print the YAML if the throwable is missing unittest { auto writer = new BufferedWriter; auto reporter = new VisualTrialReporter(writer); auto test = new TestResult("other's test"); test.status = TestResult.Status.failure; reporter.end("some suite", test); writer.buffer.should.equal("status:failure\nEND 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 VisualTrialReporter(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("status:failure\n" ~ "errorFile:unknown\n" ~ "errorLine:0\n" ~ "message:message\n" ~ "error:fluentasserts.core.base.TestException@unknown(0): message\n\n" ~ " Extra:a\n" ~ " Missing:b\n\n" ~ "END TEST;\n"); }