Skip to content

Commit 56f4740

Browse files
committed
Fix tests (other)
1 parent 7b0fe02 commit 56f4740

11 files changed

Lines changed: 264 additions & 135 deletions

test/testclass.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4033,7 +4033,7 @@ class TestClass : public TestFixture {
40334033
"void Fred::foo(std::string & a) { a = s; }\n"
40344034
"void Fred::foo(const std::string & a) { s = a; }\n");
40354035
ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:7:12]: (style) The member function 'Fred::foo' can be static. [functionStatic]\n"
4036-
"[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str());
4036+
"[test.cpp:4:10] -> [test.cpp:8:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str());
40374037

40384038
// check functions with different or missing parameter names
40394039
checkConst("class Fred {\n"
@@ -9348,19 +9348,19 @@ class TestClass : public TestFixture {
93489348
}
93499349

93509350
void ctuOneDefinitionRule() {
9351-
ctu({"class C { C() { std::cout << 0; } };", "class C { C() { std::cout << 1; } };"});
9351+
ctu({"class C { C() { std::cout << 0; } };\n", "class C { C() { std::cout << 1; } };\n"});
93529352
ASSERT_EQUALS("[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\n", errout_str());
93539353

9354-
ctu({"class C { C(); }; C::C() { std::cout << 0; }", "class C { C(); }; C::C() { std::cout << 1; }"});
9354+
ctu({"class C { C(); }; C::C() { std::cout << 0; }\n", "class C { C(); }; C::C() { std::cout << 1; }\n"});
93559355
ASSERT_EQUALS("[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\n", errout_str());
93569356

93579357
ctu({"class C { C() {} };\n", "class C { C() {} };\n"});
93589358
ASSERT_EQUALS("", errout_str());
93599359

9360-
ctu({"class C { C(); }; C::C(){}", "class C { C(); }; C::C(){}"});
9360+
ctu({"class C { C(); }; C::C(){}\n", "class C { C(); }; C::C(){}\n"});
93619361
ASSERT_EQUALS("", errout_str());
93629362

9363-
ctu({"class A::C { C() { std::cout << 0; } };", "class B::C { C() { std::cout << 1; } };"});
9363+
ctu({"class A::C { C() { std::cout << 0; } };\n", "class B::C { C() { std::cout << 1; } };\n"});
93649364
ASSERT_EQUALS("", errout_str());
93659365

93669366
// 11435 - template specialisations

test/testcondition.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5215,9 +5215,9 @@ class TestCondition : public TestFixture {
52155215
" if (i == a.x) {}\n"
52165216
" if (j == a.x) {}\n"
52175217
"}\n");
5218-
ASSERT_EQUALS("[test.cpp:6:11]: (style) Condition 'i==j' is always true [knownConditionTrueFalse]\n"
5219-
"[test.cpp:7:11]: (style) Condition 'i==a.x' is always true [knownConditionTrueFalse]\n"
5220-
"[test.cpp:8:11]: (style) Condition 'j==a.x' is always true [knownConditionTrueFalse]\n",
5218+
ASSERT_EQUALS("[test.cpp:7:11]: (style) Condition 'i==j' is always true [knownConditionTrueFalse]\n"
5219+
"[test.cpp:8:11]: (style) Condition 'i==a.x' is always true [knownConditionTrueFalse]\n"
5220+
"[test.cpp:9:11]: (style) Condition 'j==a.x' is always true [knownConditionTrueFalse]\n",
52215221
errout_str());
52225222

52235223
check("struct S { int i; };\n" // #12795

test/testleakautovar.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,13 @@ class TestLeakAutoVar : public TestFixture {
362362
" char *p;\n"
363363
" if (x && (p = malloc(10))) { }\n"
364364
"}\n");
365-
ASSERT_EQUALS("[test.c:3:35]: (error) Memory leak: p [memleak]\n", errout_str());
365+
ASSERT_EQUALS("[test.c:4:1]: (error) Memory leak: p [memleak]\n", errout_str());
366366

367367
check("void f(int x) {\n"
368368
" char *p;\n"
369369
" if (x && (p = new char[10])) { }\n"
370370
"}\n", dinit(CheckOptions, $.cpp = true));
371-
ASSERT_EQUALS("[test.cpp:3:37]: (error) Memory leak: p [memleak]\n", errout_str());
371+
ASSERT_EQUALS("[test.cpp:4:1]: (error) Memory leak: p [memleak]\n", errout_str());
372372
}
373373

374374
void assign15() {
@@ -409,13 +409,13 @@ class TestLeakAutoVar : public TestFixture {
409409
" char *p;\n"
410410
" if (x && (p = (char*)malloc(10))) { }\n"
411411
"}\n");
412-
ASSERT_EQUALS("[test.c:3:42]: (error) Memory leak: p [memleak]\n", errout_str());
412+
ASSERT_EQUALS("[test.c:4:1]: (error) Memory leak: p [memleak]\n", errout_str());
413413

414414
check("void f(int x) {\n"
415415
" char *p;\n"
416416
" if (x && (p = (char*)(int*)malloc(10))) { }\n"
417417
"}\n");
418-
ASSERT_EQUALS("[test.c:3:48]: (error) Memory leak: p [memleak]\n", errout_str());
418+
ASSERT_EQUALS("[test.c:4:1]: (error) Memory leak: p [memleak]\n", errout_str());
419419
}
420420

421421
void assign19() {

test/testother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13173,7 +13173,7 @@ class TestOther : public TestFixture {
1317313173
ASSERT_NO_THROW(check("\n void foo(int declaration = {}) {\n"
1317413174
"\n for (int i = 0; i < 10; i++) {}\n"
1317513175
"\n }\n"
13176-
"\n "));
13176+
"\n"));
1317713177
ASSERT_EQUALS("", errout_str());
1317813178
}
1317913179

test/testpreprocessor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ class TestPreprocessor : public TestFixture {
12811281
void macro_NULL() {
12821282
// See ticket #4482 - UB when passing NULL to variadic function
12831283
ASSERT_EQUALS("\n0", expandMacros("#define null 0\nnull\n", *this));
1284-
TODO_ASSERT_EQUALS("\nNULL", "\n0", expandMacros("#define NULL 0\nNULL", *this)); // TODO: Let the tokenizer handle NULL?
1284+
TODO_ASSERT_EQUALS("\nNULL\n", "\n0", expandMacros("#define NULL 0\nNULL\n", *this)); // TODO: Let the tokenizer handle NULL?
12851285
}
12861286

12871287
void string1() {
@@ -3172,7 +3172,7 @@ class TestPreprocessor : public TestFixture {
31723172
std::vector<std::string> files;
31733173
TokenList tokenlist{settingsDefault, Standards::Language::CPP};
31743174
// TODO: can this happen from application code? if yes we need to turn it into a proper error
3175-
ASSERT_THROW_EQUALS(preprocess(code, files, "test.cpp", tokenlist, dui), std::runtime_error, "unexpected simplecpp::Output type 9");
3175+
ASSERT_THROW_EQUALS(preprocess(code, files, "test.cpp", tokenlist, dui), std::runtime_error, "unexpected simplecpp::Output type 12");
31763176
ASSERT(!tokenlist.front()); // nothing is tokenized when an unknown standard is provided
31773177
}
31783178
}
@@ -3183,7 +3183,7 @@ class TestPreprocessor : public TestFixture {
31833183
"public:\n"
31843184
" void f() {}\n"
31853185
"};\n";
3186-
const char code[] = R"(#include "test.h")";
3186+
const char code[] = "#include \"test.h\"\n";
31873187
ScopedFile header("test.h", inc);
31883188
const std::string processed = getcodeforcfg(settingsDefault, *this, code, "", "test.cpp");
31893189
ASSERT_EQUALS(

test/testsimplifytokens.cpp

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ class TestSimplifyTokens : public TestFixture {
463463

464464
void declareVar() {
465465
const char code[] = "void f ( ) { char str [ 100 ] = \"100\" ; }\n";
466-
ASSERT_EQUALS(code, tok(code));
466+
const char expected[] = "void f ( ) { char str [ 100 ] = \"100\" ; }";
467+
ASSERT_EQUALS(expected, tok(code));
467468
}
468469

469470
void declareArray() {
@@ -790,7 +791,8 @@ class TestSimplifyTokens : public TestFixture {
790791
{
791792
// #4786 - don't replace , with ; in ".. : public B, C .." code
792793
const char code[] = "template < class T = X > class A : public B , C { } ;\n";
793-
ASSERT_EQUALS(code, tok(code));
794+
const char expected[] = "template < class T = X > class A : public B , C { } ;";
795+
ASSERT_EQUALS(expected, tok(code));
794796
}
795797
}
796798

@@ -1609,7 +1611,8 @@ class TestSimplifyTokens : public TestFixture {
16091611
void simplifyKnownVariables14() {
16101612
// ticket #753
16111613
const char code[] = "void f ( ) { int n ; n = 1 ; do { ++ n ; } while ( n < 10 ) ; }\n";
1612-
ASSERT_EQUALS(code, simplifyKnownVariables(code));
1614+
const char expected[] = "void f ( ) { int n ; n = 1 ; do { ++ n ; } while ( n < 10 ) ; }";
1615+
ASSERT_EQUALS(expected, simplifyKnownVariables(code));
16131616
}
16141617

16151618
void simplifyKnownVariables16() {
@@ -2063,7 +2066,10 @@ class TestSimplifyTokens : public TestFixture {
20632066
" char buf[10] = \"ab\";\n"
20642067
" memset(buf, 0, 10);\n"
20652068
"}\n";
2066-
const char expected2[] = "void f ( ) { char buf [ 10 ] = \"ab\" ; memset ( buf , 0 , 10 ) ; }";
2069+
const char expected2[] = "void f ( ) {\n"
2070+
"char buf [ 10 ] = \"ab\" ;\n"
2071+
"memset ( buf , 0 , 10 ) ;\n"
2072+
"}";
20672073
ASSERT_EQUALS(expected2, tokenizeAndStringify(code2));
20682074
}
20692075

@@ -2089,9 +2095,9 @@ class TestSimplifyTokens : public TestFixture {
20892095
" free(s);\n"
20902096
"}\n";
20912097
const char expected[] = "void f ( ) {\n"
2092-
" char * s ; s = malloc ( 10 ) ;"
2093-
" strcpy ( s , \"\" ) ;"
2094-
" free ( s ) ; "
2098+
"char * s ; s = malloc ( 10 ) ;\n"
2099+
"strcpy ( s , \"\" ) ;\n"
2100+
"free ( s ) ;\n"
20952101
"}";
20962102
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
20972103
}
@@ -2102,8 +2108,8 @@ class TestSimplifyTokens : public TestFixture {
21022108
" q = p;\n"
21032109
"}\n";
21042110
const char expected[] = "void f ( char * p , char * q ) {\n"
2105-
" strcpy ( p , \"abc\" ) ;"
2106-
" q = p ; "
2111+
"strcpy ( p , \"abc\" ) ;\n"
2112+
"q = p ;\n"
21072113
"}";
21082114
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
21092115
}
@@ -2249,7 +2255,24 @@ class TestSimplifyTokens : public TestFixture {
22492255
"const char x7 = 'b' ;\n"
22502256
"return & x7 ;\n"
22512257
"}\n";
2252-
ASSERT_EQUALS(code, tokenizeAndStringify(code));
2258+
2259+
const char expected[] = "const char * foo ( ) {\n"
2260+
"const char x1 = 'b' ;\n"
2261+
"f ( & x1 ) ;\n"
2262+
"const char x2 = 'b' ;\n"
2263+
"f ( y , & x2 ) ;\n"
2264+
"const char x3 = 'b' ;\n"
2265+
"t = & x3 ;\n"
2266+
"const char x4 = 'b' ;\n"
2267+
"t = y + & x4 ;\n"
2268+
"const char x5 = 'b' ;\n"
2269+
"z [ & x5 ] = y ;\n"
2270+
"const char x6 = 'b' ;\n"
2271+
"v = { & x6 } ;\n"
2272+
"const char x7 = 'b' ;\n"
2273+
"return & x7 ;\n"
2274+
"}";
2275+
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
22532276
ASSERT_EQUALS(
22542277
"[test.cpp:5:5]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y [valueFlowBailoutIncompleteVar]\n",
22552278
errout_str());
@@ -2272,7 +2295,24 @@ class TestSimplifyTokens : public TestFixture {
22722295
"const int x7 = 1 ;\n"
22732296
"return & x7 ;\n"
22742297
"}\n";
2275-
ASSERT_EQUALS(code, tokenizeAndStringify(code));
2298+
2299+
const char expected[] = "const int * foo ( ) {\n"
2300+
"const int x1 = 1 ;\n"
2301+
"f ( & x1 ) ;\n"
2302+
"const int x2 = 1 ;\n"
2303+
"f ( y , & x2 ) ;\n"
2304+
"const int x3 = 1 ;\n"
2305+
"t = & x3 ;\n"
2306+
"const int x4 = 1 ;\n"
2307+
"t = y + & x4 ;\n"
2308+
"const int x5 = 1 ;\n"
2309+
"z [ & x5 ] = y ;\n"
2310+
"const int x6 = 1 ;\n"
2311+
"v = { & x6 } ;\n"
2312+
"const int x7 = 1 ;\n"
2313+
"return & x7 ;\n"
2314+
"}";
2315+
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
22762316
ASSERT_EQUALS(
22772317
"[test.cpp:5:5]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y [valueFlowBailoutIncompleteVar]\n",
22782318
errout_str());
@@ -2507,7 +2547,11 @@ class TestSimplifyTokens : public TestFixture {
25072547
" int x = 123;\n"
25082548
" a(x);\n" // <- don't replace with a(123);
25092549
"}\n";
2510-
const char expected[] = "void a ( int & x ) ; void b ( ) { int x ; x = 123 ; a ( x ) ; }";
2550+
const char expected[] = "void a ( int & x ) ;\n"
2551+
"void b ( ) {\n"
2552+
"int x ; x = 123 ;\n"
2553+
"a ( x ) ;\n"
2554+
"}";
25112555
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
25122556
}
25132557
}
@@ -2519,7 +2563,12 @@ class TestSimplifyTokens : public TestFixture {
25192563
" x = 123;\n"
25202564
" while (!x) { dostuff(); }\n"
25212565
"}\n";
2522-
ASSERT_EQUALS("static int x ; void f ( ) { x = 123 ; while ( ! x ) { dostuff ( ) ; } }", tokenizeAndStringify(code));
2566+
const char expected[] = "static int x ;\n"
2567+
"void f ( ) {\n"
2568+
"x = 123 ;\n"
2569+
"while ( ! x ) { dostuff ( ) ; }\n"
2570+
"}";
2571+
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
25232572
ASSERT_EQUALS("", filter_valueflow(errout_str()));
25242573
}
25252574

test/testsingleexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class TestSingleExecutorBase : public TestFixture {
143143
"{\n"
144144
" (void)(*((int*)0));\n"
145145
"}\n", dinit(CheckOptions,
146-
$.quiet = false));
146+
$.quiet = false));
147147
{
148148
std::string expected;
149149
for (int i = 1; i <= num_files; ++i) {

test/testsuppressions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ class TestSuppressions : public TestFixture {
14021402
CppCheck cppCheck(settings, supprs, *this, nullptr, false, nullptr); // <- do not "use global suppressions". pretend this is a thread that just checks a file.
14031403

14041404
const char code[] = "int f() { int a; return a; }\n";
1405-
ASSERT_EQUALS(0, cppCheck.checkBuffer(FileWithDetails("test.c", Standards::Language::C, 0),code, sizeof(code))); // <- no unsuppressed error is seen
1405+
ASSERT_EQUALS(0, cppCheck.checkBuffer(FileWithDetails("test.c", Standards::Language::C, 0),code, sizeof(code)-1)); // <- no unsuppressed error is seen
14061406
ASSERT_EQUALS("[test.c:1:25]: (error) Uninitialized variable: a [uninitvar]\n", errout_str()); // <- report error so ThreadExecutor can suppress it and make sure the global suppression is matched.
14071407
}
14081408

@@ -1442,7 +1442,7 @@ class TestSuppressions : public TestFixture {
14421442
" int y;\n"
14431443
"};\n";
14441444
CppCheck cppCheck(settings, supprs, *this, nullptr, true, nullptr);
1445-
ASSERT_EQUALS(0, cppCheck.checkBuffer(FileWithDetails("/somewhere/test.cpp", Standards::Language::CPP, 0), code, sizeof(code)));
1445+
ASSERT_EQUALS(0, cppCheck.checkBuffer(FileWithDetails("/somewhere/test.cpp", Standards::Language::CPP, 0), code, sizeof(code)-1));
14461446
ASSERT_EQUALS("",errout_str());
14471447
}
14481448

0 commit comments

Comments
 (0)