Skip to content

Commit 5a85b00

Browse files
committed
test.cpp: also run tests with char buffer
1 parent 4044f8f commit 5a85b00

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>
@@ -25,6 +26,13 @@
2526
#define STRINGIZE(x) STRINGIZE_(x)
2627

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

3038
#define ASSERT_EQUALS(expected, actual) (assertEquals((expected), (actual), __LINE__))
@@ -41,11 +49,20 @@ static std::string pprint(const std::string &in)
4149
return ret;
4250
}
4351

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

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

90113
static simplecpp::TokenList makeTokenList(const char code[], std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
@@ -3609,8 +3632,10 @@ static void leak()
36093632
}
36103633
}
36113634

3612-
int main(int argc, char **argv)
3635+
static void runTests(int argc, char **argv, Input input)
36133636
{
3637+
USE_INPUT = input;
3638+
36143639
TEST_CASE(backslash);
36153640

36163641
TEST_CASE(builtin);
@@ -3881,6 +3906,11 @@ int main(int argc, char **argv)
38813906
TEST_CASE(fuzz_crash);
38823907

38833908
TEST_CASE(leak);
3909+
}
38843910

3911+
int main(int argc, char **argv)
3912+
{
3913+
runTests(argc, argv, Input::Stringstream);
3914+
runTests(argc, argv, Input::CharBuffer);
38853915
return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
38863916
}

0 commit comments

Comments
 (0)