Skip to content

Commit 4267325

Browse files
committed
Refactorized testrunner: Create std::string only where necessary
1 parent e978a68 commit 4267325

File tree

7 files changed

+596
-601
lines changed

7 files changed

+596
-601
lines changed

test/testassert.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ class TestAssert : public TestFixture {
2626
TestAssert() : TestFixture("TestAssert") {}
2727

2828
private:
29-
void check(
30-
const char code[],
31-
const char *filename = NULL) {
29+
void check(const char code[], const char *filename = "test.cpp") {
3230
// Clear the error buffer..
3331
errout.str("");
3432

@@ -38,7 +36,7 @@ class TestAssert : public TestFixture {
3836
// Tokenize..
3937
Tokenizer tokenizer(&settings, this);
4038
std::istringstream istr(code);
41-
tokenizer.tokenize(istr, filename ? filename : "test.cpp");
39+
tokenizer.tokenize(istr, filename);
4240

4341
// Check..
4442
CheckAssert checkAssert(&tokenizer, &settings, this);

test/testautovariables.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class TestAutoVariables : public TestFixture {
2929
private:
3030

3131

32-
33-
void check(const char code[], bool inconclusive=false, bool runSimpleChecks=true, const char* filename=nullptr) {
32+
void check(const char code[], bool inconclusive = false, bool runSimpleChecks = true, const char* filename = "test.cpp") {
3433
// Clear the error buffer..
3534
errout.str("");
3635

@@ -42,7 +41,7 @@ class TestAutoVariables : public TestFixture {
4241
// Tokenize..
4342
Tokenizer tokenizer(&settings, this);
4443
std::istringstream istr(code);
45-
tokenizer.tokenize(istr, (filename)?filename:"test.cpp");
44+
tokenizer.tokenize(istr, filename);
4645

4746
CheckAutoVariables checkAutoVariables(&tokenizer, &settings, this);
4847
checkAutoVariables.returnReference();

test/testsimplifytemplate.cpp

Lines changed: 145 additions & 146 deletions
Large diffs are not rendered by default.

test/testsimplifytokens.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ class TestSimplifyTokens : public TestFixture {
14481448
"for (int i = 0; i < static_cast<int>(3); ++i) {}\n"
14491449
"}\n";
14501450

1451-
const std::string expected("void f ( ) { for ( int i = 0 ; i < 3 ; ++ i ) { } }");
1451+
const char expected[] = "void f ( ) { for ( int i = 0 ; i < 3 ; ++ i ) { } }";
14521452

14531453
ASSERT_EQUALS(expected, tok(code));
14541454
}
@@ -1459,7 +1459,7 @@ class TestSimplifyTokens : public TestFixture {
14591459
" p = const_cast<char *> qtu ();\n"
14601460
"}\n";
14611461

1462-
const std::string expected("void f ( ) { p = const_cast < char * > qtu ( ) ; }");
1462+
const char expected[] = "void f ( ) { p = const_cast < char * > qtu ( ) ; }";
14631463

14641464
ASSERT_EQUALS(expected, tok(code));
14651465
}
@@ -1470,7 +1470,7 @@ class TestSimplifyTokens : public TestFixture {
14701470
"{\n"
14711471
" return dynamic_cast<Foo *>((bar()));\n"
14721472
"}\n";
1473-
const std::string expected("void f ( ) { return bar ( ) ; }");
1473+
const char expected[] = "void f ( ) { return bar ( ) ; }";
14741474

14751475
ASSERT_EQUALS(expected, tok(code));
14761476
}
@@ -1534,23 +1534,23 @@ class TestSimplifyTokens : public TestFixture {
15341534
{
15351535
const char code[] = "using namespace std; namespace a{ namespace b{ void f(){} } }";
15361536

1537-
const std::string expected("namespace a { namespace b { void f ( ) { } } }");
1537+
const char expected[] = "namespace a { namespace b { void f ( ) { } } }";
15381538

15391539
ASSERT_EQUALS(expected, tok(code));
15401540
}
15411541

15421542
{
15431543
const char code[] = "namespace b{ void f(){} }";
15441544

1545-
const std::string expected("namespace b { void f ( ) { } }");
1545+
const char expected[] = "namespace b { void f ( ) { } }";
15461546

15471547
ASSERT_EQUALS(expected, tok(code));
15481548
}
15491549

15501550
{
15511551
const char code[] = "void f(int namespace) { }";
15521552

1553-
const std::string expected("void f ( int namespace ) { }");
1553+
const char expected[] = "void f ( int namespace ) { }";
15541554

15551555
ASSERT_EQUALS(expected, tok(code));
15561556
}

test/testsimplifytypedef.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ class TestSimplifyTypedef : public TestFixture {
16551655
"}";
16561656

16571657
// The expected tokens..
1658-
const std::string expected1("void f ( ) { char a [ 256 ] ; char b [ 256 ] ; }");
1658+
const char expected1[] = "void f ( ) { char a [ 256 ] ; char b [ 256 ] ; }";
16591659
ASSERT_EQUALS(expected1, tok(code1, false));
16601660
ASSERT_EQUALS("", errout.str());
16611661

@@ -1666,7 +1666,7 @@ class TestSimplifyTypedef : public TestFixture {
16661666
"}";
16671667

16681668
// The expected tokens..
1669-
const std::string expected2("void f ( ) { char a [ 256 ] ; a = { 0 } ; char b [ 256 ] ; b = { 0 } ; }");
1669+
const char expected2[] = "void f ( ) { char a [ 256 ] ; a = { 0 } ; char b [ 256 ] ; b = { 0 } ; }";
16701670
ASSERT_EQUALS(expected2, tok(code2, false));
16711671
ASSERT_EQUALS("", errout.str());
16721672

@@ -1677,7 +1677,7 @@ class TestSimplifyTypedef : public TestFixture {
16771677
"}";
16781678

16791679
// The expected tokens..
1680-
const std::string expected3("void f ( ) { char a [ 256 ] ; a = \"\" ; char b [ 256 ] ; b = \"\" ; }");
1680+
const char expected3[] = "void f ( ) { char a [ 256 ] ; a = \"\" ; char b [ 256 ] ; b = \"\" ; }";
16811681
ASSERT_EQUALS(expected3, tok(code3, false));
16821682
ASSERT_EQUALS("", errout.str());
16831683

@@ -1688,7 +1688,7 @@ class TestSimplifyTypedef : public TestFixture {
16881688
"}";
16891689

16901690
// The expected tokens..
1691-
const std::string expected4("void f ( ) { char a [ 256 ] ; a = \"1234\" ; char b [ 256 ] ; b = \"5678\" ; }");
1691+
const char expected4[] = "void f ( ) { char a [ 256 ] ; a = \"1234\" ; char b [ 256 ] ; b = \"5678\" ; }";
16921692
ASSERT_EQUALS(expected4, tok(code4, false));
16931693
ASSERT_EQUALS("", errout.str());
16941694
}

test/testtokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8657,8 +8657,8 @@ class TestTokenizer : public TestFixture {
86578657
std::list<std::string> configurations;
86588658
std::string filedata = "";
86598659
std::istringstream fin(raw_code);
8660-
preprocessor.preprocess(fin, filedata, configurations, "", settings._includePaths);
8661-
const std::string code = preprocessor.getcode(filedata, "", "");
8660+
preprocessor.preprocess(fin, filedata, configurations, emptyString, settings._includePaths);
8661+
const std::string code = preprocessor.getcode(filedata, emptyString, emptyString);
86628662

86638663
tokenizeAndStringify(code.c_str()); // just survive...
86648664
}

0 commit comments

Comments
 (0)