Unit test cleanup: Removed some empty lines and whitespaces before \n.

This commit is contained in:
PKEuS 2012-12-06 10:19:22 -08:00
parent ae447a192a
commit 4737966caf
10 changed files with 63 additions and 68 deletions

View File

@ -1401,7 +1401,7 @@ private:
void array_index_43() { // #3838
check("int f( ) \n"
check("int f( )\n"
"{\n"
" struct {\n"
" int arr[ 3 ];\n"
@ -1415,7 +1415,7 @@ private:
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:10]: (error) Array 'var[0].arr[3]' index 3 out of bounds.\n","", errout.str());
check("int f( ) \n"
check("int f( )\n"
"{\n"
" struct {\n"
" int arr[ 3 ];\n"
@ -2592,7 +2592,7 @@ private:
check("void main() {\n"
" int array[] = {1,2};\n"
" int x = 0;\n"
" for( int i = 0; i<6; ) { \n"
" for( int i = 0; i<6; ) {\n"
" x += array[i];\n"
" i++; }\n"
"}\n");
@ -2601,7 +2601,7 @@ private:
check("void main() {\n"
" int array[] = {1,2};\n"
" int x = 0;\n"
" for( int i = 0; i<6; ) { \n"
" for( int i = 0; i<6; ) {\n"
" i++; }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
@ -2611,7 +2611,7 @@ private:
check("void main() {\n"
" int array[] = {1,2};\n"
" int x = 0;\n"
" for( int i = 0; i<6; ) { \n"
" for( int i = 0; i<6; ) {\n"
" x += array[i++];\n"
" }\n"
"}\n");

View File

@ -1936,7 +1936,7 @@ private:
checkNoMemset("class Fred\n"
"{\n"
" std::string * b; \n"
" std::string * b;\n"
"};\n"
"void f()\n"
"{\n"
@ -1947,7 +1947,7 @@ private:
checkNoMemset("class Fred\n"
"{\n"
" std::string b; \n"
" std::string b;\n"
"};\n"
"void f()\n"
"{\n"
@ -1958,7 +1958,7 @@ private:
checkNoMemset("class Fred\n"
"{\n"
" mutable std::string b; \n"
" mutable std::string b;\n"
"};\n"
"void f()\n"
"{\n"
@ -2041,7 +2041,7 @@ private:
checkNoMemset("namespace n1 {\n"
" class Fred\n"
" {\n"
" std::string b; \n"
" std::string b;\n"
" };\n"
"}\n"
"void f()\n"
@ -2055,7 +2055,7 @@ private:
checkNoMemset("namespace n1 {\n"
" class Fred\n"
" {\n"
" std::string b; \n"
" std::string b;\n"
" };\n"
"}\n"
"void f()\n"
@ -2069,7 +2069,7 @@ private:
checkNoMemset("namespace n1 {\n"
" class Fred\n"
" {\n"
" std::string b; \n"
" std::string b;\n"
" };\n"
"}\n"
"void f()\n"
@ -2122,7 +2122,7 @@ private:
"{\n"
" void g( struct sockaddr_in6& a);\n"
"private:\n"
" std::string b; \n"
" std::string b;\n"
"};\n"
"void f()\n"
"{\n"
@ -4181,7 +4181,7 @@ private:
"class A\n"
"{\n"
" public:\n"
" \n"
"\n"
" AA::BB::CC::DD a;\n"
" void foo(AA::BB::CC::DD b)\n"
" {\n"

View File

@ -1524,7 +1524,7 @@ private:
"private:\n"
" int a[23];\n"
"public:\n"
" Fred(); \n"
" Fred();\n"
"};\n"
"Fred::Fred() {\n"
" a[x::y] = 0;\n"

View File

@ -2201,13 +2201,13 @@ private:
// #2705
void func24() {
check("void f(void) \n"
check("void f(void)\n"
"{\n"
" std::string *x = new std::string;\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: x\n","", errout.str());
check("void f(void) \n"
check("void f(void)\n"
"{\n"
" std::string *x = new std::string;\n"
" delete x;\n"
@ -2217,7 +2217,7 @@ private:
void func25() { // ticket #2904
check("class Fred { };\n"
"void f(void) \n"
"void f(void)\n"
"{\n"
" Fred *f = new Fred();\n"
" delete f;\n"
@ -2225,14 +2225,14 @@ private:
ASSERT_EQUALS("", errout.str());
check("class Fred { };\n"
"void f(void) \n"
"void f(void)\n"
"{\n"
" Fred *f = new Fred();\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: f\n", errout.str());
check("class Fred { void foo(){ } };\n"
"void f(void) \n"
"void f(void)\n"
"{\n"
" Fred *f = new Fred();\n"
" delete f;\n"
@ -2240,7 +2240,7 @@ private:
ASSERT_EQUALS("", errout.str());
check("class Fred { void foo(){ } };\n"
"void f(void) \n"
"void f(void)\n"
"{\n"
" Fred *f = new Fred();\n"
"}\n");
@ -3479,11 +3479,11 @@ private:
check("int myfunc()\n"
"{\n"
" int handle;\n"
" \n"
"\n"
" handle = open(\"myfile\");\n"
" if (handle < 0) return 1;\n"
" \n"
" while (some_condition()) \n"
"\n"
" while (some_condition())\n"
" if (some_other_condition())\n"
" {\n"
" close(handle);\n"
@ -3497,11 +3497,11 @@ private:
check("int myfunc()\n"
"{\n"
" int handle;\n"
" \n"
"\n"
" handle = open(\"myfile\", O_RDONLY);\n"
" if (handle < 0) return 1;\n"
" \n"
" while (some_condition()) \n"
"\n"
" while (some_condition())\n"
" if (some_other_condition())\n"
" {\n"
" return 3;\n"
@ -4115,7 +4115,7 @@ private:
"{\n"
"public:\n"
" void foo()\n"
" { \n"
" {\n"
" char *str = new char[100];\n"
" delete [] str;\n"
" hello();\n"

View File

@ -699,7 +699,7 @@ private:
ASSERT_EQUALS("", errout.str());
// Ticket #2463
check("struct A \n"
check("struct A\n"
"{\n"
" B* W;\n"
"\n"
@ -1122,7 +1122,7 @@ private:
check("void foo()\n"
"{\n"
" struct my_type* p;\n"
" p = 0; \n"
" p = 0;\n"
" p->x = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
@ -1146,7 +1146,7 @@ private:
check("int foo()\n"
"{\n"
" my_type* p;\n"
" p = 0; \n"
" p = 0;\n"
" return p->x;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
@ -1154,7 +1154,7 @@ private:
check("int foo()\n"
"{\n"
" struct my_type* p;\n"
" p = 0; \n"
" p = 0;\n"
" return p->x;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());

View File

@ -274,12 +274,12 @@ private:
"}", "test.cpp", true, true);
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Opposite conditions in nested 'if' blocks lead to a dead code block.\n", errout.str());
check("void foo(int i) \n"
check("void foo(int i)\n"
"{\n"
" if(i > 5) {\n"
" i = bar();\n"
" if(i < 5) {\n"
" cout << a; \n"
" cout << a;\n"
" }\n"
" }\n"
"}", "test.cpp", true, true);
@ -329,7 +329,7 @@ private:
" int n = 100;\n"
" for(int i = 0; i < n; i ++)\n"
" {\n"
" sum += i; \n"
" sum += i;\n"
" }\n"
" cout<<b/sum;\n"
"}\n");
@ -4875,27 +4875,27 @@ private:
// Errors detected in Quake 3: Arena by PVS-Studio: Fragement 2
check("void f()\n"
"{\n"
" if (front < 0) \n"
" if (front < 0)\n"
" frac = (front)/(front-back);\n"
" else \n"
" else\n"
" frac = (front)/(front-back);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
check("void f()\n"
"{\n"
" if (front < 0) \n"
" if (front < 0)\n"
" { frac = (front)/(front-back);}\n"
" else \n"
" else\n"
" frac = (front)/(front-back);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
check("void f()\n"
"{\n"
" if (front < 0) \n"
" if (front < 0)\n"
" { frac = (front)/(front-back);}\n"
" else \n"
" else\n"
" frac = (front)/((front-back));\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());

View File

@ -1706,7 +1706,6 @@ private:
"{\n"
"public:\n"
" typedef ABC<T> m;\n"
"\n"
"};\n";
const std::string expected("template < class T > class ABC { public: } ;");
@ -5257,10 +5256,10 @@ private:
}
void simplifyTypedef65() { // ticket #2314
const char code[] = "typedef BAR<int> Foo; \n"
"int main() { \n"
" Foo b(0); \n"
" return b > Foo(10); \n"
const char code[] = "typedef BAR<int> Foo;\n"
"int main() {\n"
" Foo b(0);\n"
" return b > Foo(10);\n"
"}";
const std::string actual(tok(code));
ASSERT_EQUALS("int main ( ) { BAR < int > b ( 0 ) ; return b > BAR < int > ( 10 ) ; }", actual);
@ -5296,7 +5295,7 @@ private:
void simplifyTypedef69() { // ticket #2348
const char code[] = "typedef int (*CompilerHook)();\n"
"typedef struct VirtualMachine \n"
"typedef struct VirtualMachine\n"
"{\n"
" CompilerHook *(*compilerHookVector)(void);\n"
"}VirtualMachine;\n";
@ -5417,7 +5416,7 @@ private:
}
void simplifyTypedef75() { // ticket #2426
const char code[] = "typedef _Packed struct S { long l; }; \n";
const char code[] = "typedef _Packed struct S { long l; };\n";
const std::string expected = "";
ASSERT_EQUALS(expected, tok(code));
ASSERT_EQUALS("", errout.str());
@ -7002,7 +7001,7 @@ private:
void enum10() {
// ticket 1445
const char code[] = "enum {\n"
"SHELL_SIZE = sizeof(union { int i; char *cp; double d; }) - 1, \n"
"SHELL_SIZE = sizeof(union { int i; char *cp; double d; }) - 1,\n"
"} e = SHELL_SIZE;";
const char expected[] = "int e ; e = sizeof ( union { int i ; char * cp ; double d ; } ) - 1 ;";
ASSERT_EQUALS(expected, checkSimplifyEnum(code));
@ -7186,7 +7185,7 @@ private:
void enum28() {
const char code[] = "enum { x=0 };\n"
"void f() { char x[4]; memset(x, 0, 4); \n"
"void f() { char x[4]; memset(x, 0, 4);\n"
"{ x } };\n"
"void g() { x; }";
ASSERT_EQUALS("void f ( ) { char x [ 4 ] ; memset ( x , 0 , 4 ) ; { x } } ; void g ( ) { 0 ; }", checkSimplifyEnum(code));

View File

@ -1187,7 +1187,7 @@ private:
errout.str("");
const std::string src = "void f()\n"
"{\n"
" for ( \n"
" for (\n"
"}\n";
Settings settings;
@ -1910,7 +1910,7 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f() \n"
check("void f()\n"
"{\n"
" auto_ptr<T> p2;\n"
" p2 = new T;\n"
@ -1945,39 +1945,39 @@ private:
ASSERT_EQUALS("", errout.str());
// ticket #748
check("void f() \n"
check("void f()\n"
"{\n"
" T* var = new T[10];\n"
" auto_ptr<T> p2( var );\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n"
check("void f()\n"
"{\n"
" foo::bar::baz* var = new foo::bar::baz[10];\n"
" auto_ptr<foo::bar::baz> p2( var );\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n"
check("void f()\n"
"{\n"
" auto_ptr<T> p2( new T[] );\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n"
check("void f()\n"
"{\n"
" auto_ptr<T> p2( new T[5] );\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n"
check("void f()\n"
"{\n"
" auto_ptr<foo::bar> p(new foo::bar[10]);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n"
check("void f()\n"
"{\n"
" auto_ptr<T> p2;\n"
" p2.reset( new T[] );\n"
@ -1985,34 +1985,34 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n"
check("void f()\n"
"{\n"
" auto_ptr<T> p2( new T[][] );\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n"
check("void f()\n"
"{\n"
" auto_ptr<T> p2;\n"
" p2 = new T[10];\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n"
check("void f()\n"
"{\n"
" auto_ptr<T::B> p2;\n"
" p2 = new T::B[10];\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n"
check("void f()\n"
"{\n"
" auto_ptr<T> p2;\n"
" p2.reset( new T[10] );\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n"
check("void f()\n"
"{\n"
" auto_ptr<T::B> p2;\n"
" p2.reset( new T::B[10] );\n"
@ -2034,7 +2034,6 @@ private:
" string s1, s2;\n"
" s1.swap(s2);\n"
" s2.swap(s2);\n"
" \n"
"};\n");
ASSERT_EQUALS("[test.cpp:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)'\n", errout.str());
@ -2045,7 +2044,6 @@ private:
" s2.compare(s2);\n"
" s1.compare(s2.c_str());\n"
" s1.compare(0, s1.size(), s1);\n"
" \n"
"};\n");
ASSERT_EQUALS("[test.cpp:5]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0.\n", errout.str());
@ -2058,7 +2056,6 @@ private:
" s1 = s2.substr(0, x);\n"
" s1 = s2.substr(0,std::string::npos);\n"
" s1 = s2.substr(x+5-n, 0);\n"
" \n"
"};\n");
ASSERT_EQUALS("[test.cpp:5]: (performance) Ineffective call of function \'substr\' because it returns a copy of "
"the object. Use operator= instead.\n"

View File

@ -1153,7 +1153,7 @@ private:
"{\n"
" if (a)\n"
" bar1 ();\n"
" \n"
"\n"
" else\n"
" bar2 ();\n"
"}\n";

View File

@ -1192,8 +1192,7 @@ private:
"{\n"
" int y[2];\n"
" int s;\n"
" GetField( y + 0, \n"
" y + 1 );\n"
" GetField( y + 0, y + 1 );\n"
" s = y[0]*y[1];\n"
"}\n");
ASSERT_EQUALS("", errout.str());