summaryrefslogtreecommitdiff
path: root/vendor/bandit/specs/reporters/xunit_reporter.spec.cpp
blob: 07f0c3b7d73ce3148b671e8eafcb7e55e0f50f68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <specs/specs.h>
namespace bd = bandit::detail;

go_bandit([](){

  describe("xunit_reporter:", [&](){
    std::unique_ptr<std::stringstream> stm;
    bd::default_failure_formatter formatter;
    std::unique_ptr<bd::xunit_reporter> reporter;

    auto output = [&](){ return stm->str(); };

    before_each([&](){
      stm = std::unique_ptr<std::stringstream>(new std::stringstream());
      reporter = std::unique_ptr<bd::xunit_reporter>(new bd::xunit_reporter(*stm, formatter));
    });
  
    describe("an empty test run", [&](){
    
      before_each([&](){
        reporter->test_run_starting();
        reporter->test_run_complete();
      });

      it("adds a header to the output", [&](){
        AssertThat(output(), StartsWith("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"));
      });

      it("outputs an empty test report", [&](){
        AssertThat(output(), Contains(
            "<testsuite name=\"bandit\" tests=\"0\" errors=\"0\" failures=\"0\">\n"
            "</testsuite>\n"));
      });
    
    });

    describe("a test run with one, successful, test", [&](){

        before_each([&](){
          reporter->test_run_starting();
          reporter->context_starting("my context");
          reporter->it_starting("my test");
          reporter->it_succeeded("my test");
          reporter->context_ended("my context");
          reporter->test_run_complete();
        });

        it("outputs info about the successful test", [&](){
          AssertThat(output(), Contains(
              "<testsuite name=\"bandit\" tests=\"1\" errors=\"0\" failures=\"0\">\n"
              "\t<testcase classname=\"my context\" name=\"my test\" time=\"0\">\n"
              "\t</testcase>\n"
              "</testsuite>\n"));
        });
    });

    describe("a test run with one, failing test", [&](){
    
      before_each([&](){
        reporter->test_run_starting();
        reporter->context_starting("my context");
        reporter->it_starting("my test");

        bd::assertion_exception exception("assertion failed!", "some_file", 123);
        reporter->it_failed("my test", exception);

        reporter->context_ended("my context");
        reporter->test_run_complete();
        
      });

      it("outputs the failing test", [&](){
        AssertThat(output(), Contains(
            "<testsuite name=\"bandit\" tests=\"1\" errors=\"0\" failures=\"1\">\n"
            "\t<testcase classname=\"my context\" name=\"my test\" time=\"0\">\n"
            "\t\t<failure message=\"some_file:123: assertion failed!\" />\n"
            "\t</testcase>\n"
            "</testsuite>\n"));
      });
    
    });

    describe("a test run with one test with an unknown error", [&](){
    
      before_each([&](){
        reporter->test_run_starting();
        reporter->context_starting("my context");
        reporter->it_starting("my test");

        reporter->it_unknown_error("my test");

        reporter->context_ended("my context");
        reporter->test_run_complete();
      });

      it("outputs the erroneous test", [&](){
        AssertThat(output(), Contains(
            "<testsuite name=\"bandit\" tests=\"1\" errors=\"0\" failures=\"1\">\n"
            "\t<testcase classname=\"my context\" name=\"my test\" time=\"0\">\n"
            "\t\t<failure message=\"Unknown exception\" />\n"
            "\t</testcase>\n"
            "</testsuite>\n"));
      });
    
    });

    describe("a test run with one test failing with characters that need escaping", [&](){
    
        before_each([&](){
          reporter->test_run_starting();
          reporter->context_starting("my context & < > \\ \"");
          reporter->it_starting("my test & < > \\ \"");

          bd::assertion_exception exception("assertion failed & < > \\ \"", "some_file", 123);
          reporter->it_failed("my test & < > \\ \"", exception);

          reporter->context_ended("my context & < > \\ \"");
          reporter->test_run_complete();
        });
      
      it("outputs the escaped characters", [&](){
        AssertThat(output(), Contains(
            "<testsuite name=\"bandit\" tests=\"1\" errors=\"0\" failures=\"1\">\n"
            "\t<testcase classname=\"my context &amp; &lt; &gt; &apos; &quot;\" name=\"my test &amp; &lt; &gt; &apos; &quot;\" time=\"0\">\n"
            "\t\t<failure message=\"some_file:123: assertion failed &amp; &lt; &gt; &apos; &quot;\" />\n"
            "\t</testcase>\n"
            "</testsuite>\n"));
      });
    
    });

    describe("a context with a skipped test", [&](){
    
        before_each([&](){
          reporter->test_run_starting();
          reporter->context_starting("my context");

          reporter->it_starting("my test");
          reporter->it_succeeded("my test");
          reporter->it_skip("my skipped test");

          reporter->context_ended("my context");
          reporter->test_run_complete();
        });
      
        it("outputs info about the skipped test", [&](){
          AssertThat(output(), Contains(
              "<testsuite name=\"bandit\" tests=\"1\" errors=\"0\" failures=\"0\" skipped=\"1\">\n"
              "\t<testcase classname=\"my context\" name=\"my test\" time=\"0\">\n"
              "\t</testcase>\n"
              "\t<testcase classname=\"my context\" name=\"my skipped test\" time=\"0\">\n"
              "\t\t<skipped />\n"
              "\t</testcase>\n"
              "</testsuite>\n"));
        });
    
    });
  
  });

});