Skip to content

Commit a294535

Browse files
committed
testrunner: prefer to pass code as sized const char[]
1 parent b5cb0f8 commit a294535

36 files changed

+1735
-1347
lines changed

test/helpers.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ namespace simplecpp {
4343
// TODO: make Tokenizer private
4444
class SimpleTokenizer : public Tokenizer {
4545
public:
46-
SimpleTokenizer(ErrorLogger& errorlogger, const char code[], bool cpp = true)
46+
template<size_t size>
47+
SimpleTokenizer(ErrorLogger& errorlogger, const char (&code)[size], bool cpp = true)
4748
: Tokenizer{s_settings, errorlogger}
4849
{
4950
if (!tokenize(code, cpp))
@@ -71,7 +72,20 @@ class SimpleTokenizer : public Tokenizer {
7172
* @param configuration E.g. "A" for code where "#ifdef A" is true
7273
* @return false if source code contains syntax errors
7374
*/
74-
bool tokenize(const char code[],
75+
template<size_t size>
76+
bool tokenize(const char (&code)[size],
77+
bool cpp = true,
78+
const std::string &configuration = emptyString)
79+
{
80+
std::istringstream istr(code);
81+
if (!list.createTokens(istr, cpp ? "test.cpp" : "test.c"))
82+
return false;
83+
84+
return simplifyTokens1(configuration);
85+
}
86+
87+
// TODO: get rid of this
88+
bool tokenize(const std::string& code,
7589
bool cpp = true,
7690
const std::string &configuration = emptyString)
7791
{
@@ -90,8 +104,8 @@ class SimpleTokenizer : public Tokenizer {
90104
class SimpleTokenList
91105
{
92106
public:
93-
94-
explicit SimpleTokenList(const char code[], Standards::Language lang = Standards::Language::CPP)
107+
template<size_t size>
108+
explicit SimpleTokenList(const char (&code)[size], Standards::Language lang = Standards::Language::CPP)
95109
{
96110
std::istringstream iss(code);
97111
if (!list.createTokens(iss, lang))

test/test64bit.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class Test64BitPortability : public TestFixture {
4040
}
4141

4242
#define check(code) check_(code, __FILE__, __LINE__)
43-
void check_(const char code[], const char* file, int line) {
43+
template<size_t size>
44+
void check_(const char (&code)[size], const char* file, int line) {
4445
// Tokenize..
4546
SimpleTokenizer tokenizer(settings, *this);
4647
ASSERT_LOC(tokenizer.tokenize(code), file, line);

test/testassert.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class TestAssert : public TestFixture {
3131
const Settings settings = settingsBuilder().severity(Severity::warning).build();
3232

3333
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
34-
void check_(const char* file, int line, const char code[]) {
34+
template<size_t size>
35+
void check_(const char* file, int line, const char (&code)[size]) {
3536
// Tokenize..
3637
SimpleTokenizer tokenizer(settings, *this);
3738
ASSERT_LOC(tokenizer.tokenize(code), file, line);

0 commit comments

Comments
 (0)