Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:06

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
0008 #ifndef CATCH_REPORTER_SPEC_PARSER_HPP_INCLUDED
0009 #define CATCH_REPORTER_SPEC_PARSER_HPP_INCLUDED
0010 
0011 #include <catch2/internal/catch_console_colour.hpp>
0012 #include <catch2/internal/catch_optional.hpp>
0013 #include <catch2/internal/catch_stringref.hpp>
0014 
0015 #include <map>
0016 #include <string>
0017 #include <vector>
0018 
0019 namespace Catch {
0020 
0021     enum class ColourMode : std::uint8_t;
0022 
0023     namespace Detail {
0024         //! Splits the reporter spec into reporter name and kv-pair options
0025         std::vector<std::string> splitReporterSpec( StringRef reporterSpec );
0026 
0027         Optional<ColourMode> stringToColourMode( StringRef colourMode );
0028     }
0029 
0030     /**
0031      * Structured reporter spec that a reporter can be created from
0032      *
0033      * Parsing has been validated, but semantics have not. This means e.g.
0034      * that the colour mode is known to Catch2, but it might not be
0035      * compiled into the binary, and the output filename might not be
0036      * openable.
0037      */
0038     class ReporterSpec {
0039         std::string m_name;
0040         Optional<std::string> m_outputFileName;
0041         Optional<ColourMode> m_colourMode;
0042         std::map<std::string, std::string> m_customOptions;
0043 
0044         friend bool operator==( ReporterSpec const& lhs,
0045                                 ReporterSpec const& rhs );
0046         friend bool operator!=( ReporterSpec const& lhs,
0047                                 ReporterSpec const& rhs ) {
0048             return !( lhs == rhs );
0049         }
0050 
0051     public:
0052         ReporterSpec(
0053             std::string name,
0054             Optional<std::string> outputFileName,
0055             Optional<ColourMode> colourMode,
0056             std::map<std::string, std::string> customOptions );
0057 
0058         std::string const& name() const { return m_name; }
0059 
0060         Optional<std::string> const& outputFile() const {
0061             return m_outputFileName;
0062         }
0063 
0064         Optional<ColourMode> const& colourMode() const { return m_colourMode; }
0065 
0066         std::map<std::string, std::string> const& customOptions() const {
0067             return m_customOptions;
0068         }
0069     };
0070 
0071     /**
0072      * Parses provided reporter spec string into
0073      *
0074      * Returns empty optional on errors, e.g.
0075      *  * field that is not first and not a key+value pair
0076      *  * duplicated keys in kv pair
0077      *  * unknown catch reporter option
0078      *  * empty key/value in an custom kv pair
0079      *  * ...
0080      */
0081     Optional<ReporterSpec> parseReporterSpec( StringRef reporterSpec );
0082 
0083 }
0084 
0085 #endif // CATCH_REPORTER_SPEC_PARSER_HPP_INCLUDED