Skip to content

Commit 92a00a3

Browse files
committed
test.cpp: also run tests with char buffer
1 parent 15f8335 commit 92a00a3

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

test.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "simplecpp.h"
77

88
#include <cctype>
9+
#include <cstdint>
910
#include <cstdlib>
1011
#include <cstring>
1112
#include <exception>
@@ -24,6 +25,13 @@
2425
#define STRINGIZE(x) STRINGIZE_(x)
2526

2627
static const std::string testSourceDir = SIMPLECPP_TEST_SOURCE_DIR;
28+
29+
enum class Input : std::uint8_t {
30+
Stringstream,
31+
CharBuffer
32+
};
33+
34+
static Input USE_INPUT = Input::Stringstream;
2735
static int numberOfFailedAssertions = 0;
2836

2937
#define ASSERT_EQUALS(expected, actual) (assertEquals((expected), (actual), __LINE__))
@@ -40,11 +48,20 @@ static std::string pprint(const std::string &in)
4048
return ret;
4149
}
4250

51+
static const char* inputString(Input input) {
52+
switch (input) {
53+
case Input::Stringstream:
54+
return "Stringstream";
55+
case Input::CharBuffer:
56+
return "CharBuffer";
57+
}
58+
}
59+
4360
static int assertEquals(const std::string &expected, const std::string &actual, int line)
4461
{
4562
if (expected != actual) {
4663
numberOfFailedAssertions++;
47-
std::cerr << "------ assertion failed ---------" << std::endl;
64+
std::cerr << "------ assertion failed (" << inputString(USE_INPUT) << ")---------" << std::endl;
4865
std::cerr << "line test.cpp:" << line << std::endl;
4966
std::cerr << "expected:" << pprint(expected) << std::endl;
5067
std::cerr << "actual:" << pprint(actual) << std::endl;
@@ -81,8 +98,14 @@ static void testcase(const std::string &name, void (*f)(), int argc, char * cons
8198

8299
static 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)
83100
{
84-
std::istringstream istr(std::string(code, size));
85-
return {istr,filenames,filename,outputList};
101+
switch (USE_INPUT) {
102+
case Input::Stringstream: {
103+
std::istringstream istr(std::string(code, size));
104+
return {istr,filenames,filename,outputList};
105+
}
106+
case Input::CharBuffer:
107+
return {{code, size}, filenames, filename, outputList};
108+
}
86109
}
87110

88111
static simplecpp::TokenList makeTokenList(const char code[], std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
@@ -3518,8 +3541,10 @@ static void leak()
35183541
}
35193542
}
35203543

3521-
int main(int argc, char **argv)
3544+
static void runTests(int argc, char **argv, Input input)
35223545
{
3546+
USE_INPUT = input;
3547+
35233548
TEST_CASE(backslash);
35243549

35253550
TEST_CASE(builtin);
@@ -3786,6 +3811,11 @@ int main(int argc, char **argv)
37863811
TEST_CASE(fuzz_crash);
37873812

37883813
TEST_CASE(leak);
3814+
}
37893815

3816+
int main(int argc, char **argv)
3817+
{
3818+
runTests(argc, argv, Input::Stringstream);
3819+
runTests(argc, argv, Input::CharBuffer);
37903820
return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
37913821
}

0 commit comments

Comments
 (0)