xref: /freebsd/contrib/kyua/drivers/report_junit.hpp (revision 643ac419fafba89f5adda0e0ea75b538727453fb)
1 // Copyright 2014 The Kyua Authors.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 //   notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 //   notice, this list of conditions and the following disclaimer in the
12 //   documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 //   may be used to endorse or promote products derived from this software
15 //   without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 /// \file drivers/report_junit.hpp
30 /// Generates a JUnit report out of a test suite execution.
31 
32 #if !defined(ENGINE_REPORT_JUNIT_HPP)
33 #define ENGINE_REPORT_JUNIT_HPP
34 
35 #include <ostream>
36 #include <string>
37 
38 #include "drivers/scan_results.hpp"
39 #include "model/metadata_fwd.hpp"
40 #include "model/test_program_fwd.hpp"
41 #include "utils/datetime_fwd.hpp"
42 
43 namespace drivers {
44 
45 
46 extern const char* const junit_metadata_header;
47 extern const char* const junit_timing_header;
48 extern const char* const junit_stderr_header;
49 
50 
51 std::string junit_classname(const model::test_program&);
52 std::string junit_duration(const utils::datetime::delta&);
53 std::string junit_metadata(const model::metadata&);
54 std::string junit_timing(const utils::datetime::timestamp&,
55                          const utils::datetime::timestamp&);
56 
57 
58 /// Hooks for the scan_results driver to generate a JUnit report.
59 class report_junit_hooks : public drivers::scan_results::base_hooks {
60     /// Stream to which to write the report.
61     std::ostream& _output;
62 
63 public:
64     report_junit_hooks(std::ostream&);
65 
66     void got_context(const model::context&);
67     void got_result(store::results_iterator&);
68 
69     void end(const drivers::scan_results::result&);
70 };
71 
72 
73 }  // namespace drivers
74 
75 #endif  // !defined(ENGINE_REPORT_JUNIT_HPP)
76