Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:25:00

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         // fall through
0117         break;
0118     };
0119 
0120     return ! s.manual();
0121 }
0122 
0123 //------------------------------------------------------------------------------
0124 
0125 // Utility functions for producing predicates to select suites.
0126 
0127 /** Returns a predicate that implements a smart matching rule.
0128     The predicate checks the suite, module, and library fields of the
0129     suite_info in that order. When it finds a match, it changes modes
0130     depending on what was found:
0131 
0132         If a suite is matched first, then only the suite is selected. The
0133         suite may be marked manual.
0134 
0135         If a module is matched first, then only suites from that module
0136         and library not marked manual are selected from then on.
0137 
0138         If a library is matched first, then only suites from that library
0139         not marked manual are selected from then on.
0140 
0141 */
0142 inline
0143 selector
0144 match_auto(std::string const& name)
0145 {
0146     return selector(selector::automatch, name);
0147 }
0148 
0149 /** Return a predicate that matches all suites not marked manual. */
0150 inline
0151 selector
0152 match_all()
0153 {
0154     return selector(selector::all);
0155 }
0156 
0157 /** Returns a predicate that matches a specific suite. */
0158 inline
0159 selector
0160 match_suite(std::string const& name)
0161 {
0162     return selector(selector::suite, name);
0163 }
0164 
0165 /** Returns a predicate that matches all suites in a library. */
0166 inline
0167 selector
0168 match_library(std::string const& name)
0169 {
0170     return selector(selector::library, name);
0171 }
0172 
0173 } // unit_test
0174 } // beast
0175 } // boost
0176 
0177 #endif