• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef BASE_TESTING_TESTUTILS_H_
16 #define BASE_TESTING_TESTUTILS_H_
17 
18 #include <gmock/gmock.h>
19 
20 #include <regex>
21 #include <string>
22 
23 // The original gtest MatchesRegex will use different regex implementation on different platforms,
24 // e.g. on Windows gtest's limited regex engine is used while on Linux Posix ERE is used, which
25 // could result incompatible syntaxes. See
26 // https://github.com/google/googletest/blob/main/docs/advanced.md#regular-expression-syntax for
27 // details. std::regex will by default use the ECMAScript syntax for all platforms, which could fix
28 // this issue.
29 MATCHER_P(MatchesStdRegex, regStr, std::string("contains regular expression: ") + regStr) {
30     std::regex reg(regStr);
31     return std::regex_search(arg, reg);
32 }
33 
34 #endif  // BASE_TESTING_TESTUTILS_H_
35