Skip to content

Commit 1dcc5eb

Browse files
committed
testrunner: more usage of Simple* helpers
1 parent 5fcfd61 commit 1dcc5eb

File tree

5 files changed

+44
-73
lines changed

5 files changed

+44
-73
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,10 +856,10 @@ test/testtoken.o: test/testtoken.cpp lib/addoninfo.h lib/check.h lib/color.h lib
856856
test/testtokenize.o: test/testtokenize.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
857857
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testtokenize.cpp
858858

859-
test/testtokenlist.o: test/testtokenlist.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
859+
test/testtokenlist.o: test/testtokenlist.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
860860
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testtokenlist.cpp
861861

862-
test/testtokenrange.o: test/testtokenrange.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/tokenrange.h lib/utils.h lib/vfvalue.h test/fixture.h
862+
test/testtokenrange.o: test/testtokenrange.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/tokenrange.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
863863
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testtokenrange.cpp
864864

865865
test/testtype.o: test/testtype.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checktype.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h

test/helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class SimpleTokenizer {
6363
class SimpleTokenList
6464
{
6565
public:
66+
6667
explicit SimpleTokenList(const char code[], bool cpp = true)
6768
{
6869
std::istringstream iss(code);

test/testlibrary.cpp

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ class TestLibrary : public TestFixture {
117117
" </function>\n"
118118
"</def>";
119119

120-
TokenList tokenList(&settings);
121-
std::istringstream istr("foo();");
122-
tokenList.createTokens(istr, Standards::Language::CPP);
120+
const char code[] = "foo();";
121+
SimpleTokenList tokenList(code);
123122
tokenList.front()->next()->astOperand1(tokenList.front());
124123

125124
Library library;
@@ -140,16 +139,14 @@ class TestLibrary : public TestFixture {
140139
Library library;
141140
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
142141
{
143-
TokenList tokenList(&settings);
144-
std::istringstream istr("fred.foo(123);"); // <- wrong scope, not library function
145-
tokenList.createTokens(istr, Standards::Language::CPP);
142+
const char code[] = "fred.foo(123);"; // <- wrong scope, not library function
143+
SimpleTokenList tokenList(code);
146144

147145
ASSERT(library.isNotLibraryFunction(tokenList.front()->tokAt(2)));
148146
}
149147
{
150-
TokenList tokenList(&settings);
151-
std::istringstream istr("Fred::foo(123);"); // <- wrong scope, not library function
152-
tokenList.createTokens(istr, Standards::Language::CPP);
148+
const char code[] = "Fred::foo(123);"; // <- wrong scope, not library function
149+
SimpleTokenList tokenList(code);
153150

154151
ASSERT(library.isNotLibraryFunction(tokenList.front()->tokAt(2)));
155152
}
@@ -232,9 +229,8 @@ class TestLibrary : public TestFixture {
232229
" </function>\n"
233230
"</def>";
234231

235-
TokenList tokenList(&settings);
236-
std::istringstream istr("Fred foo(123);"); // <- Variable declaration, not library function
237-
tokenList.createTokens(istr, Standards::Language::CPP);
232+
const char code[] = "Fred foo(123);"; // <- Variable declaration, not library function
233+
SimpleTokenList tokenList(code);
238234
tokenList.front()->next()->astOperand1(tokenList.front());
239235
tokenList.front()->next()->varId(1);
240236

@@ -292,9 +288,8 @@ class TestLibrary : public TestFixture {
292288
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
293289
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[-1].notuninit);
294290

295-
TokenList tokenList(&settings);
296-
std::istringstream istr("foo(a,b,c,d,e);");
297-
tokenList.createTokens(istr, Standards::Language::CPP);
291+
const char code[] = "foo(a,b,c,d,e);";
292+
SimpleTokenList tokenList(code);
298293
tokenList.front()->next()->astOperand1(tokenList.front());
299294

300295
ASSERT_EQUALS(false, library.isuninitargbad(tokenList.front(), 1));
@@ -317,9 +312,8 @@ class TestLibrary : public TestFixture {
317312
Library library;
318313
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
319314

320-
TokenList tokenList(&settings);
321-
std::istringstream istr("foo(a,b,c,d);");
322-
tokenList.createTokens(istr, Standards::Language::CPP);
315+
const char code[] = "foo(a,b,c,d);";
316+
SimpleTokenList tokenList(code);
323317
tokenList.front()->next()->astOperand1(tokenList.front());
324318

325319
ASSERT(Library::ArgumentChecks::Direction::DIR_IN == library.getArgDirection(tokenList.front(), 1));
@@ -349,9 +343,8 @@ class TestLibrary : public TestFixture {
349343
Library library;
350344
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
351345

352-
TokenList tokenList(&settings);
353-
std::istringstream istr("foo(a,b,c,d,e,f,g,h,i,j,k);");
354-
tokenList.createTokens(istr, Standards::Language::CPP);
346+
const char code[] = "foo(a,b,c,d,e,f,g,h,i,j,k);";
347+
SimpleTokenList tokenList(code);
355348
tokenList.front()->next()->astOperand1(tokenList.front());
356349

357350
// 1-
@@ -491,9 +484,8 @@ class TestLibrary : public TestFixture {
491484
Library library;
492485
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
493486

494-
TokenList tokenList(&settings);
495-
std::istringstream istr("foo(a,b,c,d,e);");
496-
tokenList.createTokens(istr, Standards::Language::CPP);
487+
const char code[] = "foo(a,b,c,d,e);";
488+
SimpleTokenList tokenList(code);
497489
tokenList.front()->next()->astOperand1(tokenList.front());
498490

499491
// arg1: type=strlen arg2
@@ -554,16 +546,14 @@ class TestLibrary : public TestFixture {
554546
ASSERT(library.functions.at("bar").argumentChecks.empty());
555547

556548
{
557-
TokenList tokenList(&settings);
558-
std::istringstream istr("Foo::foo();");
559-
tokenList.createTokens(istr, Standards::Language::CPP);
549+
const char code[] = "Foo::foo();";
550+
SimpleTokenList tokenList(code);
560551
ASSERT(library.isnotnoreturn(tokenList.front()->tokAt(2)));
561552
}
562553

563554
{
564-
TokenList tokenList(&settings);
565-
std::istringstream istr("bar();");
566-
tokenList.createTokens(istr, Standards::Language::CPP);
555+
const char code[] = "bar();";
556+
SimpleTokenList tokenList(code);
567557
ASSERT(library.isnotnoreturn(tokenList.front()));
568558
}
569559
}
@@ -635,9 +625,8 @@ class TestLibrary : public TestFixture {
635625
Library library;
636626
ASSERT(loadxmldata(library, xmldata, sizeof(xmldata)));
637627

638-
TokenList tokenList(&settings);
639-
std::istringstream istr("a(); b();");
640-
tokenList.createTokens(istr, Standards::Language::CPP);
628+
const char code[] = "a(); b();";
629+
SimpleTokenList tokenList(code);
641630

642631
const Library::WarnInfo* a = library.getWarnInfo(tokenList.front());
643632
const Library::WarnInfo* b = library.getWarnInfo(tokenList.front()->tokAt(4));

test/testtokenlist.cpp

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "settings.h"
2020
#include "fixture.h"
21+
#include "helpers.h"
2122
#include "platform.h"
2223
#include "standards.h"
2324
#include "token.h"
@@ -62,11 +63,7 @@ class TestTokenList : public TestFixture {
6263

6364
errout.str("");
6465

65-
// tokenize..
66-
TokenList tokenlist(&settings);
67-
std::istringstream istr(code);
68-
tokenlist.createTokens(istr, "a.cpp");
69-
66+
SimpleTokenList tokenlist(code);
7067
ASSERT(Token::simpleMatch(tokenlist.front(), "a + + 1 ; 1 + + b ;"));
7168
}
7269

@@ -75,9 +72,7 @@ class TestTokenList : public TestFixture {
7572
const char code[] = "for a int delete true";
7673

7774
{
78-
TokenList tokenlist(&settings);
79-
std::istringstream istr(code);
80-
tokenlist.createTokens(istr, "a.c");
75+
SimpleTokenList tokenlist(code, false);
8176

8277
ASSERT_EQUALS(true, tokenlist.front()->isKeyword());
8378
ASSERT_EQUALS(true, tokenlist.front()->isControlFlowKeyword());
@@ -93,9 +88,7 @@ class TestTokenList : public TestFixture {
9388
ASSERT_EQUALS(false, tokenlist.front()->tokAt(4)->isControlFlowKeyword());
9489
}
9590
{
96-
TokenList tokenlist(&settings);
97-
std::istringstream istr(code);
98-
tokenlist.createTokens(istr, "a.cpp");
91+
SimpleTokenList tokenlist(code);
9992

10093
ASSERT_EQUALS(true, tokenlist.front()->isKeyword());
10194
ASSERT_EQUALS(true, tokenlist.front()->isControlFlowKeyword());
@@ -113,17 +106,13 @@ class TestTokenList : public TestFixture {
113106

114107
{
115108
const char code2[] = "_Generic"; // C11 keyword
116-
TokenList tokenlist(&settings); // default settings use latest standard
117-
std::istringstream istr(code2);
118-
tokenlist.createTokens(istr, "a.cpp");
109+
SimpleTokenList tokenlist(code2); // default settings use latest standard
119110
ASSERT_EQUALS(false, tokenlist.front()->isKeyword());
120111
}
121112

122113
{
123114
const char code2[] = "_Generic"; // C11 keyword
124-
TokenList tokenlist(&settings); // default settings use latest standard
125-
std::istringstream istr(code2);
126-
tokenlist.createTokens(istr, "a.c");
115+
SimpleTokenList tokenlist(code2, false); // default settings use latest standard
127116
ASSERT_EQUALS(true, tokenlist.front()->isKeyword());
128117
}
129118

@@ -138,17 +127,13 @@ class TestTokenList : public TestFixture {
138127

139128
{
140129
const char code2[] = "co_return"; // C++20 keyword
141-
TokenList tokenlist(&settings); // default settings use latest standard
142-
std::istringstream istr(code2);
143-
tokenlist.createTokens(istr, "a.cpp");
130+
SimpleTokenList tokenlist(code2); // default settings use latest standard
144131
ASSERT_EQUALS(true, tokenlist.front()->isKeyword());
145132
}
146133

147134
{
148135
const char code2[] = "co_return"; // C++20 keyword
149-
TokenList tokenlist(&settings); // default settings use latest standard
150-
std::istringstream istr(code2);
151-
tokenlist.createTokens(istr, "a.c");
136+
SimpleTokenList tokenlist(code2, false); // default settings use latest standard
152137
ASSERT_EQUALS(false, tokenlist.front()->isKeyword());
153138
}
154139

test/testtokenrange.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "settings.h"
2020
#include "fixture.h"
21+
#include "helpers.h"
2122
#include "token.h"
2223
#include "tokenize.h"
2324
#include "tokenlist.h"
@@ -69,32 +70,28 @@ class TestTokenRange : public TestFixture {
6970
}
7071

7172
void enumerationToEnd() const {
72-
std::istringstream istr("void a(){} void main(){ if(true){a();} }");
73-
TokenList tokenList(&settingsDefault);
74-
tokenList.createTokens(istr, "test.cpp");
73+
const char code[] = "void a(){} void main(){ if(true){a();} }";
74+
SimpleTokenList tokenList(code);
7575
ASSERT_EQUALS("", testTokenRange(ConstTokenRange{ tokenList.front(), nullptr }, tokenList.front(), nullptr));
7676
}
7777

7878
void untilHelperToEnd() const {
79-
std::istringstream istr("void a(){} void main(){ if(true){a();} }");
80-
TokenList tokenList(&settingsDefault);
81-
tokenList.createTokens(istr, "test.cpp");
79+
const char code[] = "void a(){} void main(){ if(true){a();} }";
80+
SimpleTokenList tokenList(code);
8281
ASSERT_EQUALS("", testTokenRange(tokenList.front()->until(nullptr), tokenList.front(), nullptr));
8382
}
8483

8584
void untilHelperPartWay() const {
86-
std::istringstream istr("void a(){} void main(){ if(true){a();} }");
87-
TokenList tokenList(&settingsDefault);
88-
tokenList.createTokens(istr, "test.cpp");
85+
const char code[] = "void a(){} void main(){ if(true){a();} }";
86+
SimpleTokenList tokenList(code);
8987
const Token* start = tokenList.front()->tokAt(4);
9088
const Token* end = start->tokAt(8);
9189
ASSERT_EQUALS("", testTokenRange(start->until(end), start, end));
9290
}
9391

9492
void partialEnumeration() const {
95-
std::istringstream istr("void a(){} void main(){ if(true){a();} }");
96-
TokenList tokenList(&settingsDefault);
97-
tokenList.createTokens(istr, "test.cpp");
93+
const char code[] = "void a(){} void main(){ if(true){a();} }";
94+
SimpleTokenList tokenList(code);
9895
const Token* start = tokenList.front()->tokAt(4);
9996
const Token* end = tokenList.front()->tokAt(10);
10097
ASSERT_EQUALS("", testTokenRange(ConstTokenRange{ start, end }, start, end));
@@ -116,9 +113,8 @@ class TestTokenRange : public TestFixture {
116113
}
117114

118115
void exampleAlgorithms() const {
119-
std::istringstream istr("void a(){} void main(){ if(true){a();} }");
120-
TokenList tokenList(&settingsDefault);
121-
tokenList.createTokens(istr, "test.cpp");
116+
const char code[] = "void a(){} void main(){ if(true){a();} }";
117+
SimpleTokenList tokenList(code);
122118
ConstTokenRange range{ tokenList.front(), nullptr };
123119
ASSERT_EQUALS(true, std::all_of(range.begin(), range.end(), [](const Token*) {
124120
return true;

0 commit comments

Comments
 (0)