blob: 57d4397ad5db5d74b1b095eea75859184d9f4c65 [file] [log] [blame]
Eric Fiselier4d5e91d2016-08-29 19:12:01 +00001#ifndef TEST_OUTPUT_TEST_H
2#define TEST_OUTPUT_TEST_H
3
4#undef NDEBUG
Eric Fiselier4d5e91d2016-08-29 19:12:01 +00005#include <initializer_list>
6#include <memory>
Eric Fiselierfbc9ff22016-11-05 00:30:27 +00007#include <string>
Eric Fiselier4d5e91d2016-08-29 19:12:01 +00008#include <utility>
Eric Fiselierfbc9ff22016-11-05 00:30:27 +00009#include <vector>
10
11#include "../src/re.h"
12#include "benchmark/benchmark.h"
Eric Fiselier4d5e91d2016-08-29 19:12:01 +000013
14#define CONCAT2(x, y) x##y
15#define CONCAT(x, y) CONCAT2(x, y)
16
Eric Fiselierfbc9ff22016-11-05 00:30:27 +000017#define ADD_CASES(...) int CONCAT(dummy, __LINE__) = ::AddCases(__VA_ARGS__)
Eric Fiselier4d5e91d2016-08-29 19:12:01 +000018
19#define SET_SUBSTITUTIONS(...) \
Eric Fiselierfbc9ff22016-11-05 00:30:27 +000020 int CONCAT(dummy, __LINE__) = ::SetSubstitutions(__VA_ARGS__)
Eric Fiselier4d5e91d2016-08-29 19:12:01 +000021
22enum MatchRules {
Eric Fiselierfbc9ff22016-11-05 00:30:27 +000023 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 Fiselier4d5e91d2016-08-29 19:12:01 +000027};
28
29struct 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
38enum TestCaseID {
39 TC_ConsoleOut,
40 TC_ConsoleErr,
41 TC_JSONOut,
42 TC_JSONErr,
43 TC_CSVOut,
44 TC_CSVErr,
45
Eric Fiselierfbc9ff22016-11-05 00:30:27 +000046 TC_NumID // PRIVATE
Eric Fiselier4d5e91d2016-08-29 19:12:01 +000047};
48
49// Add a list of test cases to be run against the output specified by
50// 'ID'
51int 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.
55int SetSubstitutions(
56 std::initializer_list<std::pair<std::string, std::string>> il);
57
58// Run all output tests.
59void RunOutputTests(int argc, char* argv[]);
60
61// ========================================================================= //
62// --------------------------- Misc Utilities ------------------------------ //
63// ========================================================================= //
64
65namespace {
66
67const char* const dec_re = "[0-9]*[.]?[0-9]+([eE][-+][0-9]+)?";
68
Eric Fiselierfbc9ff22016-11-05 00:30:27 +000069} // end namespace
Eric Fiselier4d5e91d2016-08-29 19:12:01 +000070
Eric Fiselierfbc9ff22016-11-05 00:30:27 +000071#endif // TEST_OUTPUT_TEST_H