Re-enabled a bunch of disabled unit tests, some as TODO tests

Merged from LCppC.
This commit is contained in:
PKEuS 2021-02-20 13:02:14 +01:00 committed by Daniel Marjamäki
parent 2bd6a6c252
commit 4b01d5bdc6
5 changed files with 30 additions and 32 deletions

View File

@ -193,7 +193,7 @@ private:
// char *p1 = a + 10; // OK
// char *p2 = a + 11 // UB
TEST_CASE(pointer_out_of_bounds_1);
// TODO TEST_CASE(pointer_out_of_bounds_2);
TEST_CASE(pointer_out_of_bounds_2);
TEST_CASE(pointer_out_of_bounds_3);
TEST_CASE(pointer_out_of_bounds_4);
// TODO TEST_CASE(pointer_out_of_bounds_sub);
@ -2148,7 +2148,7 @@ private:
" int *p = a;\n"
" p[20] = 0;\n"
"}");
// TODO pointer ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds.\n", "", errout.str());
{
// address of
@ -2157,7 +2157,7 @@ private:
" int *p = a;\n"
" p[10] = 0;\n"
"}");
// TODO pointer ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", "", errout.str());
check("void f() {\n"
" int a[10];\n"
@ -2192,7 +2192,7 @@ private:
" a += 4;\n"
" a[-1] = 0;\n"
"}");
// TODO ASSERT_EQUALS("", errout.str());
TODO_ASSERT_EQUALS("", "[test.cpp:3]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n", errout.str());
}
void array_index_enum_array() { // #8439
@ -2881,7 +2881,7 @@ private:
" p += 100;\n"
" free(p);"
"}");
ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'p+100' is out of bounds.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'p+100' is out of bounds.\n", "", errout.str());
check("void f() {\n"
" char *p = malloc(10);\n"
@ -2889,7 +2889,7 @@ private:
" *p = 0;\n"
" free(p);"
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) p is out of bounds.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) p is out of bounds.\n", "", errout.str());
check("void f() {\n"
" char *p = malloc(10);\n"
@ -3352,7 +3352,8 @@ private:
" char s[10];\n"
" mymemset(s, 0, '*');\n"
"}", settings);
// TODO ASSERT_EQUALS("[test.cpp:3]: (warning) The size argument is given as a char constant.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) The size argument is given as a char constant.\n"
"[test.cpp:3]: (error) Buffer is accessed out of bounds: s\n", "[test.cpp:3]: (error) Buffer is accessed out of bounds: s\n", errout.str());
// ticket #836
check("void f(void) {\n"
@ -3557,7 +3558,7 @@ private:
" char *str = new char[5];\n"
" mysprintf(str, \"abcde\");\n"
"}", settings);
// TODO ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
check("void f(int condition) {\n"
" char str[5];\n"
@ -3583,13 +3584,13 @@ private:
" char *a = new char(30);\n"
" mysprintf(a, \"a\");\n"
"}", settings);
// TODO ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
check("void f(char value) {\n"
" char *a = new char(value);\n"
" mysprintf(a, \"a\");\n"
"}", settings);
// TODO ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
// This is out of bounds if 'sizeof(ABC)' is 1 (No padding)
check("struct Foo { char a[1]; };\n"
@ -3597,7 +3598,7 @@ private:
" struct Foo *x = malloc(sizeof(Foo));\n"
" mysprintf(x.a, \"aa\");\n"
"}", settings);
// TODO ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("", errout.str()); // TODO: Inconclusive error?
check("struct Foo { char a[1]; };\n"
"void f() {\n"

View File

@ -62,7 +62,7 @@ private:
// Invalid function usage
TEST_CASE(invalidFunctionUsage1);
// TODO TEST_CASE(invalidFunctionUsageStrings);
TEST_CASE(invalidFunctionUsageStrings);
// Math function usage
TEST_CASE(mathfunctionCall_fmod);
@ -480,32 +480,32 @@ private:
check("int f() { char x = 'x'; return strcmp(\"Hello world\", &x); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required.\n", errout.str());
check("size_t f(char x) { char * y = &x; return strlen(y) }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout.str());
check("size_t f(char x) { char * y = &x; return strlen(y); }");
TODO_ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", "", errout.str());
check("size_t f(char x) { char * y = &x; char *z = y; return strlen(z) }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout.str());
check("size_t f(char x) { char * y = &x; char *z = y; return strlen(z); }");
TODO_ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", "", errout.str());
check("size_t f() { char x = 'x'; char * y = &x; char *z = y; return strlen(z) }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout.str());
check("size_t f() { char x = 'x'; char * y = &x; char *z = y; return strlen(z); }");
TODO_ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", "", errout.str());
check("size_t f() { char x = '\\0'; char * y = &x; char *z = y; return strlen(z) }");
check("size_t f() { char x = '\\0'; char * y = &x; char *z = y; return strlen(z); }");
ASSERT_EQUALS("", errout.str());
check("size_t f() { char x[] = \"Hello world\"; return strlen(x) }");
check("size_t f() { char x[] = \"Hello world\"; return strlen(x); }");
ASSERT_EQUALS("", errout.str());
check("size_t f(char x[]) { return strlen(x) }");
check("size_t f(char x[]) { return strlen(x); }");
ASSERT_EQUALS("", errout.str());
check("int f(char x, char y) { return strcmp(&x, &y); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strcmp() argument nr 1. A nul-terminated string is required.\n"
"[test.cpp:1]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required.\n", errout.str());
check("size_t f() { char x[] = \"Hello world\"; return strlen(&x[0]) }");
check("size_t f() { char x[] = \"Hello world\"; return strlen(&x[0]); }");
ASSERT_EQUALS("", errout.str());
check("size_t f() { char* x = \"Hello world\"; return strlen(&x[0]) }");
check("size_t f() { char* x = \"Hello world\"; return strlen(&x[0]); }");
ASSERT_EQUALS("", errout.str());
check("struct S {\n"

View File

@ -72,7 +72,7 @@ private:
TEST_CASE(assign10);
TEST_CASE(assign11); // #3942: x = a(b(p));
TEST_CASE(assign12); // #4236: FP. bar(&x);
// TODO TEST_CASE(assign13); // #4237: FP. char*&ref=p; p=malloc(10); free(ref);
TEST_CASE(assign13); // #4237: FP. char*&ref=p; p=malloc(10); free(ref);
TEST_CASE(assign14);
TEST_CASE(assign15);
TEST_CASE(assign16);
@ -95,7 +95,7 @@ private:
TEST_CASE(deallocuse2);
TEST_CASE(deallocuse3);
TEST_CASE(deallocuse4);
// TODO TEST_CASE(deallocuse5); // #4018: FP. free(p), p = 0;
TEST_CASE(deallocuse5); // #4018: FP. free(p), p = 0;
TEST_CASE(deallocuse6); // #4034: FP. x = p = f();
TEST_CASE(deallocuse7); // #6467, #6469, #6473
TEST_CASE(deallocuse8); // #1765
@ -342,7 +342,7 @@ private:
" p = malloc(10);\n"
" free(ref);\n"
"}");
ASSERT_EQUALS("", errout.str());
TODO_ASSERT_EQUALS("", "[test.c:6]: (error) Memory leak: p\n", errout.str());
}
void assign14() {

View File

@ -989,7 +989,6 @@ private:
}
{
/* TODO: What to do here? since there are syntax error simplecpp outputs ""
const char filedata[] = "#define BC(b, c...) 0##b * 0##c\n"
"#define ABC(a, b...) a + BC(b)\n"
"\n"
@ -997,8 +996,7 @@ private:
"ABC(2,3);\n"
"ABC(4,5,6);\n";
ASSERT_EQUALS("\n\n\n1 + 0 * 0;\n2 + 03 * 0;\n4 + 05 * 06;", OurPreprocessor::expandMacros(filedata));
*/
ASSERT_EQUALS("\n\n\n1 + 0 * 0 ;\n2 + 03 * 0 ;\n4 + 05 * 06 ;", OurPreprocessor::expandMacros(filedata));
}
{
@ -1142,10 +1140,9 @@ private:
}
void macro_NULL() const {
// Let the tokenizer handle NULL.
// See ticket #4482 - UB when passing NULL to variadic function
ASSERT_EQUALS("\n0", OurPreprocessor::expandMacros("#define null 0\nnull"));
// TODO ASSERT_EQUALS("\nNULL", OurPreprocessor::expandMacros("#define NULL 0\nNULL"));
TODO_ASSERT_EQUALS("\nNULL", "\n0", OurPreprocessor::expandMacros("#define NULL 0\nNULL")); // TODO: Let the tokenizer handle NULL?
}
void string1() {

View File

@ -3058,7 +3058,7 @@ private:
"void A::DoSomething(void) {\n"
" const std::string x = Bar();\n" // <- warning
"}");
// TODO ASSERT_EQUALS("[test.cpp:16]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str());
ASSERT_EQUALS("[test.cpp:16]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str());
}
void localvar50() { // #6261, #6542