Skip to content

Commit 6133aba

Browse files
committed
test.cpp: also run tests with char buffer
1 parent 5e00b60 commit 6133aba

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

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;
@@ -82,8 +99,14 @@ static void testcase(const std::string &name, void (*f)(), int argc, char * cons
8299

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

89112
static simplecpp::TokenList makeTokenList(const char code[], std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
@@ -3525,8 +3548,10 @@ static void leak()
35253548
}
35263549
}
35273550

3528-
int main(int argc, char **argv)
3551+
static void runTests(int argc, char **argv, Input input)
35293552
{
3553+
USE_INPUT = input;
3554+
35303555
TEST_CASE(backslash);
35313556

35323557
TEST_CASE(builtin);
@@ -3793,6 +3818,11 @@ int main(int argc, char **argv)
37933818
TEST_CASE(fuzz_crash);
37943819

37953820
TEST_CASE(leak);
3821+
}
37963822

3823+
int main(int argc, char **argv)
3824+
{
3825+
runTests(argc, argv, Input::Stringstream);
3826+
runTests(argc, argv, Input::CharBuffer);
37973827
return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
37983828
}

0 commit comments

Comments
 (0)