xref: /freebsd/contrib/kyua/engine/googletest_result.hpp (revision eb8f69902f7de8012a31a85db2f88a54584f81af)
1 // Copyright 2024 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 engine/googletest_result.hpp
30 /// Functions and types to process the results of googletest-based test cases.
31 
32 #if !defined(ENGINE_GOOGLETEST_RESULT_HPP)
33 #define ENGINE_GOOGLETEST_RESULT_HPP
34 
35 #include "engine/googletest_result_fwd.hpp"
36 
37 #include <istream>
38 #include <ostream>
39 
40 #include "model/test_result_fwd.hpp"
41 #include "utils/optional.hpp"
42 #include "utils/fs/path_fwd.hpp"
43 #include "utils/process/status_fwd.hpp"
44 
45 namespace engine {
46 
47 
48 /// Internal representation of the raw result files of googletest-based tests.
49 ///
50 /// This class is used exclusively to represent the transient result files read
51 /// from test cases before generating the "public" version of the result.  This
52 /// class should actually not be exposed in the header files, but it is for
53 /// testing purposes only.
54 class googletest_result {
55 public:
56     /// List of possible types for the test case result.
57     enum types {
58         broken,
59         disabled,
60         failed,
61         skipped,
62         successful,
63     };
64 
65 private:
66     /// The test case result.
67     types _type;
68 
69     /// A description of the test case result.
70     ///
71     /// Should always be present except for the passed type and sometimes with
72     /// the skipped type.
73     utils::optional< std::string > _reason;
74 
75 public:
76     googletest_result(const types);
77     googletest_result(const types, const std::string&);
78 
79     static googletest_result parse(std::istream&);
80     static googletest_result load(const utils::fs::path&);
81 
82     types type(void) const;
83     const utils::optional< std::string >& reason(void) const;
84 
85     bool good(void) const;
86     googletest_result apply(
87         const utils::optional< utils::process::status >&) const;
88     model::test_result externalize(void) const;
89 
90     bool operator==(const googletest_result&) const;
91     bool operator!=(const googletest_result&) const;
92 };
93 
94 
95 std::ostream& operator<<(std::ostream&, const googletest_result&);
96 
97 
98 model::test_result calculate_googletest_result(
99     const utils::optional< utils::process::status >&,
100     const utils::fs::path&);
101 
102 
103 /// A bogus identifier for nul reasons provided by the test writer.
104 ///
105 /// TODO: Support nul messages with skipped results in the schema, etc.
106 const std::string bogus_googletest_skipped_nul_message = "\n";
107 
108 
109 }  // namespace engine
110 
111 #endif  // !defined(ENGINE_GOOGLETEST_RESULT_HPP)
112