2424#define STRINGIZE (x ) STRINGIZE_(x)
2525
2626static const std::string testSourceDir = SIMPLECPP_TEST_SOURCE_DIR;
27+
28+ enum Input {
29+ Stringstream,
30+ CharBuffer
31+ };
32+
33+ static Input USE_INPUT = Stringstream;
2734static int numberOfFailedAssertions = 0 ;
2835
2936#define ASSERT_EQUALS (expected, actual ) (assertEquals((expected), (actual), __LINE__))
@@ -40,11 +47,20 @@ static std::string pprint(const std::string &in)
4047 return ret;
4148}
4249
50+ static const char * inputString (Input input) {
51+ switch (input) {
52+ case Stringstream:
53+ return " Stringstream" ;
54+ case CharBuffer:
55+ return " CharBuffer" ;
56+ }
57+ }
58+
4359static int assertEquals (const std::string &expected, const std::string &actual, int line)
4460{
4561 if (expected != actual) {
4662 numberOfFailedAssertions++;
47- std::cerr << " ------ assertion failed ---------" << std::endl;
63+ std::cerr << " ------ assertion failed ( " << inputString (USE_INPUT) << " ) ---------" << std::endl;
4864 std::cerr << " line test.cpp:" << line << std::endl;
4965 std::cerr << " expected:" << pprint (expected) << std::endl;
5066 std::cerr << " actual:" << pprint (actual) << std::endl;
@@ -81,8 +97,14 @@ static void testcase(const std::string &name, void (*f)(), int argc, char * cons
8197
8298static simplecpp::TokenList makeTokenList (const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
8399{
84- std::istringstream istr (std::string (code, size));
85- return {istr,filenames,filename,outputList};
100+ switch (USE_INPUT) {
101+ case Stringstream: {
102+ std::istringstream istr (std::string (code, size));
103+ return {istr,filenames,filename,outputList};
104+ }
105+ case CharBuffer:
106+ return {{code, size}, filenames, filename, outputList};
107+ }
86108}
87109
88110static simplecpp::TokenList makeTokenList (const char code[], std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
@@ -3518,8 +3540,10 @@ static void leak()
35183540 }
35193541}
35203542
3521- int main (int argc, char **argv)
3543+ static void runTests (int argc, char **argv, Input input )
35223544{
3545+ USE_INPUT = input;
3546+
35233547 TEST_CASE (backslash);
35243548
35253549 TEST_CASE (builtin);
@@ -3786,6 +3810,11 @@ int main(int argc, char **argv)
37863810 TEST_CASE (fuzz_crash);
37873811
37883812 TEST_CASE (leak);
3813+ }
37893814
3815+ int main (int argc, char **argv)
3816+ {
3817+ runTests (argc, argv, Stringstream);
3818+ runTests (argc, argv, CharBuffer);
37903819 return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
37913820}
0 commit comments