Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 08:09:28

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_UNIT_TEST_MATCH_HPP
0011 #define BOOST_BEAST_UNIT_TEST_MATCH_HPP
0012 
0013 #include <boost/beast/_experimental/unit_test/suite_info.hpp>
0014 #include <string>
0015 
0016 namespace boost {
0017 namespace beast {
0018 namespace unit_test {
0019 
0020 // Predicate for implementing matches
0021 class selector
0022 {
0023 public:
0024     enum mode_t
0025     {
0026         // Run all tests except manual ones
0027         all,
0028 
0029         // Run tests that match in any field
0030         automatch,
0031 
0032         // Match on suite
0033         suite,
0034 
0035         // Match on library
0036         library,
0037 
0038         // Match on module (used internally)
0039         module,
0040 
0041         // Match nothing (used internally)
0042         none
0043     };
0044 
0045 private:
0046     mode_t mode_;
0047     std::string pat_;
0048     std::string library_;
0049 
0050 public:
0051     template<class = void>
0052     explicit
0053     selector(mode_t mode, std::string const& pattern = "");
0054 
0055     template<class = void>
0056     bool
0057     operator()(suite_info const& s);
0058 };
0059 
0060 //------------------------------------------------------------------------------
0061 
0062 template<class>
0063 selector::selector(mode_t mode, std::string const& pattern)
0064     : mode_(mode)
0065     , pat_(pattern)
0066 {
0067     if(mode_ == automatch && pattern.empty())
0068         mode_ = all;
0069 }
0070 
0071 template<class>
0072 bool
0073 selector::operator()(suite_info const& s)
0074 {
0075     switch(mode_)
0076     {
0077     case automatch:
0078         // suite or full name
0079         if(s.name() == pat_ || s.full_name() == pat_)
0080         {
0081             mode_ = none;
0082             return true;
0083         }
0084 
0085         // check module
0086         if(pat_ == s.module())
0087         {
0088             mode_ = module;
0089             library_ = s.library();
0090             return ! s.manual();
0091         }
0092 
0093         // check library
0094         if(pat_ == s.library())
0095         {
0096             mode_ = library;
0097             return ! s.manual();
0098         }
0099 
0100         return false;
0101 
0102     case suite:
0103         return pat_ == s.name();
0104 
0105     case module:
0106         return pat_ == s.module() && ! s.manual();
0107 
0108     case library:
0109         return pat_ == s.library() && ! s.manual();
0110 
0111     case none:
0112         return false;
0113 
0114     case all:
0115     default:
0116         break;
0117     };
0118 
0119     return ! s.manual();
0120 }
0121 
0122 //------------------------------------------------------------------------------
0123 
0124 // Utility functions for producing predicates to select suites.
0125 
0126 /** Returns a predicate that implements a smart matching rule.
0127     The predicate checks the suite, module, and library fields of the
0128     suite_info in that order. When it finds a match, it changes modes
0129     depending on what was found:
0130 
0131         If a suite is matched first, then only the suite is selected. The
0132         suite may be marked manual.
0133 
0134         If a module is matched first, then only suites from that module
0135         and library not marked manual are selected from then on.
0136 
0137         If a library is matched first, then only suites from that library
0138         not marked manual are selected from then on.
0139 
0140 */
0141 inline
0142 selector
0143 match_auto(std::string const& name)
0144 {
0145     return selector(selector::automatch, name);
0146 }
0147 
0148 /** Return a predicate that matches all suites not marked manual. */
0149 inline
0150 selector
0151 match_all()
0152 {
0153     return selector(selector::all);
0154 }
0155 
0156 /** Returns a predicate that matches a specific suite. */
0157 inline
0158 selector
0159 match_suite(std::string const& name)
0160 {
0161     return selector(selector::suite, name);
0162 }
0163 
0164 /** Returns a predicate that matches all suites in a library. */
0165 inline
0166 selector
0167 match_library(std::string const& name)
0168 {
0169     return selector(selector::library, name);
0170 }
0171 
0172 } // unit_test
0173 } // beast
0174 } // boost
0175 
0176 #endif