blob: 98ce54b2e48073eb4b1d28887e7667f069223036 [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
5#include "benchmark/benchmark.h"
6#include "../src/re.h"
7#include <vector>
8#include <string>
9#include <initializer_list>
10#include <memory>
11#include <utility>
12
13#define CONCAT2(x, y) x##y
14#define CONCAT(x, y) CONCAT2(x, y)
15
16#define ADD_CASES(...) \
17 int CONCAT(dummy, __LINE__) = ::AddCases(__VA_ARGS__)
18
19#define SET_SUBSTITUTIONS(...) \
20 int CONCAT(dummy, __LINE__) = ::SetSubstitutions(__VA_ARGS__)
21
22enum MatchRules {
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
27};
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
46 TC_NumID // PRIVATE
47};
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
69} // end namespace
70
71
72#endif // TEST_OUTPUT_TEST_H