From bd8cb94050d9f3249d280fb33a369e11141208de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Mon, 8 Apr 2024 10:11:27 +0200 Subject: [PATCH] testrunner: small `TestSimplifyTokens` cleanup / fixed valueflow message suppression / improved ignoring of output (#6243) --- Makefile | 4 +- test/fixture.h | 5 ++ test/helpers.h | 19 ++++++ test/testbufferoverrun.cpp | 2 +- test/testclass.cpp | 2 +- test/testfunctions.cpp | 13 +--- test/testgarbage.cpp | 58 +++++++++--------- test/testpreprocessor.cpp | 2 +- test/testprocessexecutor.cpp | 4 +- test/testsimplifytokens.cpp | 94 +++++++++++++---------------- test/testsimplifytypedef.cpp | 6 +- test/testsimplifyusing.cpp | 10 ++-- test/testsingleexecutor.cpp | 4 +- test/testsuppressions.cpp | 4 +- test/testthreadexecutor.cpp | 4 +- test/testtokenize.cpp | 112 ++++++++++++++++++++++++++++------- 16 files changed, 208 insertions(+), 135 deletions(-) diff --git a/Makefile b/Makefile index 32b030b8d26..a720612033f 100644 --- a/Makefile +++ b/Makefile @@ -753,7 +753,7 @@ test/testexceptionsafety.o: test/testexceptionsafety.cpp lib/addoninfo.h lib/che test/testfilelister.o: test/testfilelister.cpp cli/filelister.h lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testfilelister.cpp -test/testfunctions.o: test/testfunctions.cpp lib/addoninfo.h lib/check.h lib/checkfunctions.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h +test/testfunctions.o: test/testfunctions.cpp lib/addoninfo.h lib/check.h lib/checkfunctions.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testfunctions.cpp test/testgarbage.o: test/testgarbage.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h @@ -816,7 +816,7 @@ test/testsettings.o: test/testsettings.cpp lib/addoninfo.h lib/check.h lib/color test/testsimplifytemplate.o: test/testsimplifytemplate.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testsimplifytemplate.cpp -test/testsimplifytokens.o: test/testsimplifytokens.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h +test/testsimplifytokens.o: test/testsimplifytokens.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testsimplifytokens.cpp test/testsimplifytypedef.o: test/testsimplifytypedef.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h diff --git a/test/fixture.h b/test/fixture.h index af227609363..63e35f79733 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -260,6 +260,11 @@ class TestFixture : public ErrorLogger { return s; } + void ignore_errout() { + if (errout_str().empty()) + throw std::runtime_error("no errout to ignore"); + } + const Settings settingsDefault; private: diff --git a/test/helpers.h b/test/helpers.h index d134b6121d1..b451b4a4597 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -170,4 +170,23 @@ struct make_default_obj } }; +inline std::string filter_valueflow(const std::string& s) { + bool filtered = false; + std::istringstream istr(s); + std::string ostr; + std::string errline; + while (std::getline(istr, errline)) { + if (errline.find("valueflow.cpp") != std::string::npos) + { + filtered = true; + continue; + } + ostr += errline; + ostr += '\n'; // TODO: last line might not contain a newline + } + if (!filtered) + throw std::runtime_error("no valueflow.cpp messages were filtered"); + return ostr; +} + #endif // helpersH diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 0160c084942..d462f44638d 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -4979,7 +4979,7 @@ class TestBufferOverrun : public TestFixture { const Check& c = getCheck(); c.getErrorMessages(this, nullptr); // we are not interested in the output - just consume it - (void)errout_str(); + ignore_errout(); } void arrayIndexThenCheck() { diff --git a/test/testclass.cpp b/test/testclass.cpp index c68ee5ca1ba..7b628149e63 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -6688,7 +6688,7 @@ class TestClass : public TestFixture { "struct D : S<150> {};\n"); // don't hang // we are not interested in the output - just consume it - (void)errout_str(); + ignore_errout(); } void const93() { // #12162 diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index a9227d636ff..d907c9ae40a 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -18,6 +18,7 @@ #include "checkfunctions.h" #include "errortypes.h" +#include "helpers.h" #include "settings.h" #include "standards.h" #include "fixture.h" @@ -104,18 +105,6 @@ class TestFunctions : public TestFixture { TEST_CASE(checkUseStandardLibrary14); } - static std::string filter_valueflow(const std::string& s) { - std::istringstream istr(s); - std::ostringstream ostr; - std::string errline; - while (std::getline(istr, errline)) { - if (errline.find("valueflow.cpp") == std::string::npos) { - ostr << errline << '\n'; - } - } - return ostr.str(); - } - #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) void check_(const char* file, int line, const char code[], const char filename[] = "test.cpp", const Settings* settings_ = nullptr) { if (!settings_) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 36827ffd0a3..8a08aff2f7c 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -355,7 +355,7 @@ class TestGarbage : public TestFixture { // don't segfault.. ASSERT_THROW(checkCode(code), InternalError); - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output } @@ -495,7 +495,7 @@ class TestGarbage : public TestFixture { void garbageCode12() { // do not crash checkCode("{ g; S (void) { struct } { } int &g; }"); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode13() { @@ -563,7 +563,7 @@ class TestGarbage : public TestFixture { " cptr = (char *)buffer;\n" " cptr += (-(long int) buffer & (16 * sizeof (float) - 1));\n" "}\n"), InternalError); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode25() { @@ -598,7 +598,7 @@ class TestGarbage : public TestFixture { " int a;\n" " R1 () : a { }\n" "};"); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode30() { @@ -606,7 +606,7 @@ class TestGarbage : public TestFixture { checkCode("void f(int x) {\n" " x = 42\n" "}"); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode31() { @@ -676,7 +676,7 @@ class TestGarbage : public TestFixture { void garbageCode46() { // #6705 checkCode(" { bar(char *x); void foo (int ...) { struct } va_list ap; va_start(ap, size); va_arg(ap, (d)); }"); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode47() { // #6706 @@ -685,7 +685,7 @@ class TestGarbage : public TestFixture { void garbageCode48() { // #6712 checkCode(" { d\" ) d ...\" } int main ( ) { ( ) catch ( A a ) { { } catch ( ) \"\" } }"); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode49() { // #6715 @@ -776,7 +776,7 @@ class TestGarbage : public TestFixture { void garbageCode74() { // #6751 ASSERT_THROW(checkCode("_lenraw(const char* digits) { } typedef decltype(sizeof(0)) { } operator"), InternalError); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode76() { // #6754 @@ -789,7 +789,7 @@ class TestGarbage : public TestFixture { void garbageCode78() { // #6756 ASSERT_THROW(checkCode("( ) { [ ] } ( ) { } const_array_of_int ( ) { } typedef int A [ ] [ ] ; A a = { { } { } }"), InternalError); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode79() { // #6757 @@ -887,7 +887,7 @@ class TestGarbage : public TestFixture { void garbageCode102() { // #6846 checkCode("struct Object { ( ) ; Object & operator= ( Object ) { ( ) { } if ( this != & b ) } }"); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode103() { // #6824 @@ -916,7 +916,7 @@ class TestGarbage : public TestFixture { void garbageCode109() { // #6900 "segmentation fault (invalid code) in CheckStl::runSimplifiedChecks" checkCode("( *const<> (( ) ) { } ( *const ( ) ( ) ) { } ( * const<> ( size_t )) ) { } ( * const ( ) ( ) ) { }"); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode110() { // #6902 "segmentation fault (invalid code) in CheckStl::string_c_str" @@ -963,7 +963,7 @@ class TestGarbage : public TestFixture { void garbageCode119() { // #5598 checkCode("{ { void foo() { struct }; template struct S { Used x; void bar() } auto f = [this] { }; } };"); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode120() { // #4927 @@ -984,7 +984,7 @@ class TestGarbage : public TestFixture { "char *a = malloc(10);\n" "a[0]\n" "}"); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode123() { @@ -993,7 +993,7 @@ class TestGarbage : public TestFixture { " C tpl_mem(T *) { return }\n" " };\n" "}"); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode125() { @@ -1017,7 +1017,7 @@ class TestGarbage : public TestFixture { "};\n" " const A& foo(const A& arg) { return arg; }\n" " foo(A(12)).Var"); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void garbageCode128() { @@ -1106,7 +1106,7 @@ class TestGarbage : public TestFixture { "template struct X {}; " "X<&S::i, int> x = X<&S::i, int>(); " "X<&S::j, int> y = X<&S::j, int>();"); - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output checkCode("template struct A {}; " "template <> struct A {}; " "void foo(const void* f = 0) {}"); @@ -1124,7 +1124,7 @@ class TestGarbage : public TestFixture { " static int i; " "}; " "void f() { A::i = 0; }"); - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output } void garbageCode135() { // #4994 @@ -1133,7 +1133,7 @@ class TestGarbage : public TestFixture { "}\n" "long a = 1 ;\n" "long b = 2 ;"); - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output } void garbageCode136() { // #7033 @@ -1155,7 +1155,7 @@ class TestGarbage : public TestFixture { " } halo;\n" "}\n" "CS_PLUGIN_NAMESPACE_END(csparser)"); - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output } void garbageCode139() { // #6659 heap user after free: kernel: sm750_accel.c @@ -1255,7 +1255,7 @@ class TestGarbage : public TestFixture { "static std::string foo(char *Bla) {\n" " while (Bla[1] && Bla[1] != ',') }\n"; checkCode(code); - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output } void garbageCode153() { @@ -1327,7 +1327,7 @@ class TestGarbage : public TestFixture { " case YY_STATE_EOF(block):\n" " yyterminate();\n" "} }"); // #5663 - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output } void garbageAST() { @@ -1398,7 +1398,7 @@ class TestGarbage : public TestFixture { "typedef something_like_tuple something_like_tuple_t;\n" "SA ((is_last::value == false));\n" "SA ((is_last::value == false));"); - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output checkCode( // #6225 "template \n" @@ -1494,7 +1494,7 @@ class TestGarbage : public TestFixture { void garbageCode176() { // #7527 checkCode("class t { { struct } enum class f : unsigned { q } b ; operator= ( T ) { switch ( b ) { case f::q: } } { assert ( b ) ; } } { ; & ( t ) ( f::t ) ; } ;"); - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output } void garbageCode181() { @@ -1527,7 +1527,7 @@ class TestGarbage : public TestFixture { " return bStatus;\n" " };\n" "}"); - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output } // #8151 - segfault due to incorrect template syntax @@ -1721,7 +1721,7 @@ class TestGarbage : public TestFixture { void garbageCode218() { // #8763 checkCode("d f(){t n0000 const[]n0000+0!=n0000,(0)}"); // don't crash - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output } void garbageCode219() { // #10101 checkCode("typedef void (*func) (addr) ;\n" @@ -1729,7 +1729,7 @@ class TestGarbage : public TestFixture { " func f;\n" " f & = (func)42;\n" "}\n"); // don't crash - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output } void garbageCode220() { // #6832 ASSERT_THROW(checkCode("(){(){{()}}return;{switch()0 case(){}break;l:()}}\n"), InternalError); // don't crash @@ -1817,7 +1817,7 @@ class TestGarbage : public TestFixture { ASSERT_THROW(checkCode("void f(){x=0,return return''[]()}"), InternalError); ASSERT_THROW(checkCode("void f(){x='0'++'0'(return)[];}"), InternalError); // #9063 checkCode("void f(){*(int *)42=0;}"); // no syntax error - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output ASSERT_THROW(checkCode("void f() { x= 'x' > typedef name5 | ( , ;){ } (); }"), InternalError); // #9067 ASSERT_THROW(checkCode("void f() { x= {}( ) ( 'x')[ ] (); }"), InternalError); // #9068 ASSERT_THROW(checkCode("void f() { x= y{ } name5 y[ ] + y ^ name5 ^ name5 for ( ( y y y && y y y && name5 ++ int )); }"), InternalError); // #9069 @@ -1832,7 +1832,7 @@ class TestGarbage : public TestFixture { "bool bReturn(false);\n" "}\n" "};")); - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output } void enumTrailingComma() { @@ -1850,7 +1850,7 @@ class TestGarbage : public TestFixture { "template< class Predicate > int\n" "List::DeleteIf( const Predicate &pred )\n" "{}"); - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output // #8749 checkCode( diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 1235ab8aaf3..2144d0a9885 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -1977,7 +1977,7 @@ class TestPreprocessor : public TestFixture { ASSERT_EQUALS(false, suppr.checked); ASSERT_EQUALS(false, suppr.matched); - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output } void predefine1() { diff --git a/test/testprocessexecutor.cpp b/test/testprocessexecutor.cpp index f8bfd7fbdac..51caf802405 100644 --- a/test/testprocessexecutor.cpp +++ b/test/testprocessexecutor.cpp @@ -187,7 +187,7 @@ class TestProcessExecutorBase : public TestFixture { " return 0;\n" "}", dinit(CheckOptions, $.showtime = SHOWTIME_MODES::SHOWTIME_SUMMARY)); // we are not interested in the results - so just consume them - (void)errout_str(); + ignore_errout(); } void many_threads_plist() { @@ -201,7 +201,7 @@ class TestProcessExecutorBase : public TestFixture { " return 0;\n" "}", dinit(CheckOptions, $.plistOutput = plistOutput.c_str())); // we are not interested in the results - so just consume them - (void)errout_str(); + ignore_errout(); } void no_errors_more_files() { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 209f53f3a48..e49771b81a9 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -17,6 +17,7 @@ */ #include "errortypes.h" +#include "helpers.h" #include "platform.h" #include "settings.h" #include "standards.h" @@ -165,29 +166,27 @@ class TestSimplifyTokens : public TestFixture { } #define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__) - std::string tok_(const char* file, int line, const char code[], bool simplify = true, Platform::Type type = Platform::Type::Native) { + std::string tok_(const char* file, int line, const char code[], Platform::Type type = Platform::Type::Native) { const Settings settings = settingsBuilder(settings0).platform(type).build(); Tokenizer tokenizer(settings, this); std::istringstream istr(code); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); - return tokenizer.tokens()->stringifyList(nullptr, !simplify); + return tokenizer.tokens()->stringifyList(nullptr, false); } - std::string tok_(const char* file, int line, const char code[], const char filename[], bool simplify = true) { + std::string tok_(const char* file, int line, const char code[], const char filename[]) { Tokenizer tokenizer(settings0, this); std::istringstream istr(code); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); - (void)simplify; - return tokenizer.tokens()->stringifyList(nullptr, false); } #define tokenizeAndStringify(...) tokenizeAndStringify_(__FILE__, __LINE__, __VA_ARGS__) - std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool simplify = false, bool expand = true, Platform::Type platform = Platform::Type::Native, const char* filename = "test.cpp", bool cpp11 = true) { + std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool expand = true, Platform::Type platform = Platform::Type::Native, const char* filename = "test.cpp", bool cpp11 = true) { const Settings settings = settingsBuilder(settings1).debugwarnings().platform(platform).cpp(cpp11 ? Standards::CPP11 : Standards::CPP03).build(); // tokenize.. @@ -195,31 +194,17 @@ class TestSimplifyTokens : public TestFixture { std::istringstream istr(code); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr); - (void)simplify; - - // TODO: should be handled in a better way - // filter out ValueFlow messages.. - const std::string debugwarnings = errout_str(); - std::istringstream istr2(debugwarnings); - std::string line; - while (std::getline(istr2,line)) { - if (line.find("bailout") == std::string::npos) - {} // TODO mErrout << line << "\n"; - } - if (tokenizer.tokens()) return tokenizer.tokens()->stringifyList(false, expand, false, true, false, nullptr, nullptr); return ""; } #define tokenizeDebugListing(...) tokenizeDebugListing_(__FILE__, __LINE__, __VA_ARGS__) - std::string tokenizeDebugListing_(const char* file, int line, const char code[], bool simplify = false, const char filename[] = "test.cpp") { + std::string tokenizeDebugListing_(const char* file, int line, const char code[], const char filename[] = "test.cpp") { Tokenizer tokenizer(settings0, this); std::istringstream istr(code); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); - (void)simplify; - // result.. return tokenizer.tokens()->stringifyList(true); } @@ -246,10 +231,10 @@ class TestSimplifyTokens : public TestFixture { ASSERT_EQUALS(tok(code2), tok(code1)); const char code3[] = "x = L\"1\" TEXT(\"2\") L\"3\";"; - ASSERT_EQUALS("x = L\"123\" ;", tok(code3, false, Platform::Type::Win64)); + ASSERT_EQUALS("x = L\"123\" ;", tok(code3, Platform::Type::Win64)); const char code4[] = "x = TEXT(\"1\") L\"2\";"; - ASSERT_EQUALS("x = L\"1\" L\"2\" ;", tok(code4, false, Platform::Type::Win64)); + ASSERT_EQUALS("x = L\"1\" L\"2\" ;", tok(code4, Platform::Type::Win64)); } void combine_wstrings() { @@ -1345,12 +1330,12 @@ class TestSimplifyTokens : public TestFixture { ASSERT_EQUALS("int f ( ) ;", tok("int __far __syscall f();")); ASSERT_EQUALS("int f ( ) ;", tok("int __far __pascal f();")); ASSERT_EQUALS("int f ( ) ;", tok("int __far __fortran f();")); - ASSERT_EQUALS("int f ( ) ;", tok("int WINAPI f();", true, Platform::Type::Win32A)); - ASSERT_EQUALS("int f ( ) ;", tok("int APIENTRY f();", true, Platform::Type::Win32A)); - ASSERT_EQUALS("int f ( ) ;", tok("int CALLBACK f();", true, Platform::Type::Win32A)); + ASSERT_EQUALS("int f ( ) ;", tok("int WINAPI f();", Platform::Type::Win32A)); + ASSERT_EQUALS("int f ( ) ;", tok("int APIENTRY f();", Platform::Type::Win32A)); + ASSERT_EQUALS("int f ( ) ;", tok("int CALLBACK f();", Platform::Type::Win32A)); // don't simplify Microsoft defines in unix code (#7554) - ASSERT_EQUALS("enum E { CALLBACK } ;", tok("enum E { CALLBACK } ;", true, Platform::Type::Unix32)); + ASSERT_EQUALS("enum E { CALLBACK } ;", tok("enum E { CALLBACK } ;", Platform::Type::Unix32)); } void simplifyAttribute() { @@ -1728,7 +1713,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 + v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1746,7 +1731,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 - v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1764,7 +1749,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 * v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1782,7 +1767,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 / v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1800,7 +1785,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 & v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1818,7 +1803,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 | v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1836,7 +1821,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 ^ v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1854,7 +1839,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 % v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1872,7 +1857,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 >> v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1890,7 +1875,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 << v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1908,7 +1893,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 == v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1926,7 +1911,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 != v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1944,7 +1929,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 > v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1962,7 +1947,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 >= v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1980,7 +1965,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 < v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -1998,7 +1983,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 <= v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -2016,7 +2001,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 && v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } { @@ -2034,7 +2019,7 @@ class TestSimplifyTokens : public TestFixture { "4:\n" "5: return u@1 || v@2 ;\n" "6: }\n"; - ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } } @@ -2089,7 +2074,7 @@ class TestSimplifyTokens : public TestFixture { "strcpy ( a , \"hello\" ) ;\n" "strcat ( a , \"!\" ) ;\n" "}"; - ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Platform::Type::Native, "test.c")); + ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, Platform::Type::Native, "test.c")); } { @@ -2131,6 +2116,7 @@ class TestSimplifyTokens : public TestFixture { "if ( s [ 6 ] == ' ' ) { ; }\n" "}"; ASSERT_EQUALS(expected, tokenizeAndStringify(code,true)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } } @@ -2185,7 +2171,7 @@ class TestSimplifyTokens : public TestFixture { "cin >> x ;\n" "return x ;\n" "}"; - ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Platform::Type::Native, "test.cpp")); + ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, Platform::Type::Native, "test.cpp")); } } @@ -2199,7 +2185,7 @@ class TestSimplifyTokens : public TestFixture { "int x ; x = 0 ;\n" "cin >> std :: hex >> x ;\n" "}"; - ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Platform::Type::Native, "test.cpp")); + ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, Platform::Type::Native, "test.cpp")); } void simplifyKnownVariables48() { @@ -2212,7 +2198,7 @@ class TestSimplifyTokens : public TestFixture { "int i ;\n" "for ( i = 0 ; ( i < sz ) && ( sz > 3 ) ; ++ i ) { }\n" "}"; - ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Platform::Type::Native, "test.c")); + ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, Platform::Type::Native, "test.c")); } void simplifyKnownVariables49() { // #3691 @@ -2228,7 +2214,7 @@ class TestSimplifyTokens : public TestFixture { "case 2 : ; x = sz ; break ;\n" "}\n" "}"; - ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Platform::Type::Native, "test.c")); + ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, Platform::Type::Native, "test.c")); } void simplifyKnownVariables50() { // #4066 @@ -2336,7 +2322,7 @@ class TestSimplifyTokens : public TestFixture { " Other\n" " };\n" " enum { XX };\n" - "};", /*simplify=*/ true); + "};", /*expand=*/ true); ASSERT_EQUALS("", errout_str()); } @@ -2348,7 +2334,7 @@ class TestSimplifyTokens : public TestFixture { tokenizeAndStringify("void foo(std::string str) {\n" " char *p = &str[0];\n" " *p = 0;\n" - "}", /*simplify=*/ true)); + "}", /*expand=*/ true)); } void simplifyKnownVariables63() { // #10798 @@ -2369,6 +2355,7 @@ class TestSimplifyTokens : public TestFixture { "return i ;\n" "}"; ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void simplifyKnownVariablesBailOutAssign2() { @@ -2442,7 +2429,7 @@ class TestSimplifyTokens : public TestFixture { " return a;\n" "}\n"; tokenizeAndStringify(code,true); - ASSERT_EQUALS("", errout_str()); // no debug warnings + ASSERT_EQUALS("", filter_valueflow(errout_str())); // no debug warnings } void simplifyKnownVariablesBailOutSwitchBreak() { @@ -2504,6 +2491,7 @@ class TestSimplifyTokens : public TestFixture { " while (!x) { dostuff(); }" "}"; ASSERT_EQUALS("static int x ; void f ( ) { x = 123 ; while ( ! x ) { dostuff ( ) ; } }", tokenizeAndStringify(code,true)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void simplifyKnownVariablesNamespace() { diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index b0526b3c33d..88dad9f0674 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -2522,7 +2522,7 @@ class TestSimplifyTypedef : public TestFixture { void simplifyTypedef107() { // ticket #3963 (bad code => segmentation fault) const char code[] = "typedef int x[]; int main() { return x }"; ASSERT_EQUALS("int main ( ) { return x }", tok(code)); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void simplifyTypedef108() { // ticket #4777 @@ -3403,14 +3403,14 @@ class TestSimplifyTypedef : public TestFixture { " sizeof(t);\n" "}\n"; ASSERT_EQUALS("void g ( ) { sizeof ( t ) ; }", tok(code)); // TODO: handle implicit int - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output code = "typedef t[3];\n" "void g() {\n" " sizeof(t);\n" "}\n"; ASSERT_EQUALS("void g ( ) { sizeof ( t ) ; }", tok(code)); // TODO: handle implicit int - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void simplifyTypedef146() { diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 46e0838b3e8..a5714103a71 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -485,7 +485,7 @@ class TestSimplifyUsing : public TestFixture { "}\n" "}"; tok(code); // don't hang - (void)errout_str(); // we are not interested in the output + ignore_errout(); // we are not interested in the output } void simplifyUsing20() { @@ -530,7 +530,7 @@ class TestSimplifyUsing : public TestFixture { "}\n" "}}}}}}}"; tok(code); // don't hang - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void simplifyUsing21() { @@ -562,7 +562,7 @@ class TestSimplifyUsing : public TestFixture { "} " "} } } } }"; ASSERT_EQUALS(expected, tok(code)); // don't hang - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } void simplifyUsing23() { @@ -1294,7 +1294,7 @@ class TestSimplifyUsing : public TestFixture { " return ret;\n" "}"; tok(code); // don't crash - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } } @@ -1440,7 +1440,7 @@ class TestSimplifyUsing : public TestFixture { "} " "}"; ASSERT_EQUALS(exp, tok(code)); - (void)errout_str(); // we do not care about the output + ignore_errout(); // we do not care about the output } } diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp index 4db0307257f..2de91fccf2f 100644 --- a/test/testsingleexecutor.cpp +++ b/test/testsingleexecutor.cpp @@ -190,7 +190,7 @@ class TestSingleExecutorBase : public TestFixture { " return 0;\n" "}", dinit(CheckOptions, $.showtime = SHOWTIME_MODES::SHOWTIME_SUMMARY)); // we are not interested in the results - so just consume them - (void)errout_str(); + ignore_errout(); } void many_files_plist() { @@ -204,7 +204,7 @@ class TestSingleExecutorBase : public TestFixture { " return 0;\n" "}", dinit(CheckOptions, $.plistOutput = plistOutput.c_str())); // we are not interested in the results - so just consume them - (void)errout_str(); + ignore_errout(); } void no_errors_more_files() { diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index 4de36a14a86..9eb7adb08de 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -856,14 +856,14 @@ class TestSuppressions : public TestFixture { " int a; return a;\n" "}\n", "")); - (void)errout_str(); + ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: a\n", errout_str()); ASSERT_EQUALS(0U, (this->*check)("int f() {\n" " int a; return a;\n" "}\n", "uninitvar")); - (void)errout_str(); + ASSERT_EQUALS("", errout_str()); // cppcheck-suppress-macro (this->*check)("// cppcheck-suppress-macro zerodiv\n" diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index 24d6a16d65e..46389de85b0 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -188,7 +188,7 @@ class TestThreadExecutorBase : public TestFixture { " return 0;\n" "}", dinit(CheckOptions, $.showtime = SHOWTIME_MODES::SHOWTIME_SUMMARY)); // we are not interested in the results - so just consume them - (void)errout_str(); + ignore_errout(); } void many_threads_plist() { @@ -202,7 +202,7 @@ class TestThreadExecutorBase : public TestFixture { " return 0;\n" "}", dinit(CheckOptions, $.plistOutput = plistOutput.c_str())); // we are not interested in the results - so just consume them - (void)errout_str(); + ignore_errout(); } void no_errors_more_files() { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 18f15edcb9d..c60cc947901 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -460,16 +460,6 @@ class TestTokenizer : public TestFixture { std::istringstream istr(code); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr); - // TODO: handle in a better way - // filter out ValueFlow messages.. - const std::string debugwarnings = errout_str(); - std::istringstream istr2(debugwarnings); - std::string line; - while (std::getline(istr2,line)) { - if (line.find("bailout") == std::string::npos) - {} // TODO mErrout << line << "\n"; - } - if (tokenizer.tokens()) return tokenizer.tokens()->stringifyList(false, expand, false, true, false, nullptr, nullptr); return ""; @@ -484,15 +474,6 @@ class TestTokenizer : public TestFixture { std::istringstream istr(code); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr); - // filter out ValueFlow messages.. - const std::string debugwarnings = errout_str(); - std::istringstream istr2(debugwarnings); - std::string line; - while (std::getline(istr2,line)) { - if (line.find("valueflow.cpp") == std::string::npos) - {} // TODO errout << line << "\n"; - } - if (tokenizer.tokens()) return tokenizer.tokens()->stringifyList(false, expand, false, true, false, nullptr, nullptr); return ""; @@ -651,6 +632,7 @@ class TestTokenizer : public TestFixture { " v[dim]->f();\n" " }\n" "};")); + ignore_errout(); // we do not care about the output } void tokenize21() { // tokenize 0x0E-7 @@ -874,6 +856,7 @@ class TestTokenizer : public TestFixture { void ifconstexpr() { ASSERT_EQUALS("void f ( ) { if ( FOO ) { bar ( c ) ; } }", tokenizeAndStringify("void f() { if constexpr ( FOO ) { bar(c); } }")); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void combineOperators() { @@ -1036,6 +1019,7 @@ class TestTokenizer : public TestFixture { "if ( a ) { ; }\n" "else { ; }\n" "}", tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void ifAddBraces2() { @@ -1047,6 +1031,7 @@ class TestTokenizer : public TestFixture { "{\n" "if ( a ) { if ( b ) { } }\n" "}", tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void ifAddBraces3() { @@ -1058,6 +1043,7 @@ class TestTokenizer : public TestFixture { "{\n" "if ( a ) { for ( ; ; ) { } }\n" "}", tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void ifAddBraces4() { @@ -1077,6 +1063,7 @@ class TestTokenizer : public TestFixture { "{ } }\n" "return str ;\n" "}", tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void ifAddBraces5() { @@ -1111,6 +1098,7 @@ class TestTokenizer : public TestFixture { "if ( a ) {\n" "( { a = 4 ; } ) , ( { a = 5 ; } ) ; }\n" "}", tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void ifAddBraces9() { @@ -1162,6 +1150,7 @@ class TestTokenizer : public TestFixture { "}"; ASSERT_EQUALS("void f ( ) { ( void ) ( { if ( * p ) { ( * p ) = x ( ) ; } } ) }", tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } } @@ -1182,6 +1171,7 @@ class TestTokenizer : public TestFixture { "else {\n" "bar2 ( ) ; }\n" "}", tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void ifAddBraces18() { @@ -1213,6 +1203,7 @@ class TestTokenizer : public TestFixture { "else {\n" "bar2 ( ) ; } } }\n" "}", tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void ifAddBraces20() { // #5012 - syntax error 'else }' @@ -1230,6 +1221,7 @@ class TestTokenizer : public TestFixture { " if (x)\n" " l1: l2: return x;\n" "}")); + ASSERT_EQUALS("", filter_valueflow(errout_str())); // Labels before { ASSERT_EQUALS("int f ( int x ) {\n" @@ -1240,6 +1232,7 @@ class TestTokenizer : public TestFixture { " if (x)\n" " l1: l2: { return x; }\n" "}")); + ASSERT_EQUALS("", filter_valueflow(errout_str())); // Labels before try/catch ASSERT_EQUALS("int f ( int x ) {\n" @@ -1254,6 +1247,7 @@ class TestTokenizer : public TestFixture { " try { throw 1; }\n" " catch(...) { return x; }\n" "}")); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void switchAddBracesLabels() { @@ -1307,6 +1301,7 @@ class TestTokenizer : public TestFixture { " while (x)\n" " l1: l2: --x;\n" "}")); + ASSERT_EQUALS("", filter_valueflow(errout_str())); // Labels before { ASSERT_EQUALS("void f ( int x ) {\n" @@ -1317,6 +1312,7 @@ class TestTokenizer : public TestFixture { " while (x)\n" " l1: l2: { -- x; }\n" "}")); + ASSERT_EQUALS("", filter_valueflow(errout_str())); // Labels before try/catch ASSERT_EQUALS("void f ( int x ) {\n" @@ -1331,6 +1327,7 @@ class TestTokenizer : public TestFixture { " try { throw 1; }\n" " catch(...) { --x; }\n" "}")); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void doWhileAddBraces() { @@ -1339,16 +1336,19 @@ class TestTokenizer : public TestFixture { const char result[] = "{ do { ; } while ( 0 ) ; }"; ASSERT_EQUALS(result, tokenizeAndStringify(code)); + ASSERT_EQUALS("", errout_str()); } { const char code[] = "{ UNKNOWN_MACRO ( do ) ; while ( a -- ) ; }"; ASSERT_THROW(tokenizeAndStringify(code), InternalError); + ASSERT_EQUALS("", errout_str()); } { const char code[] = "{ UNKNOWN_MACRO ( do , foo ) ; while ( a -- ) ; }"; ASSERT_THROW(tokenizeAndStringify(code), InternalError); + ASSERT_EQUALS("", errout_str()); } { @@ -1369,6 +1369,7 @@ class TestTokenizer : public TestFixture { "return 0 ;\n" "}"; ASSERT_EQUALS(result, tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } { @@ -1385,6 +1386,7 @@ class TestTokenizer : public TestFixture { "return 0 ;\n" "}"; ASSERT_EQUALS(result, tokenizeAndStringify(code)); + ASSERT_EQUALS("", errout_str()); } { @@ -1396,6 +1398,7 @@ class TestTokenizer : public TestFixture { "do { while ( x ) { f ( ) ; } } while ( y ) ;\n" "}"; ASSERT_EQUALS(result, tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } } @@ -1454,6 +1457,7 @@ class TestTokenizer : public TestFixture { "else { } }\n" "}"; ASSERT_EQUALS(expected, tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } { @@ -1470,6 +1474,7 @@ class TestTokenizer : public TestFixture { "else { } } }\n" "}"; ASSERT_EQUALS(expected, tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } } @@ -1568,20 +1573,27 @@ class TestTokenizer : public TestFixture { { const char code[] = "char a [ ABC ( DEF ) ] ;"; ASSERT_EQUALS(code, tokenizeAndStringify(code)); + ASSERT_EQUALS("", errout_str()); } { const char code[] = "module ( a , a , sizeof ( a ) , 0444 ) ;"; ASSERT_EQUALS("module ( a , a , sizeof ( a ) , 0444 ) ;", tokenizeAndStringify(code)); + ASSERT_EQUALS("", errout_str()); } ASSERT_EQUALS("void f ( int x ) { }", tokenizeAndStringify("void f(x) int x; { }")); + ASSERT_EQUALS("", errout_str()); ASSERT_EQUALS("void f ( int x , char y ) { }", tokenizeAndStringify("void f(x,y) int x; char y; { }")); + ASSERT_EQUALS("", errout_str()); ASSERT_EQUALS("int main ( int argc , char * argv [ ] ) { }", tokenizeAndStringify("int main(argc,argv) int argc; char *argv[]; { }")); + ASSERT_EQUALS("", errout_str()); ASSERT_EQUALS("int f ( int p , int w , float d ) { }", tokenizeAndStringify("int f(p,w,d) float d; { }")); + ASSERT_EQUALS("", errout_str()); // #1067 - Not simplified. Feel free to fix so it is simplified correctly but this syntax is obsolescent. ASSERT_EQUALS("int ( * d ( a , b , c ) ) ( ) int a ; int b ; int c ; { }", tokenizeAndStringify("int (*d(a,b,c))()int a,b,c; { }")); + ASSERT_EQUALS("", errout_str()); { // This is not a function but the pattern is similar.. @@ -1592,6 +1604,7 @@ class TestTokenizer : public TestFixture { " { }" "}"; ASSERT_EQUALS("void foo ( ) { if ( x ) { int x ; } { } }", tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } } @@ -1637,6 +1650,7 @@ class TestTokenizer : public TestFixture { const char code[] = "template < typename T1 > template < typename T2 > " "void A < T1 > :: foo ( T2 ) { }"; ASSERT_EQUALS(code, tokenizeAndStringify(code)); + ASSERT_EQUALS("[test.cpp:1]: (debug) Executable scope 'foo' with unknown function.\n", errout_str()); } void simplifyFunctionParametersErrors() { @@ -2426,6 +2440,7 @@ class TestTokenizer : public TestFixture { "{\n" "const int X = 0 ;\n" "}", tokenizeAndStringify(code)); + ASSERT_EQUALS("[test.cpp:1]: (debug) Executable scope 'b' with unknown function.\n", errout_str()); } void vardecl21() { // type in namespace @@ -2489,6 +2504,7 @@ class TestTokenizer : public TestFixture { "void A::a() {\n" " b = new d( [this]( const P & p) -> double { return this->func(p);} );\n" "}"); + ignore_errout(); } void vardecl26() { // #5907 @@ -2496,6 +2512,7 @@ class TestTokenizer : public TestFixture { const char expected[] = "extern int * new ; extern int obj ; extern int player ;"; ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, Platform::Type::Native, "test.c")); ASSERT_EQUALS(expected, tokenizeAndStringify(code)); + ASSERT_EQUALS("[test.cpp:1]: (debug) Scope::checkVariable found variable 'new' with varid 0.\n", errout_str()); } void vardecl27() { // #7850 @@ -3655,18 +3672,22 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("char buf [ 100 ] ; readlink ( path , buf , 99 ) ;", tokenizeAndStringify("char buf[100] ; readlink(path, &buf[0], 99);", true, Platform::Type::Native, "test.c")); + ASSERT_EQUALS("", errout_str()); ASSERT_EQUALS("void foo ( char * c ) { if ( 1 == ( 1 & c [ 0 ] ) ) { } }", tokenizeAndStringify("void foo(char *c) { if (1==(1 & c[0])) {} }", true, Platform::Type::Native, "test.c")); + ASSERT_EQUALS("", filter_valueflow(errout_str())); // Simplification of unknown type - C only ASSERT_EQUALS("foo data [ 100 ] ; something ( foo ) ;", tokenizeAndStringify("foo data[100]; something(&foo[0]);", true, Platform::Type::Native, "test.c")); + ASSERT_EQUALS("", errout_str()); // C++: No pointer simplification ASSERT_EQUALS("foo data [ 100 ] ; something ( & foo [ 0 ] ) ;", tokenizeAndStringify("foo data[100]; something(&foo[0]);")); + ASSERT_EQUALS("", errout_str()); } void simplifyFunctionPointers1() { @@ -4137,6 +4158,7 @@ class TestTokenizer : public TestFixture { void cpp14template() { // Ticket #6708 tokenizeAndStringify("template " "decltype(auto) forward(T& t) { return 0; }"); + ASSERT_EQUALS("[test.cpp:1]: (debug) auto token with no type.\n", errout_str()); } void arraySize() { @@ -4929,6 +4951,8 @@ class TestTokenizer : public TestFixture { const char exp[] = "struct S { int a ; int b ; } ; void f ( struct S * compl ) { compl . a = compl . b ; }"; ASSERT_EQUALS(exp, tokenizeAndStringify(code, true, Platform::Type::Native, "test.c")); } + + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void simplifyRoundCurlyParentheses() { @@ -5080,18 +5104,23 @@ class TestTokenizer : public TestFixture { void simplifyOperatorName11() { // #8889 const char code[] = "auto operator = (const Fred & other) -> Fred & ;"; ASSERT_EQUALS("auto operator= ( const Fred & other ) . Fred & ;", tokenizeAndStringify(code)); + ASSERT_EQUALS("[test.cpp:1]: (debug) auto token with no type.\n", errout_str()); const char code1[] = "auto operator = (const Fred & other) -> Fred & { }"; ASSERT_EQUALS("auto operator= ( const Fred & other ) . Fred & { }", tokenizeAndStringify(code1)); + ASSERT_EQUALS("[test.cpp:1]: (debug) auto token with no type.\n", errout_str()); const char code2[] = "template void g(S<&T::operator+ >) {}"; ASSERT_EQUALS("template < typename T > void g ( S < & T :: operator+ > ) { }", tokenizeAndStringify(code2)); + ASSERT_EQUALS("", errout_str()); const char code3[] = "template void g(S<&T::operator int>) {}"; ASSERT_EQUALS("template < typename T > void g ( S < & T :: operatorint > ) { }", tokenizeAndStringify(code3)); + ASSERT_EQUALS("", errout_str()); const char code4[] = "template void g(S<&T::template operator- >) {}"; ASSERT_EQUALS("template < typename T > void g ( S < & T :: operator- < double > > ) { }", tokenizeAndStringify(code4)); + ASSERT_EQUALS("", errout_str()); } void simplifyOperatorName12() { // #9110 @@ -5258,6 +5287,7 @@ class TestTokenizer : public TestFixture { "return RSLNotEqual ; " "}", tokenizeAndStringify(code)); + ASSERT_EQUALS("", filter_valueflow(errout_str())); } void simplifyOperatorName23() { @@ -5271,6 +5301,7 @@ class TestTokenizer : public TestFixture { "return & ( this . Element [ i ] [ 0 ] ) ; " "}", tokenizeAndStringify(code)); + ignore_errout(); } { const char code[] = "double *vtkMatrix3x3::operator,(const unsigned int i) {" @@ -5282,6 +5313,7 @@ class TestTokenizer : public TestFixture { "return & ( this . Element [ i ] [ 0 ] ) ; " "}", tokenizeAndStringify(code)); + ignore_errout(); } } @@ -5326,6 +5358,7 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("template < class ... Ts > struct overloaded : Ts ... { using Ts :: operator ( ) ... ; } ;\n" "int main ( ) { }", tokenizeAndStringify(code)); + ASSERT_EQUALS("[test.cpp:1]: (debug) simplifyOperatorName: found unsimplified operator name\n", errout_str()); } void simplifyOperatorName29() { @@ -6417,6 +6450,7 @@ class TestTokenizer : public TestFixture { "void f(void* p, B* b) {\n" " b->hash = (g(b->hash))(p);\n" "}\n")); + ignore_errout(); ASSERT_NO_THROW(tokenizeAndStringify("struct A;\n" "struct B { A* hash; };\n" "A* h(void* p);\n" @@ -6425,11 +6459,13 @@ class TestTokenizer : public TestFixture { "void f(void* p, B * b) {\n" "b->hash = (g(b->hash))(p);\n" "}\n")); + ASSERT_EQUALS("", errout_str()); ASSERT_NO_THROW(tokenizeAndStringify("struct A;\n" "struct B { A* hash; };\n" "void f(void* p, B* b) {\n" " b->hash = (decltype(b->hash))(p);\n" "}\n")); + ASSERT_EQUALS("", errout_str()); ASSERT_NO_THROW(tokenizeAndStringify("void a(int);\n" // #10801 " struct b {\n" @@ -6438,6 +6474,7 @@ class TestTokenizer : public TestFixture { "void f() {\n" " (decltype (&a)(d.c))(0);\n" "}\n")); + ASSERT_EQUALS("", errout_str()); // #10334: Do not hang! tokenizeAndStringify("void foo(const std::vector& locations = {\"\"}) {\n" @@ -6448,10 +6485,12 @@ class TestTokenizer : public TestFixture { ASSERT_NO_THROW(tokenizeAndStringify("void f() {\n" // #10831 " auto g = [](std::function h = []() {}) { };\n" "}")); + ASSERT_EQUALS("", errout_str()); ASSERT_NO_THROW(tokenizeAndStringify("void f() {\n" // #11379 " auto l = [x = 3](std::string&& v) { };\n" "}\n")); + ASSERT_EQUALS("", errout_str()); } void astbrackets() { // [] @@ -6555,41 +6594,53 @@ class TestTokenizer : public TestFixture { void asttemplate() { // uninstantiated templates will have <,>,etc.. ASSERT_EQUALS("a(3==", testAst("a()==3")); + ASSERT_EQUALS("", errout_str()); ASSERT_EQUALS("ab(== f(", testAst("a == b(); f();")); + ASSERT_EQUALS("", errout_str()); ASSERT_EQUALS("static_casta(i[", testAst("; static_cast(a)[i];")); // #6203 + ASSERT_EQUALS("", errout_str()); ASSERT_EQUALS("reinterpret_castreinterpret_castptr(123&(", testAst(";reinterpret_cast(reinterpret_cast(ptr) & 123);")); // #7253 + ASSERT_EQUALS("", errout_str()); ASSERT_EQUALS("bcd.(=", testAst(";a && b = c->d();")); + ASSERT_EQUALS("", errout_str()); // This two unit tests were added to avoid a crash. The actual correct AST result for non-executable code has not been determined so far. ASSERT_NO_THROW(testAst("class C : public ::a::b { };")); + ASSERT_EQUALS("", errout_str()); ASSERT_EQUALS("AB: abc+=", testAst("struct A : public B { void f() { a=b+c; } };")); + ASSERT_EQUALS("", errout_str()); ASSERT_EQUALS("xfts(=", testAst("; auto x = f(ts...);")); + ASSERT_EQUALS("", errout_str()); ASSERT_EQUALS("dae(new= ifd(", testAst("template \n" // #10199 "void c(b... e) {\n" " a d = new a((e)...);\n" " if (d) {}\n" "}\n")); + ASSERT_EQUALS("", errout_str()); ASSERT_EQUALS("ad*astdforward::e((new= ifd(", testAst("struct a {};\n" // #11103 "template void c(b... e) {\n" " a* d = new a(std::forward(e)...);\n" " if (d) {}\n" "}\n")); + ASSERT_EQUALS("", errout_str()); ASSERT_EQUALS("stddir::Args...&&, dir\"abc\"+= dirconcatstdforward::args((+return", testAst("template std::string concat(std::string dir, Args&& ...args) {\n" // #10492 " dir += \"abc\";\n" " return dir + concat(std::forward(args)...);\n" "}\n")); + ASSERT_EQUALS("", errout_str()); // #11369 ASSERT_NO_THROW(tokenizeAndStringify("int a;\n" "template auto b() -> decltype(a) {\n" " if (a) {}\n" "}\n")); + ignore_errout(); } void astcast() { @@ -6702,6 +6753,7 @@ class TestTokenizer : public TestFixture { // #9729 ASSERT_NO_THROW(tokenizeAndStringify("void foo() { bar([]() noexcept { if (0) {} }); }")); + ASSERT_EQUALS("", errout_str()); // #11128 ASSERT_NO_THROW(tokenizeAndStringify("template \n" @@ -6714,6 +6766,7 @@ class TestTokenizer : public TestFixture { " else\n" " return z;\n" "}\n", true, Platform::Type::Native, "test.cpp", Standards::CPP17)); + ignore_errout(); // #10079 - createInnerAST bug.. ASSERT_EQUALS("x{([= yz= switchy(", @@ -6733,6 +6786,7 @@ class TestTokenizer : public TestFixture { " return a < b;\n" " });\n" "}\n")); + ignore_errout(); ASSERT_NO_THROW(tokenizeAndStringify("namespace N {\n" " enum E : bool { F };\n" @@ -6747,6 +6801,7 @@ class TestTokenizer : public TestFixture { " return a < b;\n" " });\n" "}\n")); + ignore_errout(); ASSERT_NO_THROW(tokenizeAndStringify("void f(const std::vector& v) {\n" " std::for_each(v.begin(), v.end(), [&](char c) {\n" @@ -6758,6 +6813,7 @@ class TestTokenizer : public TestFixture { " }\n" " });\n" "}\n")); + ASSERT_EQUALS("", errout_str()); ASSERT_NO_THROW(tokenizeAndStringify("struct A { A(int) {} };\n" "void g(void (*)(int));\n" @@ -6771,6 +6827,7 @@ class TestTokenizer : public TestFixture { " }\n" " });\n" "}\n")); + ASSERT_EQUALS("", errout_str()); // #11378 ASSERT_EQUALS("gT{(&[{= 0return", testAst("auto g = T{ [&]() noexcept -> int { return 0; } };")); @@ -7096,6 +7153,8 @@ class TestTokenizer : public TestFixture { ASSERT_NO_THROW(tokenizeAndStringify("S* g = ::new(ptr) S();")); // #12552 ASSERT_NO_THROW(tokenizeAndStringify("void f(int* p) { return ::delete p; }")); + + ignore_errout(); } @@ -7106,12 +7165,14 @@ class TestTokenizer : public TestFixture { " typename std::enable_if<\n" " std::is_convertible{}>::type* = nullptr>\n" "void foo(U x);\n")); + ASSERT_EQUALS("", errout_str()); ASSERT_NO_THROW(tokenizeAndStringify( "template\n" "T f(const T a, const T b) {\n" " return a < b ? b : a;\n" "}\n")); + ASSERT_EQUALS("", errout_str()); ASSERT_NO_THROW(tokenizeAndStringify( "template\n" @@ -7120,6 +7181,7 @@ class TestTokenizer : public TestFixture { " return a < b ? b : a;\n" " }\n" "};\n")); + ASSERT_EQUALS("", errout_str()); ASSERT_NO_THROW(tokenizeAndStringify( "const int a = 1;\n" @@ -7128,21 +7190,25 @@ class TestTokenizer : public TestFixture { "struct A {\n" " int x = a < b ? b : a;" "};\n")); + ASSERT_EQUALS("", errout_str()); // #10139 ASSERT_NO_THROW(tokenizeAndStringify("template\n" "void foo(std::enable_if_t>* = 0) {}\n")); + ASSERT_EQUALS("", errout_str()); // #10001 ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" " int c;\n" " template void d(b e) const { c < e ? c : e; }\n" "};\n")); + ASSERT_EQUALS("", errout_str()); ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" " int c;\n" " template void d(b e) const { c > e ? c : e; }\n" "};\n")); + ASSERT_EQUALS("", errout_str()); } void checkTemplates() { @@ -7355,6 +7421,8 @@ class TestTokenizer : public TestFixture { "using b = c;\n" "template <> struct d : d {};\n" "template <> struct d<> : d {};\n")); + + ignore_errout(); } void checkNamespaces() { @@ -7449,6 +7517,7 @@ class TestTokenizer : public TestFixture { "int main() { \n" " takesFunc([func = [](S s) { return s.c; }] {});\n" "}\n")); + ignore_errout(); } void checkIfCppCast() { ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" @@ -7514,7 +7583,7 @@ class TestTokenizer : public TestFixture { " if (0) {}\n" " return 0;\n" "};\n")); - + ignore_errout(); } void checkConditionBlock() { @@ -7529,6 +7598,7 @@ class TestTokenizer : public TestFixture { " const auto &bias = GEMM_CTX_ARG_STORAGE(bias);\n" " auto &c = GEMM_CTX_ARG_STORAGE(c);\n" "}\n")); + ignore_errout(); // we do not care about the output } void checkRequires() @@ -7560,6 +7630,7 @@ class TestTokenizer : public TestFixture { "template <> d::d(const int &, a::b, double, double);\n" "template <> d::d(const d &) {}\n" "template <> d::d(const d &) {}\n")); + ignore_errout(); // we do not care about the output } void noCrash3() { @@ -7888,6 +7959,7 @@ class TestTokenizer : public TestFixture { ASSERT_NO_THROW(tokenizeAndStringify("template struct X {};\n" // don't crash "template auto f(T t) -> X {}\n")); + ASSERT_EQUALS("[test.cpp:2]: (debug) auto token with no type.\n", errout_str()); #undef testIsCpp11init } };