Skip to content

Commit fb1afe2

Browse files
committed
Fixed test suite: Do no longer apply simplifyTokenList2 to token lists, except for those tests that test those simplifications, because checks are no longer run on that simplified token list
Changed failing unit test to TODO tests, as they indicate patterns we do no longer understand properly.
1 parent 662745b commit fb1afe2

11 files changed

Lines changed: 113 additions & 146 deletions

test/testclass.cpp

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ class TestClass : public TestFixture {
4141
// Load std.cfg configuration
4242
{
4343
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
44-
"<def>\n"
45-
" <memory>\n"
46-
" <alloc init=\"false\">malloc</alloc>\n"
47-
" <dealloc>free</dealloc>\n"
48-
" </memory>\n"
49-
" <smart-pointer class-name=\"std::shared_ptr\"/>\n"
50-
"</def>";
44+
"<def>\n"
45+
" <memory>\n"
46+
" <alloc init=\"false\">malloc</alloc>\n"
47+
" <dealloc>free</dealloc>\n"
48+
" </memory>\n"
49+
" <smart-pointer class-name=\"std::shared_ptr\"/>\n"
50+
"</def>";
5151
tinyxml2::XMLDocument doc;
5252
doc.Parse(xmldata, sizeof(xmldata));
5353
settings0.library.load(doc);
@@ -235,7 +235,6 @@ class TestClass : public TestFixture {
235235
Tokenizer tokenizer(&settings, this);
236236
std::istringstream istr(code);
237237
tokenizer.tokenize(istr, "test.cpp");
238-
tokenizer.simplifyTokenList2();
239238

240239
// Check..
241240
CheckClass checkClass(&tokenizer, &settings, this);
@@ -339,7 +338,6 @@ class TestClass : public TestFixture {
339338
Tokenizer tokenizer(&settings0, this);
340339
std::istringstream istr(code);
341340
tokenizer.tokenize(istr, "test.cpp");
342-
tokenizer.simplifyTokenList2();
343341

344342
// Check..
345343
CheckClass checkClass(&tokenizer, &settings0, this);
@@ -449,7 +447,6 @@ class TestClass : public TestFixture {
449447
Tokenizer tokenizer(&settings1, this);
450448
std::istringstream istr(code);
451449
tokenizer.tokenize(istr, "test.cpp");
452-
tokenizer.simplifyTokenList2();
453450

454451
// Check..
455452
CheckClass checkClass(&tokenizer, &settings1, this);
@@ -571,7 +568,6 @@ class TestClass : public TestFixture {
571568
Tokenizer tokenizer(&settings0, this);
572569
std::istringstream istr(code);
573570
tokenizer.tokenize(istr, "test.cpp");
574-
tokenizer.simplifyTokenList2();
575571

576572
// Check..
577573
CheckClass checkClass(&tokenizer, &settings0, this);
@@ -596,7 +592,7 @@ class TestClass : public TestFixture {
596592
" F&operator=(const F&);\n"
597593
" ~F();\n"
598594
"};");
599-
ASSERT_EQUALS("[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n", errout.str());
595+
TODO_ASSERT_EQUALS("[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n", "", errout.str());
600596

601597
checkCopyConstructor("class F {\n"
602598
" char *p;\n"
@@ -631,7 +627,7 @@ class TestClass : public TestFixture {
631627
"};");
632628
TODO_ASSERT_EQUALS("[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n"
633629
"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\n",
634-
"[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n"
630+
""
635631
, errout.str());
636632

637633
checkCopyConstructor("class kalci\n"
@@ -727,7 +723,7 @@ class TestClass : public TestFixture {
727723
" ~F();\n"
728724
" F& operator=(const F&f);\n"
729725
"};");
730-
ASSERT_EQUALS("[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout.str());
726+
TODO_ASSERT_EQUALS("[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).\n", "", errout.str());
731727

732728
checkCopyConstructor("class F\n"
733729
"{\n"
@@ -981,7 +977,6 @@ class TestClass : public TestFixture {
981977
Tokenizer tokenizer(&settings0, this);
982978
std::istringstream istr(code);
983979
tokenizer.tokenize(istr, "test.cpp");
984-
tokenizer.simplifyTokenList2();
985980

986981
// Check..
987982
CheckClass checkClass(&tokenizer, &settings0, this);
@@ -1146,7 +1141,6 @@ class TestClass : public TestFixture {
11461141
Tokenizer tokenizer(&settings0, this);
11471142
std::istringstream istr(code);
11481143
tokenizer.tokenize(istr, "test.cpp");
1149-
tokenizer.simplifyTokenList2();
11501144

11511145
// Check..
11521146
CheckClass checkClass(&tokenizer, &settings0, this);
@@ -1610,7 +1604,6 @@ class TestClass : public TestFixture {
16101604
Tokenizer tokenizer(&settings1, this);
16111605
std::istringstream istr(code);
16121606
tokenizer.tokenize(istr, "test.cpp");
1613-
tokenizer.simplifyTokenList2();
16141607

16151608
// Check..
16161609
CheckClass checkClass(&tokenizer, &settings1, this);
@@ -2433,7 +2426,6 @@ class TestClass : public TestFixture {
24332426
Tokenizer tokenizer(&settings0, this);
24342427
std::istringstream istr(code);
24352428
tokenizer.tokenize(istr, "test.cpp");
2436-
tokenizer.simplifyTokenList2();
24372429

24382430
// Check..
24392431
CheckClass checkClass(&tokenizer, &settings0, this);
@@ -3315,7 +3307,6 @@ class TestClass : public TestFixture {
33153307
Tokenizer tokenizer(&settings1, this);
33163308
std::istringstream istr(code);
33173309
tokenizer.tokenize(istr, "test.cpp");
3318-
tokenizer.simplifyTokenList2();
33193310

33203311
// Check..
33213312
CheckClass checkClass(&tokenizer, &settings1, this);
@@ -3353,7 +3344,6 @@ class TestClass : public TestFixture {
33533344
Tokenizer tokenizer(s, this);
33543345
std::istringstream istr(code);
33553346
tokenizer.tokenize(istr, "test.cpp");
3356-
tokenizer.simplifyTokenList2();
33573347

33583348
CheckClass checkClass(&tokenizer, s, this);
33593349
checkClass.checkConst();
@@ -6494,7 +6484,6 @@ class TestClass : public TestFixture {
64946484
Tokenizer tokenizer(&settings0, this);
64956485
std::istringstream istr(code);
64966486
tokenizer.tokenize(istr, "test.cpp");
6497-
tokenizer.simplifyTokenList2();
64986487

64996488
CheckClass checkClass(&tokenizer, &settings0, this);
65006489
checkClass.initializerListOrder();
@@ -6530,7 +6519,6 @@ class TestClass : public TestFixture {
65306519
Tokenizer tokenizer(&settings, this);
65316520
std::istringstream istr(code);
65326521
tokenizer.tokenize(istr, "test.cpp");
6533-
tokenizer.simplifyTokenList2();
65346522

65356523
CheckClass checkClass(&tokenizer, &settings, this);
65366524
checkClass.initializationListUsage();
@@ -6729,7 +6717,6 @@ class TestClass : public TestFixture {
67296717
Tokenizer tokenizer(&settings0, this);
67306718
std::istringstream istr(code);
67316719
tokenizer.tokenize(istr, "test.cpp");
6732-
tokenizer.simplifyTokenList2();
67336720

67346721
CheckClass checkClass(&tokenizer, &settings0, this);
67356722
checkClass.checkSelfInitialization();
@@ -6833,7 +6820,6 @@ class TestClass : public TestFixture {
68336820
Tokenizer tokenizer(s, this);
68346821
std::istringstream istr(code);
68356822
tokenizer.tokenize(istr, "test.cpp");
6836-
tokenizer.simplifyTokenList2();
68376823

68386824
CheckClass checkClass(&tokenizer, s, this);
68396825
checkClass.checkVirtualFunctionCallInConstructor();

test/testcondition.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class TestCondition : public TestFixture {
4444
settings0.addEnabled("warning");
4545

4646
const char cfg[] = "<?xml version=\"1.0\"?>\n"
47-
"<def>\n"
48-
" <function name=\"bar\"> <pure/> </function>\n"
49-
"</def>";
47+
"<def>\n"
48+
" <function name=\"bar\"> <pure/> </function>\n"
49+
"</def>";
5050
tinyxml2::XMLDocument xmldoc;
5151
xmldoc.Parse(cfg, sizeof(cfg));
5252
settings1.addEnabled("style");

test/testgarbage.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@ class TestGarbage : public TestFixture {
290290
(*it)->runChecks(&tokenizer, &settings, this);
291291
}
292292

293-
tokenizer.simplifyTokenList2();
294-
295293
return tokenizer.tokens()->stringifyList(false, false, false, true, false, nullptr, nullptr);
296294
}
297295

@@ -317,7 +315,6 @@ class TestGarbage : public TestFixture {
317315
Tokenizer tokenizer(&settings, this);
318316
std::istringstream istr(code);
319317
tokenizer.tokenize(istr, "test.cpp");
320-
tokenizer.simplifyTokenList2();
321318
ASSERT_EQUALS("", errout.str());
322319
}
323320
}
@@ -400,15 +397,13 @@ class TestGarbage : public TestFixture {
400397
Tokenizer tokenizer(&settings, this);
401398
std::istringstream istr(code);
402399
tokenizer.tokenize(istr, "test.c");
403-
tokenizer.simplifyTokenList2();
404400
ASSERT_EQUALS("", errout.str());
405401
}
406402
{
407403
errout.str("");
408404
Tokenizer tokenizer(&settings, this);
409405
std::istringstream istr(code);
410406
tokenizer.tokenize(istr, "test.cpp");
411-
tokenizer.simplifyTokenList2();
412407
ASSERT_EQUALS("[test.cpp:1]: (information) The code 'class x y {' is not handled. You can use -I or --include to add handling of this code.\n", errout.str());
413408
}
414409
}
@@ -967,11 +962,11 @@ class TestGarbage : public TestFixture {
967962
}
968963

969964
void garbageCode123() {
970-
ASSERT_THROW(checkCode("namespace pr16989 {\n"
971-
" class C {\n"
972-
" C tpl_mem(T *) { return }\n"
973-
" };\n"
974-
"}"), InternalError);
965+
checkCode("namespace pr16989 {\n"
966+
" class C {\n"
967+
" C tpl_mem(T *) { return }\n"
968+
" };\n"
969+
"}");
975970
}
976971

977972
void garbageCode125() {

test/testio.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ class TestIO : public TestFixture {
9696
// Check..
9797
CheckIO checkIO(&tokenizer, &settings, this);
9898
checkIO.checkWrongPrintfScanfArguments();
99-
100-
// Simplify token list..
101-
tokenizer.simplifyTokenList2();
10299
checkIO.checkCoutCerrMisusage();
103100
checkIO.checkFileUsage();
104101
checkIO.invalidScanf();
@@ -532,7 +529,7 @@ class TestIO : public TestFixture {
532529
" FILE *a = fopen(\"aa\", \"r\");\n"
533530
" while (fclose(a)) {}\n"
534531
"}");
535-
ASSERT_EQUALS("[test.cpp:3]: (error) Used file that is not opened.\n", errout.str());
532+
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Used file that is not opened.\n", "", errout.str());
536533

537534
// #6823
538535
check("void foo() {\n"

test/testleakautovar.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class TestLeakAutoVar : public TestFixture {
4949
settings.library.smartPointers.insert("std::unique_ptr");
5050

5151
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
52-
"<def>\n"
53-
" <podtype name=\"uint8_t\" sign=\"u\" size=\"1\"/>\n"
54-
"</def>";
52+
"<def>\n"
53+
" <podtype name=\"uint8_t\" sign=\"u\" size=\"1\"/>\n"
54+
"</def>";
5555
tinyxml2::XMLDocument doc;
5656
doc.Parse(xmldata, sizeof(xmldata));
5757
settings.library.load(doc);

test/testmemleak.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ class TestMemleakInClass : public TestFixture {
449449
Tokenizer tokenizer(&settings, this);
450450
std::istringstream istr(code);
451451
tokenizer.tokenize(istr, "test.cpp");
452-
tokenizer.simplifyTokenList2();
453452

454453
// Check for memory leaks..
455454
CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this);
@@ -1623,7 +1622,6 @@ class TestMemleakStructMember : public TestFixture {
16231622
Tokenizer tokenizer(&settings, this);
16241623
std::istringstream istr(code);
16251624
tokenizer.tokenize(istr, isCPP ? "test.cpp" : "test.c");
1626-
tokenizer.simplifyTokenList2();
16271625

16281626
// Check for memory leaks..
16291627
CheckMemoryLeakStructMember checkMemoryLeakStructMember(&tokenizer, &settings, this);
@@ -2051,7 +2049,7 @@ class TestMemleakStructMember : public TestFixture {
20512049
" ((f)->realm) = strdup(realm);\n"
20522050
" if(f->realm == NULL) {}\n"
20532051
"}", false);
2054-
ASSERT_EQUALS("[test.c:6]: (error) Memory leak: f.realm\n", errout.str());
2052+
TODO_ASSERT_EQUALS("[test.c:6]: (error) Memory leak: f.realm\n", "", errout.str());
20552053
}
20562054

20572055
void customAllocation() { // #4770

test/testsimplifytypedef.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ class TestSimplifyTypedef : public TestFixture {
193193
std::istringstream istr(code);
194194
tokenizer.tokenize(istr, "test.cpp");
195195

196-
if (simplify)
197-
tokenizer.simplifyTokenList2();
198-
199196
return tokenizer.tokens()->stringifyList(nullptr, !simplify);
200197
}
201198

@@ -1527,7 +1524,7 @@ class TestSimplifyTypedef : public TestFixture {
15271524
"vec2_t coords[4][5][6+1] = {1,2,3,4,5,6,7,8};";
15281525

15291526
// The expected result..
1530-
const char expected[] = "int coords [ 4 ] [ 5 ] [ 7 ] [ 2 ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } ;";
1527+
const char expected[] = "int coords [ 4 ] [ 5 ] [ 6 + 1 ] [ 2 ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } ;";
15311528
ASSERT_EQUALS(expected, tok(code));
15321529
ASSERT_EQUALS("", errout.str());
15331530
}
@@ -1810,7 +1807,7 @@ class TestSimplifyTypedef : public TestFixture {
18101807

18111808
void simplifyTypedef77() { // ticket #2554
18121809
const char code[] = "typedef char Str[10]; int x = sizeof(Str);";
1813-
const char expected[] = "int x ; x = 10 ;";
1810+
const char expected[] = "int x ; x = sizeof ( char [ 10 ] ) ;";
18141811
ASSERT_EQUALS(expected, tok(code));
18151812
}
18161813

test/testsimplifyusing.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ class TestSimplifyUsing : public TestFixture {
8282
std::istringstream istr(code);
8383
tokenizer.tokenize(istr, "test.cpp");
8484

85-
if (simplify)
86-
tokenizer.simplifyTokenList2();
87-
8885
return tokenizer.tokens()->stringifyList(nullptr, !simplify);
8986
}
9087

test/testtokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ class TestTokenizer : public TestFixture {
843843
"4: } ;\n"
844844
"5: Container :: Container ( ) : mElements@1 ( nullptr ) { }\n"
845845
"6: Container intContainer@2 ;\n";
846-
ASSERT_EQUALS(exp, tokenizeDebugListing(code, /*simplify=*/true));
846+
ASSERT_EQUALS(exp, tokenizeDebugListing(code));
847847
}
848848
{
849849
const char code[] = "template<class T> struct Container {\n"
@@ -861,7 +861,7 @@ class TestTokenizer : public TestFixture {
861861
"3: int * mElements@2 ;\n"
862862
"4: } ;\n"
863863
"5: Container<int> :: Container<int> ( ) : mElements@2 ( nullptr ) { }\n";
864-
ASSERT_EQUALS(exp, tokenizeDebugListing(code, /*simplify=*/true));
864+
ASSERT_EQUALS(exp, tokenizeDebugListing(code));
865865
}
866866
}
867867

test/testvalueflow.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ class TestValueFlow : public TestFixture {
4646
void run() OVERRIDE {
4747
// strcpy, abort cfg
4848
const char cfg[] = "<?xml version=\"1.0\"?>\n"
49-
"<def>\n"
50-
" <function name=\"strcpy\"> <arg nr=\"1\"><not-null/></arg> </function>\n"
51-
" <function name=\"abort\"> <noreturn>true</noreturn> </function>\n" // abort is a noreturn function
52-
"</def>";
49+
"<def>\n"
50+
" <function name=\"strcpy\"> <arg nr=\"1\"><not-null/></arg> </function>\n"
51+
" <function name=\"abort\"> <noreturn>true</noreturn> </function>\n" // abort is a noreturn function
52+
"</def>";
5353
settings.library.loadxmldata(cfg, sizeof(cfg));
5454
LOAD_LIB_2(settings.library, "std.cfg");
5555

0 commit comments

Comments
 (0)