| Eric Fiselier | 4d5e91d | 2016-08-29 19:12:01 +0000 | [diff] [blame] | 1 | #ifndef TEST_OUTPUT_TEST_H |
| 2 | #define TEST_OUTPUT_TEST_H |
| 3 | |
| 4 | #undef NDEBUG |
| Eric Fiselier | 4d5e91d | 2016-08-29 19:12:01 +0000 | [diff] [blame] | 5 | #include <initializer_list> |
| 6 | #include <memory> |
| Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 +0000 | [diff] [blame^] | 7 | #include <string> |
| Eric Fiselier | 4d5e91d | 2016-08-29 19:12:01 +0000 | [diff] [blame] | 8 | #include <utility> |
| Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 +0000 | [diff] [blame^] | 9 | #include <vector> |
| 10 | |
| 11 | #include "../src/re.h" |
| 12 | #include "benchmark/benchmark.h" |
| Eric Fiselier | 4d5e91d | 2016-08-29 19:12:01 +0000 | [diff] [blame] | 13 | |
| 14 | #define CONCAT2(x, y) x##y |
| 15 | #define CONCAT(x, y) CONCAT2(x, y) |
| 16 | |
| Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 +0000 | [diff] [blame^] | 17 | #define ADD_CASES(...) int CONCAT(dummy, __LINE__) = ::AddCases(__VA_ARGS__) |
| Eric Fiselier | 4d5e91d | 2016-08-29 19:12:01 +0000 | [diff] [blame] | 18 | |
| 19 | #define SET_SUBSTITUTIONS(...) \ |
| Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 +0000 | [diff] [blame^] | 20 | int CONCAT(dummy, __LINE__) = ::SetSubstitutions(__VA_ARGS__) |
| Eric Fiselier | 4d5e91d | 2016-08-29 19:12:01 +0000 | [diff] [blame] | 21 | |
| 22 | enum MatchRules { |
| Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 +0000 | [diff] [blame^] | 23 | MR_Default, // Skip non-matching lines until a match is found. |
| 24 | MR_Next, // Match must occur on the next line. |
| 25 | MR_Not // No line between the current position and the next match matches |
| 26 | // the regex |
| Eric Fiselier | 4d5e91d | 2016-08-29 19:12:01 +0000 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | struct TestCase { |
| 30 | TestCase(std::string re, int rule = MR_Default); |
| 31 | |
| 32 | std::string regex_str; |
| 33 | int match_rule; |
| 34 | std::string substituted_regex; |
| 35 | std::shared_ptr<benchmark::Regex> regex; |
| 36 | }; |
| 37 | |
| 38 | enum TestCaseID { |
| 39 | TC_ConsoleOut, |
| 40 | TC_ConsoleErr, |
| 41 | TC_JSONOut, |
| 42 | TC_JSONErr, |
| 43 | TC_CSVOut, |
| 44 | TC_CSVErr, |
| 45 | |
| Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 +0000 | [diff] [blame^] | 46 | TC_NumID // PRIVATE |
| Eric Fiselier | 4d5e91d | 2016-08-29 19:12:01 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | // Add a list of test cases to be run against the output specified by |
| 50 | // 'ID' |
| 51 | int AddCases(TestCaseID ID, std::initializer_list<TestCase> il); |
| 52 | |
| 53 | // Add or set a list of substitutions to be performed on constructed regex's |
| 54 | // See 'output_test_helper.cc' for a list of default substitutions. |
| 55 | int SetSubstitutions( |
| 56 | std::initializer_list<std::pair<std::string, std::string>> il); |
| 57 | |
| 58 | // Run all output tests. |
| 59 | void RunOutputTests(int argc, char* argv[]); |
| 60 | |
| 61 | // ========================================================================= // |
| 62 | // --------------------------- Misc Utilities ------------------------------ // |
| 63 | // ========================================================================= // |
| 64 | |
| 65 | namespace { |
| 66 | |
| 67 | const char* const dec_re = "[0-9]*[.]?[0-9]+([eE][-+][0-9]+)?"; |
| 68 | |
| Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 +0000 | [diff] [blame^] | 69 | } // end namespace |
| Eric Fiselier | 4d5e91d | 2016-08-29 19:12:01 +0000 | [diff] [blame] | 70 | |
| Eric Fiselier | fbc9ff2 | 2016-11-05 00:30:27 +0000 | [diff] [blame^] | 71 | #endif // TEST_OUTPUT_TEST_H |