1 /++
2   A module containing the ListReporter
3 
4   This is an example of how this reporter looks
5   <script type="text/javascript" src="https://asciinema.org/a/b4u0o9vba18dquzdgwif7anl5.js" id="asciicast-b4u0o9vba18dquzdgwif7anl5" async></script>
6 
7   Copyright: © 2017 Szabo Bogdan
8   License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
9   Authors: Szabo Bogdan
10 +/
11 module trial.reporters.list;
12 
13 import std.stdio;
14 import std.array;
15 import std.conv;
16 import std.datetime;
17 import std..string;
18 import std.algorithm;
19 
20 import trial.interfaces;
21 import trial.settings;
22 import trial.reporters.spec;
23 import trial.reporters.writer;
24 
25 /// The list reporter outputs a simple specifications list as test cases pass or
26 /// fail
27 class ListReporter : SpecReporter
28 {
29   this(Settings settings)
30   {
31     super(settings);
32   }
33 
34   this(ReportWriter writer)
35   {
36     super(writer);
37   }
38 
39   override
40   {
41     void begin(string suite, ref TestResult)
42     {
43 
44     }
45 
46     void end(string suite, ref TestResult test)
47     {
48       if(test.status == TestResult.Status.success) {
49         write!(Type.success)("", 1);
50         write!(Type.none)(suite ~ " " ~ test.name ~ "\n");
51       } else if(test.status == TestResult.Status.pending) {
52         write!(Type.pending)("", 1);
53         write!(Type.none)(suite ~ " " ~ test.name ~ "\n");
54       } else {
55         write!(Type.failure)(suite ~ " " ~ test.name ~ "\n", 1);
56         failedTests++;
57       }
58     }
59   }
60 }
61 
62 version (unittest)
63 {
64   import fluent.asserts;
65 }
66 
67 @("it should print a sucess test")
68 unittest
69 {
70   auto writer = new BufferedWriter;
71   auto reporter = new ListReporter(writer);
72 
73   auto test = new TestResult("other test");
74   test.status = TestResult.Status.success;
75 
76   reporter.end("some suite", test);
77 
78   writer.buffer.should.equal("  ✓ some suite other test\n");
79 }
80 
81 @("it should print two failing tests")
82 unittest
83 {
84   auto writer = new BufferedWriter;
85   auto reporter = new ListReporter(writer);
86 
87   auto test = new TestResult("other test");
88   test.status = TestResult.Status.failure;
89 
90   reporter.end("some suite", test);
91   reporter.end("some suite", test);
92 
93   writer.buffer.should.equal("  0) some suite other test\n  1) some suite other test\n");
94 }
95 
96 
97 @("it should print a pending test")
98 unittest
99 {
100   auto writer = new BufferedWriter;
101   auto reporter = new ListReporter(writer);
102 
103   auto test = new TestResult("other test");
104   test.status = TestResult.Status.pending;
105 
106   reporter.end("some suite", test);
107 
108   writer.buffer.should.equal("  - some suite other test\n");
109 }