From 1417ebacdde076f5a2ffaa227593708faa807553 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 11 Oct 2021 10:47:31 +0200 Subject: [PATCH 01/18] ASSERT() on calls to Tokenizer::tokenize() in test code --- test/test64bit.cpp | 2 +- test/testassert.cpp | 2 +- test/testastutils.cpp | 16 +++--- test/testautovariables.cpp | 2 +- test/testbool.cpp | 2 +- test/testboost.cpp | 2 +- test/testbufferoverrun.cpp | 6 +-- test/testcharvar.cpp | 2 +- test/testclass.cpp | 38 +++++++------- test/testcondition.cpp | 2 +- test/testconstructors.cpp | 4 +- test/testexceptionsafety.cpp | 2 +- test/testexprengine.cpp | 8 +-- test/testfunctions.cpp | 2 +- test/testgarbage.cpp | 12 ++--- test/testinternal.cpp | 2 +- test/testio.cpp | 2 +- test/testleakautovar.cpp | 8 +-- test/testlibrary.cpp | 8 +-- test/testmemleak.cpp | 12 ++--- test/testnullpointer.cpp | 4 +- test/testother.cpp | 4 +- test/testpostfixoperator.cpp | 2 +- test/testsimplifytemplate.cpp | 4 +- test/testsimplifytokens.cpp | 32 ++++++------ test/testsimplifytypedef.cpp | 4 +- test/testsimplifyusing.cpp | 2 +- test/testsizeof.cpp | 2 +- test/teststl.cpp | 7 ++- test/teststring.cpp | 2 +- test/testsummaries.cpp | 2 +- test/testsymboldatabase.cpp | 7 ++- test/testtoken.cpp | 2 +- test/testtokenize.cpp | 98 +++++++++++++++++------------------ test/testtokenrange.cpp | 2 +- test/testtype.cpp | 2 +- test/testuninitvar.cpp | 6 +-- test/testunusedfunctions.cpp | 2 +- test/testunusedvar.cpp | 2 +- test/testvaarg.cpp | 2 +- test/testvalueflow.cpp | 32 ++++++------ test/testvarid.cpp | 6 +-- 42 files changed, 181 insertions(+), 179 deletions(-) diff --git a/test/test64bit.cpp b/test/test64bit.cpp index 1f8acd0eb46..68cf774fb97 100644 --- a/test/test64bit.cpp +++ b/test/test64bit.cpp @@ -50,7 +50,7 @@ class Test64BitPortability : public TestFixture { Tokenizer tokenizer(&settings, this); LOAD_LIB_2(settings.library, "std.cfg"); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check char variable usage.. Check64BitPortability check64BitPortability(&tokenizer, &settings, this); diff --git a/test/testassert.cpp b/test/testassert.cpp index 759f8985875..8ba386ebadb 100644 --- a/test/testassert.cpp +++ b/test/testassert.cpp @@ -37,7 +37,7 @@ class TestAssert : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)); // Check.. CheckAssert checkAssert; diff --git a/test/testastutils.cpp b/test/testastutils.cpp index 5bb57fb2fee..a57da2a6d88 100644 --- a/test/testastutils.cpp +++ b/test/testastutils.cpp @@ -48,7 +48,7 @@ class TestAstUtils : public TestFixture { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; const Token * const tokEnd = ::findLambdaEndToken(tokenizer.tokens()); return tokEnd && tokEnd->next() == nullptr; } @@ -81,7 +81,7 @@ class TestAstUtils : public TestFixture { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; const Token * const tokStart = ::findLambdaStartToken(tokenizer.list.back()); return tokStart && tokStart == tokenizer.list.front(); } @@ -113,7 +113,7 @@ class TestAstUtils : public TestFixture { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; return ::isNullOperand(tokenizer.tokens()); } @@ -134,7 +134,7 @@ class TestAstUtils : public TestFixture { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; const Token * const tok = (offset < 0) ? tokenizer.list.back()->tokAt(1+offset) : tokenizer.tokens()->tokAt(offset); @@ -165,7 +165,7 @@ class TestAstUtils : public TestFixture { Library library; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; tokenizer.simplifyTokens1(""); const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), tokStr1, strlen(tokStr1)); const Token * const tok2 = Token::findsimplematch(tok1->next(), tokStr2, strlen(tokStr2)); @@ -203,7 +203,7 @@ class TestAstUtils : public TestFixture { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), startPattern, strlen(startPattern)); const Token * const tok2 = Token::findsimplematch(tokenizer.tokens(), endPattern, strlen(endPattern)); return ::isVariableChanged(tok1,tok2,1,false,&settings,true); @@ -225,7 +225,7 @@ class TestAstUtils : public TestFixture { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; const Token * const argtok = Token::findmatch(tokenizer.tokens(), pattern); return ::isVariableChangedByFunctionCall(argtok, 0, &settings, inconclusive); } @@ -247,7 +247,7 @@ class TestAstUtils : public TestFixture { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; const Token * tok = Token::findsimplematch(tokenizer.tokens(), parentPattern, strlen(parentPattern)); return Token::simpleMatch(::nextAfterAstRightmostLeaf(tok), rightPattern, strlen(rightPattern)); } diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index bf6b6d3118f..e5eb43edfb6 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -39,7 +39,7 @@ class TestAutoVariables : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)); CheckAutoVariables checkAutoVariables; checkAutoVariables.runChecks(&tokenizer, &settings, this); diff --git a/test/testbool.cpp b/test/testbool.cpp index c93054593e5..b8246aeb7a9 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -84,7 +84,7 @@ class TestBool : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)); // Check... CheckBool checkBool(&tokenizer, &settings, this); diff --git a/test/testboost.cpp b/test/testboost.cpp index 27133893579..187bb4789c2 100644 --- a/test/testboost.cpp +++ b/test/testboost.cpp @@ -44,7 +44,7 @@ class TestBoost : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckBoost checkBoost; diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 1a1e8aaf00a..cf9bb5a066d 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -47,7 +47,7 @@ class TestBufferOverrun : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)); // Check for buffer overruns.. CheckBufferOverrun checkBufferOverrun; @@ -57,7 +57,7 @@ class TestBufferOverrun : public TestFixture { void check(const char code[], const Settings &settings, const char filename[] = "test.cpp") { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)); // Clear the error buffer.. errout.str(""); @@ -4447,7 +4447,7 @@ class TestBufferOverrun : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); CTU::FileInfo *ctu = CTU::getFileInfo(&tokenizer); diff --git a/test/testcharvar.cpp b/test/testcharvar.cpp index 4f4a4fe5c72..e0b307ca995 100644 --- a/test/testcharvar.cpp +++ b/test/testcharvar.cpp @@ -48,7 +48,7 @@ class TestCharVar : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check char variable usage.. CheckOther checkOther(&tokenizer, &settings, this); diff --git a/test/testclass.cpp b/test/testclass.cpp index f53cfcb3e22..c924b614fa7 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -237,7 +237,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckClass checkClass(&tokenizer, &settings, this); @@ -340,7 +340,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckClass checkClass(&tokenizer, &settings0, this); @@ -449,7 +449,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckClass checkClass(&tokenizer, &settings1, this); @@ -603,7 +603,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckClass checkClass(&tokenizer, &settings0, this); @@ -1034,7 +1034,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckClass checkClass(&tokenizer, &settings0, this); @@ -1497,7 +1497,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckClass checkClass(&tokenizer, &settings1, this); @@ -2458,7 +2458,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckClass checkClass(&tokenizer, &settings0, this); @@ -2756,7 +2756,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckClass checkClass(&tokenizer, &settings, this); @@ -3346,7 +3346,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckClass checkClass(&tokenizer, &settings1, this); @@ -3383,7 +3383,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(s, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); CheckClass checkClass(&tokenizer, s, this); checkClass.checkConst(); @@ -6569,7 +6569,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); CheckClass checkClass(&tokenizer, &settings0, this); checkClass.initializerListOrder(); @@ -6604,7 +6604,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); CheckClass checkClass(&tokenizer, &settings, this); checkClass.initializationListUsage(); @@ -6815,7 +6815,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); CheckClass checkClass(&tokenizer, &settings0, this); checkClass.checkSelfInitialization(); @@ -6916,7 +6916,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(s, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); CheckClass checkClass(&tokenizer, s, this); checkClass.checkVirtualFunctionCallInConstructor(); @@ -7173,7 +7173,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckClass checkClass(&tokenizer, &settings, this); @@ -7256,7 +7256,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckClass checkClass(&tokenizer, &settings, this); @@ -7275,7 +7275,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckClass checkClass(&tokenizer, &settings1, this); @@ -7432,7 +7432,7 @@ class TestClass : public TestFixture { for (const std::string& c: code) { Tokenizer tokenizer(&settings, this); std::istringstream istr(c); - tokenizer.tokenize(istr, (std::to_string(fileInfo.size()) + ".cpp").c_str()); + ASSERT(tokenizer.tokenize(istr, (std::to_string(fileInfo.size()) + ".cpp").c_str())); fileInfo.push_back(check.getFileInfo(&tokenizer, &settings)); } @@ -7470,7 +7470,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckClass checkClass(&tokenizer, &settings1, this); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 2ef5055befa..5face980eb8 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -539,7 +539,7 @@ class TestCondition : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); CheckCondition checkCondition; checkCondition.runChecks(&tokenizer, &settings1, this); diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 7b10120edf5..d54e44f98b8 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -39,7 +39,7 @@ class TestConstructors : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check class constructors.. CheckClass checkClass(&tokenizer, &settings, this); @@ -53,7 +53,7 @@ class TestConstructors : public TestFixture { // Tokenize.. Tokenizer tokenizer(&s, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check class constructors.. CheckClass checkClass(&tokenizer, &s, this); diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index 3a28021ccbc..cadefb10075 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -64,7 +64,7 @@ class TestExceptionSafety : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check char variable usage.. CheckExceptionSafety checkExceptionSafety(&tokenizer, &settings, this); diff --git a/test/testexprengine.cpp b/test/testexprengine.cpp index b3cd8e55d7e..0a3bb36bb47 100644 --- a/test/testexprengine.cpp +++ b/test/testexprengine.cpp @@ -180,7 +180,7 @@ class TestExprEngine : public TestFixture { settings.platform(cppcheck::Platform::Unix64); Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; std::string ret; ExprEngine::Callback f = [&](const Token *tok, const ExprEngine::Value &value, ExprEngine::DataBase *dataBase) { if (tok->str() != binop) @@ -205,7 +205,7 @@ class TestExprEngine : public TestFixture { settings.platform(cppcheck::Platform::Unix64); Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; std::vector callbacks; std::ostringstream trace; ExprEngine::executeAllFunctions(this, &tokenizer, &settings, callbacks, trace); @@ -223,7 +223,7 @@ class TestExprEngine : public TestFixture { settings.library.smartPointers["std::shared_ptr"]; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; std::string ret; ExprEngine::Callback f = [&](const Token *tok, const ExprEngine::Value &value, ExprEngine::DataBase *dataBase) { (void)dataBase; @@ -250,7 +250,7 @@ class TestExprEngine : public TestFixture { settings->library.smartPointers["std::shared_ptr"]; Tokenizer tokenizer(settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; std::vector callbacks; std::ostringstream ret; ExprEngine::executeAllFunctions(this, &tokenizer, settings, callbacks, ret); diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index eae1509258b..68c939de8fc 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -105,7 +105,7 @@ class TestFunctions : public TestFixture { // Tokenize.. Tokenizer tokenizer(settings_, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)); CheckFunctions checkFunctions(&tokenizer, settings_, this); checkFunctions.runChecks(&tokenizer, settings_, this); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index fcb03e0a268..939d04b874b 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -277,7 +277,7 @@ class TestGarbage : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)) false; // call all "runChecks" in all registered Check classes for (std::list::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { @@ -291,7 +291,7 @@ class TestGarbage : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); try { - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; } catch (InternalError& e) { if (e.id != "syntaxError") return ""; @@ -308,7 +308,7 @@ class TestGarbage : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS("", errout.str()); } } @@ -356,7 +356,7 @@ class TestGarbage : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); try { - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); assertThrowFail(__FILE__, __LINE__); } catch (InternalError& e) { ASSERT_EQUALS("syntax error", e.errorMessage); @@ -390,14 +390,14 @@ class TestGarbage : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.c"); + ASSERT(tokenizer.tokenize(istr, "test.c")); ASSERT_EQUALS("", errout.str()); } { errout.str(""); Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS("[test.cpp:1]: (information) The code 'class x y {' is not handled. You can use -I or --include to add handling of this code.\n", errout.str()); } } diff --git a/test/testinternal.cpp b/test/testinternal.cpp index 5200334fc83..cc8c3346ce3 100644 --- a/test/testinternal.cpp +++ b/test/testinternal.cpp @@ -53,7 +53,7 @@ class TestInternal : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckInternal checkInternal; diff --git a/test/testio.cpp b/test/testio.cpp index e13e50d382c..31e7a0e37b6 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -92,7 +92,7 @@ class TestIO : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckIO checkIO(&tokenizer, &settings, this); diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 5be1e1f74e3..58f6930194c 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -208,7 +208,7 @@ class TestLeakAutoVar : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, cpp?"test.cpp":"test.c"); + ASSERT(tokenizer.tokenize(istr, cpp ? "test.cpp" : "test.c")); // Check for leaks.. CheckLeakAutoVar c; @@ -224,7 +224,7 @@ class TestLeakAutoVar : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings_, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check for leaks.. CheckLeakAutoVar c; @@ -2314,7 +2314,7 @@ class TestLeakAutoVarStrcpy : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check for leaks.. CheckLeakAutoVar checkLeak; @@ -2364,7 +2364,7 @@ class TestLeakAutoVarWindows : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.c"); + ASSERT(tokenizer.tokenize(istr, "test.c")); // Check for leaks.. CheckLeakAutoVar checkLeak; diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index add484834c0..da3c44ef12a 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -554,14 +554,14 @@ class TestLibrary : public TestFixture { { Tokenizer tokenizer(&settings, nullptr); std::istringstream istr("CString str; str.Format();"); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format"))); } { Tokenizer tokenizer(&settings, nullptr); std::istringstream istr("HardDrive hd; hd.Format();"); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(!library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format"))); } } @@ -580,14 +580,14 @@ class TestLibrary : public TestFixture { { Tokenizer tokenizer(&settings, nullptr); std::istringstream istr("struct X : public Base { void dostuff() { f(0); } };"); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1)); } { Tokenizer tokenizer(&settings, nullptr); std::istringstream istr("struct X : public Base { void dostuff() { f(1,2); } };"); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(!library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1)); } } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index fabb168c189..1ffea91ddd4 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -46,7 +46,7 @@ class TestMemleak : private TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; const CheckMemoryLeak c(&tokenizer, this, &settings); @@ -98,7 +98,7 @@ class TestMemleak : private TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // there is no allocation const Token *tok = Token::findsimplematch(tokenizer.tokens(), "ret ="); @@ -131,7 +131,7 @@ class TestMemleakInFunction : public TestFixture { // Tokenize.. Tokenizer tokenizer(settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check for memory leaks.. CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, settings, this); @@ -474,7 +474,7 @@ class TestMemleakInClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check for memory leaks.. CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this); @@ -1646,7 +1646,7 @@ class TestMemleakStructMember : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, isCPP ? "test.cpp" : "test.c"); + ASSERT(tokenizer.tokenize(istr, isCPP ? "test.cpp" : "test.c")); // Check for memory leaks.. CheckMemoryLeakStructMember checkMemoryLeakStructMember(&tokenizer, &settings, this); @@ -2127,7 +2127,7 @@ class TestMemleakNoVar : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check for memory leaks.. CheckMemoryLeakNoVar checkMemoryLeakNoVar(&tokenizer, &settings, this); diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 299eb06fc98..4d4df2a5192 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -3593,7 +3593,7 @@ class TestNullPointer : public TestFixture { Settings settings1; Tokenizer tokenizer(&settings1,this); std::istringstream code("void f() { int a,b,c; x(a,b,c); }"); - tokenizer.tokenize(code,"test.c"); + ASSERT(tokenizer.tokenize(code, "test.c")); const Token *xtok = Token::findsimplematch(tokenizer.tokens(), "x"); // nothing bad.. @@ -3922,7 +3922,7 @@ class TestNullPointer : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); CTU::FileInfo *ctu = CTU::getFileInfo(&tokenizer); diff --git a/test/testother.cpp b/test/testother.cpp index 44406a9c3ea..1f2f55ccf74 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -279,7 +279,7 @@ class TestOther : public TestFixture { // Tokenize.. Tokenizer tokenizer(settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename ? filename : "test.cpp"); + ASSERT(tokenizer.tokenize(istr, filename ? filename : "test.cpp")); // Check.. CheckOther checkOther(&tokenizer, settings, this); @@ -1454,7 +1454,7 @@ class TestOther : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); CheckOther checkOtherCpp(&tokenizer, &settings, this); checkOtherCpp.invalidPointerCast(); diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index 5533f4f25a6..e443501621b 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -38,7 +38,7 @@ class TestPostfixOperator : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check for postfix operators.. CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index e11d3a3b616..ae4606b0f84 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -309,7 +309,7 @@ class TestSimplifyTemplate : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; return tokenizer.tokens()->stringifyList(nullptr, true); } @@ -5584,7 +5584,7 @@ class TestSimplifyTemplate : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp", ""); + ASSERT(tokenizer.tokenize(istr, "test.cpp", "")) false; return TemplateSimplifier::instantiateMatch(tokenizer.tokens(), numberOfArguments, false, patternAfter); } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index dede4b01f14..8b98667f5c7 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -377,7 +377,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; if (simplify) tokenizer.simplifyTokenList2(); @@ -392,7 +392,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings_windows, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; if (simplify) tokenizer.simplifyTokenList2(); @@ -406,7 +406,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)) {}; if (simplify) tokenizer.simplifyTokenList2(); @@ -419,7 +419,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; tokenizer.simplifyTokenList2(); return tokenizer.tokens()->stringifyList(false, false, false, true, false); @@ -431,7 +431,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings_std, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; tokenizer.simplifyTokenList2(); return tokenizer.tokens()->stringifyList(nullptr, false); @@ -447,7 +447,7 @@ class TestSimplifyTokens : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)) {}; if (simplify) tokenizer.simplifyTokenList2(); @@ -472,7 +472,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)) {}; if (simplify) tokenizer.simplifyTokenList2(); @@ -1999,7 +1999,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); } @@ -2011,7 +2011,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); } @@ -2023,7 +2023,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); } @@ -2035,7 +2035,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); } @@ -2047,7 +2047,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); } @@ -3106,7 +3106,7 @@ class TestSimplifyTokens : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; tokenizer.simplifyIfAndWhileAssign(); @@ -3195,7 +3195,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr("{ while (!(m = q->push(x))) {} }"); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); tokenizer.simplifyTokenList2(); ASSERT_EQUALS("{ m = q . push < Message > ( x ) ; while ( ! m ) { m = q . push < Message > ( x ) ; } }", tokenizer.tokens()->stringifyList(nullptr, false)); @@ -4445,7 +4445,7 @@ class TestSimplifyTokens : public TestFixture { void duplicateDefinition() { // #3565 - wrongly detects duplicate definition Tokenizer tokenizer(&settings0, this); std::istringstream istr("{ x ; return a not_eq x; }"); - tokenizer.tokenize(istr, "test.c"); + ASSERT(tokenizer.tokenize(istr, "test.c")); Token *x_token = tokenizer.list.front()->tokAt(5); ASSERT_EQUALS(false, tokenizer.duplicateDefinition(&x_token)); } @@ -5239,7 +5239,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; tokenizer.simplifyKnownVariables(); diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index cfbac96faa9..d7302019227 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -207,7 +207,7 @@ class TestSimplifyTypedef : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; return tokenizer.tokens()->stringifyList(nullptr, !simplify); } @@ -257,7 +257,7 @@ class TestSimplifyTypedef : public TestFixture { settings2.debugwarnings = true; // show warnings about unhandled typedef Tokenizer tokenizer(&settings2, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); } diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 78a78fef756..b76489eacfd 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -104,7 +104,7 @@ class TestSimplifyUsing : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; return tokenizer.tokens()->stringifyList(nullptr); } diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index 6b4a8d204fc..908d22185b7 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -57,7 +57,7 @@ class TestSizeof : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check... CheckSizeof checkSizeof(&tokenizer, &settings, this); diff --git a/test/teststl.cpp b/test/teststl.cpp index 261a10c7828..febfc688ed6 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -187,7 +187,7 @@ class TestStl : public TestFixture { CheckStl checkStl(&tokenizer, &settings, this); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); checkStl.runChecks(&tokenizer, &settings, this); } @@ -202,11 +202,14 @@ class TestStl : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + if (!tokenizer.tokenize(istr, "test.cpp")) + errout << "Tokenizer failed!"; // Check.. CheckStl checkStl(&tokenizer, &settings, this); checkStl.runChecks(&tokenizer, &settings, this); + if (!tokenizer.list.isCPP()) + errout << "Check failed, language must be CPP!"; } void outOfBounds() { diff --git a/test/teststring.cpp b/test/teststring.cpp index 32a8c67f024..02e3191ac1b 100644 --- a/test/teststring.cpp +++ b/test/teststring.cpp @@ -67,7 +67,7 @@ class TestString : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)); // Check char variable usage.. CheckString checkString(&tokenizer, &settings, this); diff --git a/test/testsummaries.cpp b/test/testsummaries.cpp index f2a9ef2aecb..70b00133828 100644 --- a/test/testsummaries.cpp +++ b/test/testsummaries.cpp @@ -44,7 +44,7 @@ class TestSummaries : public TestFixture { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)) {}; return Summaries::create(&tokenizer, ""); } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index cf0b4f225c1..51e1776f4e5 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -82,8 +82,7 @@ class TestSymbolDatabase : public TestFixture { const static SymbolDatabase* getSymbolDB_inner(Tokenizer& tokenizer, const char* code, const char* filename) { errout.str(""); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); - return tokenizer.getSymbolDatabase(); + return tokenizer.tokenize(istr, filename) ? tokenizer.getSymbolDatabase() : nullptr; } static const Scope *findFunctionScopeByToken(const SymbolDatabase * db, const Token *tok) { @@ -2143,7 +2142,7 @@ class TestSymbolDatabase : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)); // force symbol database creation tokenizer.createSymbolDatabase(); @@ -7119,7 +7118,7 @@ class TestSymbolDatabase : public TestFixture { std::string typeOf(const char code[], const char pattern[], const char filename[] = "test.cpp", const Settings *settings = nullptr) { Tokenizer tokenizer(settings ? settings : &settings2, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)) {}; const Token* tok; for (tok = tokenizer.list.back(); tok; tok = tok->previous()) if (Token::simpleMatch(tok, pattern, strlen(pattern))) diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 35a236ddf73..b7206044f98 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -137,7 +137,7 @@ class TestToken : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(";" + code + ";"); try { - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; } catch (...) {} return Token::Match(tokenizer.tokens()->next(), pattern.c_str(), varid); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 535b2c54dbd..ae6c3e55ac8 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -452,7 +452,7 @@ class TestTokenizer : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)) {}; // filter out ValueFlow messages.. const std::string debugwarnings = errout.str(); @@ -480,7 +480,7 @@ class TestTokenizer : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings_windows, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)) {}; // filter out ValueFlow messages.. const std::string debugwarnings = errout.str(); @@ -504,7 +504,7 @@ class TestTokenizer : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)) {}; if (!tokenizer.tokens()) return ""; return tokenizer.tokens()->stringifyList(false, true, false, true, false, nullptr, nullptr); @@ -518,7 +518,7 @@ class TestTokenizer : public TestFixture { Tokenizer tokenizer(&settings2, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)) {}; // result.. return tokenizer.tokens()->stringifyList(true,true,true,true,false); @@ -2806,7 +2806,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); // A body {} ASSERT_EQUALS(true, tok->linkAt(2) == tok->tokAt(9)); @@ -2831,7 +2831,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); // a[10] ASSERT_EQUALS(true, tok->linkAt(7) == tok->tokAt(9)); @@ -2855,7 +2855,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); // foo( ASSERT_EQUALS(true, tok->linkAt(6) == tok->tokAt(10)); @@ -2875,7 +2875,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); // template< ASSERT_EQUALS(true, tok->tokAt(6) == tok->linkAt(4)); @@ -2903,7 +2903,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); // static_cast< @@ -2920,7 +2920,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); // nvwa<(x > y)> @@ -2936,7 +2936,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); // B<..> @@ -2952,7 +2952,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->tokAt(1) == tok->linkAt(18)); @@ -2969,7 +2969,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->tokAt(2) == tok->linkAt(4)); @@ -2985,7 +2985,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->tokAt(3) == tok->linkAt(9)); @@ -3000,7 +3000,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(3) == nullptr); @@ -3012,7 +3012,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(4) == nullptr); @@ -3024,7 +3024,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(5)); @@ -3036,7 +3036,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(3) == nullptr); @@ -3048,7 +3048,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(7)); } @@ -3059,7 +3059,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(7)); } @@ -3069,7 +3069,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(7)); ASSERT_EQUALS(true, tok->tokAt(1) == tok->linkAt(7)); @@ -3080,7 +3080,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(4) == tok->tokAt(8)); ASSERT_EQUALS(true, tok->tokAt(4) == tok->linkAt(8)); @@ -3091,7 +3091,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(4)); ASSERT_EQUALS(true, tok->tokAt(1) == tok->linkAt(4)); @@ -3103,7 +3103,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = tokenizer.tokens(); ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(4)); // @@ -3123,7 +3123,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok = Token::findsimplematch(tokenizer.tokens(), "<"); ASSERT_EQUALS(true, tok->link() == tok->tokAt(4)); ASSERT_EQUALS(true, tok->linkAt(4) == tok); @@ -3137,7 +3137,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "struct")->tokAt(2); const Token *tok2 = Token::findsimplematch(tokenizer.tokens(), "{")->previous(); ASSERT_EQUALS(true, tok1->link() == tok2); @@ -3150,7 +3150,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "< Y"); const Token *tok2 = Token::findsimplematch(tok1, "> copy"); ASSERT_EQUALS(true, tok1->link() == tok2); @@ -3163,7 +3163,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok1 = tokenizer.tokens()->next(); const Token *tok2 = tok1->tokAt(2); ASSERT_EQUALS(true, tok1->link() == tok2); @@ -3176,7 +3176,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "<"); const Token *tok2 = tok1->tokAt(2); ASSERT_EQUALS(true, tok1->link() == tok2); @@ -3189,7 +3189,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *A = Token::findsimplematch(tokenizer.tokens(), "A <"); ASSERT_EQUALS(true, A->next()->link() == A->tokAt(3)); } @@ -3200,7 +3200,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(true, Token::simpleMatch(tokenizer.tokens()->next()->link(), "> void")); } @@ -3209,7 +3209,7 @@ class TestTokenizer : public TestFixture { const char code[] = "a = f(x%x<--a==x>x);"; Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(nullptr == Token::findsimplematch(tokenizer.tokens(), "<")->link()); } @@ -3218,7 +3218,7 @@ class TestTokenizer : public TestFixture { const char code[] = "using std::list; list l;"; Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "<")->link()); } @@ -3230,7 +3230,7 @@ class TestTokenizer : public TestFixture { "}"; Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "<")->link()); } @@ -3242,7 +3242,7 @@ class TestTokenizer : public TestFixture { "}\n"; Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ::")->link()); } @@ -3254,7 +3254,7 @@ class TestTokenizer : public TestFixture { "};\n"; Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> [")->link()); } @@ -3267,7 +3267,7 @@ class TestTokenizer : public TestFixture { "template using baz = g;\n"; Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ;")->link()); } @@ -3282,7 +3282,7 @@ class TestTokenizer : public TestFixture { "auto f = -e<1> == 0;\n"; Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ==")->link()); } @@ -3301,7 +3301,7 @@ class TestTokenizer : public TestFixture { "}\n"; Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> . f (")->link()); } } @@ -3533,7 +3533,7 @@ class TestTokenizer : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Expected result.. ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); @@ -3560,7 +3560,7 @@ class TestTokenizer : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); const Token * VAS_Fail = Token::findsimplematch(tokenizer.tokens(), "VAS_Fail"); @@ -3580,7 +3580,7 @@ class TestTokenizer : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Expected result.. ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); @@ -3615,7 +3615,7 @@ class TestTokenizer : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Expected result.. ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); @@ -3656,7 +3656,7 @@ class TestTokenizer : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Expected result.. ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false)); @@ -4301,7 +4301,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token *x = Token::findsimplematch(tokenizer.tokens(), "x"); ASSERT_EQUALS(1, x->bits()); } @@ -6328,7 +6328,7 @@ class TestTokenizer : public TestFixture { bool isStartOfExecutableScope(int offset, const char code[]) { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; return Tokenizer::startOfExecutableScope(tokenizer.tokens()->tokAt(offset)) != nullptr; } @@ -6857,7 +6857,7 @@ class TestTokenizer : public TestFixture { // tokenize.. Tokenizer tokenizer(&s, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); } void checkConfiguration() { @@ -6881,7 +6881,7 @@ class TestTokenizer : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); tokenizer.printUnknownTypes(); @@ -6901,7 +6901,7 @@ class TestTokenizer : public TestFixture { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { ASSERT_EQUALS(tok->str() == "(", tok->isCast()); diff --git a/test/testtokenrange.cpp b/test/testtokenrange.cpp index 9c5f0d5e75e..6286999d7e8 100644 --- a/test/testtokenrange.cpp +++ b/test/testtokenrange.cpp @@ -104,7 +104,7 @@ class TestTokenRange : public TestFixture { Settings settings; Tokenizer tokenizer{ &settings, nullptr }; std::istringstream sample("void a(){} void main(){ if(true){a();} }"); - tokenizer.tokenize(sample, "test.cpp"); + ASSERT(tokenizer.tokenize(sample, "test.cpp")); const SymbolDatabase* sd = tokenizer.getSymbolDatabase(); const Scope& scope = *std::next(sd->scopeList.begin(), 3); //The scope of the if block diff --git a/test/testtype.cpp b/test/testtype.cpp index f80ec8a8a76..b1ae1e20c83 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -55,7 +55,7 @@ class TestType : public TestFixture { // Tokenize.. Tokenizer tokenizer(settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)); // Check.. CheckType checkType(&tokenizer, settings, this); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index b93add16f87..136bb6a74d0 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -104,7 +104,7 @@ class TestUninitVar : public TestFixture { settings.debugwarnings = debugwarnings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, fname); + ASSERT(tokenizer.tokenize(istr, fname)); // Check for redundant code.. CheckUninitVar checkuninitvar(&tokenizer, &settings, this); @@ -4380,7 +4380,7 @@ class TestUninitVar : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check for redundant code.. CheckUninitVar checkuninitvar(&tokenizer, &settings, this); @@ -5190,7 +5190,7 @@ class TestUninitVar : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); CTU::FileInfo *ctu = CTU::getFileInfo(&tokenizer); diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index 6fab7fd098c..dbe3e6ef47d 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -75,7 +75,7 @@ class TestUnusedFunctions : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check for unused functions.. CheckUnusedFunctions checkUnusedFunctions(&tokenizer, &settings, this); diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 9a66aa984e5..9bbb0597f9f 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -235,7 +235,7 @@ class TestUnusedVar : public TestFixture { Tokenizer tokenizer(&settings, this); tokenizer.setPreprocessor(&preprocessor); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check for unused variables.. CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this); diff --git a/test/testvaarg.cpp b/test/testvaarg.cpp index 1a720142b3c..7ebe652920a 100644 --- a/test/testvaarg.cpp +++ b/test/testvaarg.cpp @@ -37,7 +37,7 @@ class TestVaarg : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckVaarg checkVaarg; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index f8d417c9449..19bf561f6c0 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -178,7 +178,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -198,7 +198,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; for (const Token* tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -218,7 +218,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -239,7 +239,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; for (const Token* tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -259,7 +259,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -279,7 +279,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -298,7 +298,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; for (const Token* tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -317,7 +317,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -336,7 +336,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() != "x" || tok->linenr() != linenr) @@ -360,7 +360,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -378,7 +378,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -396,7 +396,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -414,7 +414,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -432,7 +432,7 @@ class TestValueFlow : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -470,7 +470,7 @@ class TestValueFlow : public TestFixture { Tokenizer tokenizer(s ? s : &settings, this); std::istringstream istr(code); errout.str(""); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; const Token *tok = Token::findmatch(tokenizer.tokens(), tokstr); return tok ? tok->values() : std::list(); } @@ -488,7 +488,7 @@ class TestValueFlow : public TestFixture { Tokenizer tokenizer(s ? s : &settings, this); std::istringstream istr(code); errout.str(""); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; const Token *tok = Token::findmatch(tokenizer.tokens(), tokstr); if (!tok) return result; diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 27674402fd4..ee842f4273a 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -230,7 +230,7 @@ class TestVarID : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)) {}; // result.. Token::stringifyOptions options = Token::stringifyOptions::forDebugVarId(); @@ -249,7 +249,7 @@ class TestVarID : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)) {}; // result.. Token::stringifyOptions options = Token::stringifyOptions::forDebugExprId(); @@ -268,7 +268,7 @@ class TestVarID : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, filename); + ASSERT(tokenizer.tokenize(istr, filename)) {}; unsigned int varid = ~0U; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { From fecec1761de5a4909fd2d6087ce8a5e8f765ae77 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 11 Oct 2021 11:00:02 +0200 Subject: [PATCH 02/18] Fix return type --- test/testexprengine.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/testexprengine.cpp b/test/testexprengine.cpp index 0a3bb36bb47..e7b830adbec 100644 --- a/test/testexprengine.cpp +++ b/test/testexprengine.cpp @@ -180,7 +180,7 @@ class TestExprEngine : public TestFixture { settings.platform(cppcheck::Platform::Unix64); Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; std::string ret; ExprEngine::Callback f = [&](const Token *tok, const ExprEngine::Value &value, ExprEngine::DataBase *dataBase) { if (tok->str() != binop) @@ -223,7 +223,7 @@ class TestExprEngine : public TestFixture { settings.library.smartPointers["std::shared_ptr"]; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; std::string ret; ExprEngine::Callback f = [&](const Token *tok, const ExprEngine::Value &value, ExprEngine::DataBase *dataBase) { (void)dataBase; @@ -250,7 +250,7 @@ class TestExprEngine : public TestFixture { settings->library.smartPointers["std::shared_ptr"]; Tokenizer tokenizer(settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; std::vector callbacks; std::ostringstream ret; ExprEngine::executeAllFunctions(this, &tokenizer, settings, callbacks, ret); From 2d3dfebdc529ab4a59eb5e884e7d72f790dfbc6c Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 11 Oct 2021 11:18:26 +0200 Subject: [PATCH 03/18] Fix return type --- test/testgarbage.cpp | 2 +- test/testsimplifytemplate.cpp | 2 +- test/testsimplifytokens.cpp | 8 ++++---- test/testsimplifyusing.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 939d04b874b..b6e7a36e8b3 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -277,7 +277,7 @@ class TestGarbage : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) false; + ASSERT(tokenizer.tokenize(istr, filename)) {}; // call all "runChecks" in all registered Check classes for (std::list::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index ae4606b0f84..3521431fe35 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -309,7 +309,7 @@ class TestSimplifyTemplate : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; return tokenizer.tokens()->stringifyList(nullptr, true); } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 8b98667f5c7..f34597ef7c2 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -392,7 +392,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings_windows, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; if (simplify) tokenizer.simplifyTokenList2(); @@ -419,7 +419,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; tokenizer.simplifyTokenList2(); return tokenizer.tokens()->stringifyList(false, false, false, true, false); @@ -431,7 +431,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings_std, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; tokenizer.simplifyTokenList2(); return tokenizer.tokens()->stringifyList(nullptr, false); @@ -5239,7 +5239,7 @@ class TestSimplifyTokens : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; tokenizer.simplifyKnownVariables(); diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index b76489eacfd..91e4933afca 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -104,7 +104,7 @@ class TestSimplifyUsing : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; return tokenizer.tokens()->stringifyList(nullptr); } From dbedbd4f1ce6db4b4b5202808006f8ee827c7cf6 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 11 Oct 2021 11:56:20 +0200 Subject: [PATCH 04/18] Missing assert --- test/teststl.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/teststl.cpp b/test/teststl.cpp index d9275736c2b..cd835be94cf 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -202,14 +202,11 @@ class TestStl : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - if (!tokenizer.tokenize(istr, "test.cpp")) - errout << "Tokenizer failed!"; + ASSERT(tokenizer.tokenize(istr, "test.cpp")); // Check.. CheckStl checkStl(&tokenizer, &settings, this); checkStl.runChecks(&tokenizer, &settings, this); - if (!tokenizer.list.isCPP()) - errout << "Check failed, language must be CPP!"; } void outOfBounds() { From e6c47bd93a96816b0a6196d9509f5f21d0e1e040 Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 26 Oct 2021 17:53:01 +0200 Subject: [PATCH 05/18] Add ASSERT_LOC() to capture file/line info --- test/test64bit.cpp | 5 +++-- test/testsuite.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test64bit.cpp b/test/test64bit.cpp index 68cf774fb97..d8ecf58bd3a 100644 --- a/test/test64bit.cpp +++ b/test/test64bit.cpp @@ -42,7 +42,8 @@ class Test64BitPortability : public TestFixture { TEST_CASE(assignment); } - void check(const char code[]) { +#define check(code) check_(code, __FILE__, __LINE__) + void check_(const char code[], const char* file, int line) { // Clear the error buffer.. errout.str(""); @@ -50,7 +51,7 @@ class Test64BitPortability : public TestFixture { Tokenizer tokenizer(&settings, this); LOAD_LIB_2(settings.library, "std.cfg"); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp")); // Check char variable usage.. Check64BitPortability check64BitPortability(&tokenizer, &settings, this); diff --git a/test/testsuite.h b/test/testsuite.h index 4e7e312d850..ad1ee0c0c4b 100644 --- a/test/testsuite.h +++ b/test/testsuite.h @@ -121,6 +121,7 @@ extern std::ostringstream output; #define TEST_CASE( NAME ) do { if (prepareTest(#NAME)) { setVerbose(false); NAME(); } } while (false) #define ASSERT( CONDITION ) if (!assert_(__FILE__, __LINE__, (CONDITION))) return +#define ASSERT_LOC( CONDITION ) if (!assert_(file, line, (CONDITION))) return #define CHECK_EQUALS( EXPECTED, ACTUAL ) assertEquals(__FILE__, __LINE__, (EXPECTED), (ACTUAL)) #define ASSERT_EQUALS( EXPECTED, ACTUAL ) if (!assertEquals(__FILE__, __LINE__, (EXPECTED), (ACTUAL))) return #define ASSERT_EQUALS_WITHOUT_LINENUMBERS( EXPECTED, ACTUAL ) assertEqualsWithoutLineNumbers(__FILE__, __LINE__, EXPECTED, ACTUAL) From b28dbb57210ecde64dc0c781af58507cf6c94bc3 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Tue, 26 Oct 2021 20:16:59 +0200 Subject: [PATCH 06/18] Fix test case --- test/testuninitvar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index b8eba2b0070..999107e52c8 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -4393,7 +4393,7 @@ class TestUninitVar : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT(tokenizer.tokenize(istr, fname)); // Check for redundant code.. CheckUninitVar checkuninitvar(&tokenizer, &settings, this); From f8174f49fc624d87372fdafe6faf480359ff9035 Mon Sep 17 00:00:00 2001 From: chrchr Date: Wed, 27 Oct 2021 09:37:17 +0200 Subject: [PATCH 07/18] Add args to ASSERT_LOC(), no return --- test/test64bit.cpp | 2 +- test/testsuite.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test64bit.cpp b/test/test64bit.cpp index d8ecf58bd3a..4e3ff768a34 100644 --- a/test/test64bit.cpp +++ b/test/test64bit.cpp @@ -51,7 +51,7 @@ class Test64BitPortability : public TestFixture { Tokenizer tokenizer(&settings, this); LOAD_LIB_2(settings.library, "std.cfg"); std::istringstream istr(code); - ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check char variable usage.. Check64BitPortability check64BitPortability(&tokenizer, &settings, this); diff --git a/test/testsuite.h b/test/testsuite.h index ad1ee0c0c4b..291aa7abf10 100644 --- a/test/testsuite.h +++ b/test/testsuite.h @@ -121,7 +121,7 @@ extern std::ostringstream output; #define TEST_CASE( NAME ) do { if (prepareTest(#NAME)) { setVerbose(false); NAME(); } } while (false) #define ASSERT( CONDITION ) if (!assert_(__FILE__, __LINE__, (CONDITION))) return -#define ASSERT_LOC( CONDITION ) if (!assert_(file, line, (CONDITION))) return +#define ASSERT_LOC( CONDITION, FILE_, LINE_ ) assert_(FILE_, LINE_, (CONDITION)) #define CHECK_EQUALS( EXPECTED, ACTUAL ) assertEquals(__FILE__, __LINE__, (EXPECTED), (ACTUAL)) #define ASSERT_EQUALS( EXPECTED, ACTUAL ) if (!assertEquals(__FILE__, __LINE__, (EXPECTED), (ACTUAL))) return #define ASSERT_EQUALS_WITHOUT_LINENUMBERS( EXPECTED, ACTUAL ) assertEqualsWithoutLineNumbers(__FILE__, __LINE__, EXPECTED, ACTUAL) From 9ea857bfe08c5f31920ed5fd54e8d5820326c8f3 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 28 Oct 2021 19:28:27 +0200 Subject: [PATCH 08/18] Add macros to capture file/line --- test/testassert.cpp | 5 +++-- test/testautovariables.cpp | 6 +++--- test/testbool.cpp | 6 +++--- test/testboost.cpp | 5 +++-- test/testunusedvar.cpp | 14 ++++++++------ test/testvaarg.cpp | 6 +++--- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/test/testassert.cpp b/test/testassert.cpp index 8ba386ebadb..537ebfdf196 100644 --- a/test/testassert.cpp +++ b/test/testassert.cpp @@ -30,14 +30,15 @@ class TestAssert : public TestFixture { private: Settings settings; - void check(const char code[], const char *filename = "test.cpp") { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], const char *filename = "test.cpp") { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)); + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); // Check.. CheckAssert checkAssert; diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index c18c65345dc..fc7d86b9fa9 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -29,8 +29,8 @@ class TestAutoVariables : public TestFixture { private: Settings settings; - - void check(const char code[], bool inconclusive = false, const char* filename = "test.cpp") { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], bool inconclusive = false, const char* filename = "test.cpp") { // Clear the error buffer.. errout.str(""); @@ -39,7 +39,7 @@ class TestAutoVariables : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)); + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); CheckAutoVariables checkAutoVariables; checkAutoVariables.runChecks(&tokenizer, &settings, this); diff --git a/test/testbool.cpp b/test/testbool.cpp index 81b4775918f..a1a5b313d39 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -74,8 +74,8 @@ class TestBool : public TestFixture { TEST_CASE(returnNonBoolLogicalOp); TEST_CASE(returnNonBoolClass); } - - void check(const char code[], bool experimental = false, const char filename[] = "test.cpp") { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], bool experimental = false, const char filename[] = "test.cpp") { // Clear the error buffer.. errout.str(""); @@ -84,7 +84,7 @@ class TestBool : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)); + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); // Check... CheckBool checkBool(&tokenizer, &settings, this); diff --git a/test/testboost.cpp b/test/testboost.cpp index 187bb4789c2..700aa3859fb 100644 --- a/test/testboost.cpp +++ b/test/testboost.cpp @@ -37,14 +37,15 @@ class TestBoost : public TestFixture { TEST_CASE(BoostForeachContainerModification); } - void check(const char code[]) { +#define check(code) check_(code, __FILE__, __LINE__) + void check_(const char code[], const char* file, int line) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckBoost checkBoost; diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index e00e2dfb888..873a84d6f7a 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -119,6 +119,7 @@ class TestUnusedVar : public TestFixture { TEST_CASE(localvar57); // #8974 - increment TEST_CASE(localvar58); // #9901 - increment false positive TEST_CASE(localvar59); // #9737 + TEST_CASE(localvar60); TEST_CASE(localvarloops); // loops TEST_CASE(localvaralias1); TEST_CASE(localvaralias2); // ticket #1637 @@ -224,7 +225,9 @@ class TestUnusedVar : public TestFixture { TEST_CASE(globalData); } - void checkStructMemberUsage(const char code[], const std::list *directives=nullptr) { +#define functionVariableUsage(...) functionVariableUsage_(__FILE__, __LINE__, __VA_ARGS__) +#define checkStructMemberUsage(...) checkStructMemberUsage_(__FILE__, __LINE__, __VA_ARGS__) + void checkStructMemberUsage_(const char* file, int line, const char code[], const std::list* directives = nullptr) { // Clear the error buffer.. errout.str(""); @@ -236,11 +239,11 @@ class TestUnusedVar : public TestFixture { Tokenizer tokenizer(&settings, this); tokenizer.setPreprocessor(&preprocessor); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check for unused variables.. CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this); - checkUnusedVar.checkStructMemberUsage(); + (checkUnusedVar.checkStructMemberUsage)(); } void isRecordTypeWithoutSideEffects() { @@ -1562,15 +1565,14 @@ class TestUnusedVar : public TestFixture { ASSERT_EQUALS("", errout.str()); } - void functionVariableUsage(const char code[], const char filename[]="test.cpp") { + void functionVariableUsage_(const char* file, int line, const char code[], const char filename[] = "test.cpp") { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - if (!tokenizer.tokenize(istr, filename)) - return; + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); // Check for unused variables.. CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this); diff --git a/test/testvaarg.cpp b/test/testvaarg.cpp index 7ebe652920a..2f09e9b634c 100644 --- a/test/testvaarg.cpp +++ b/test/testvaarg.cpp @@ -29,15 +29,15 @@ class TestVaarg : public TestFixture { private: Settings settings; - - void check(const char code[]) { +#define check(code) check_(code, __FILE__, __LINE__) + void check_(const char code[], const char* file, int line) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckVaarg checkVaarg; From fa69d3c4fcc95f8331e0f80ae4f189ea759589f0 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 28 Oct 2021 19:58:11 +0200 Subject: [PATCH 09/18] Fix test case --- test/testunusedvar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 873a84d6f7a..5d4cf94b7b6 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -2721,7 +2721,7 @@ class TestUnusedVar : public TestFixture { " int ppos = 1;\n" " int pneg = 0;\n" " const char*edge = ppos? \" +\" : pneg ? \" -\" : \"\";\n" - " printf(\"This should be a '+' -> %s\n\", edge);\n" + " printf(\"This should be a '+' -> %s\\n\", edge);\n" " return 0;\n" "}"); ASSERT_EQUALS("", errout.str()); From a7e8184e15bc5ab773bb017363cc95d37d2d8697 Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 29 Oct 2021 19:47:59 +0200 Subject: [PATCH 10/18] More ASSERT_LOC --- test/testbufferoverrun.cpp | 20 +++++++++++--------- test/testcharvar.cpp | 5 +++-- test/testcondition.cpp | 5 +++-- test/testexceptionsafety.cpp | 5 +++-- test/testfunctions.cpp | 5 +++-- test/testinternal.cpp | 5 +++-- test/testio.cpp | 5 +++-- test/testpostfixoperator.cpp | 6 +++--- test/testsizeof.cpp | 5 +++-- test/teststl.cpp | 12 +++++++----- test/teststring.cpp | 5 +++-- test/testtype.cpp | 5 +++-- test/testunusedfunctions.cpp | 9 +++++---- 13 files changed, 53 insertions(+), 39 deletions(-) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 29ed575ade6..48258b04ee3 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -38,7 +38,8 @@ class TestBufferOverrun : public TestFixture { private: Settings settings0; - void check(const char code[], const char filename[] = "test.cpp") { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], const char filename[] = "test.cpp") { // Clear the error buffer.. errout.str(""); @@ -47,17 +48,17 @@ class TestBufferOverrun : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)); + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); // Check for buffer overruns.. CheckBufferOverrun checkBufferOverrun; checkBufferOverrun.runChecks(&tokenizer, &settings0, this); } - void check(const char code[], const Settings &settings, const char filename[] = "test.cpp") { + void check_(const char* file, int line, const char code[], const Settings &settings, const char filename[] = "test.cpp") { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)); + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); // Clear the error buffer.. errout.str(""); @@ -4445,22 +4446,23 @@ class TestBufferOverrun : public TestFixture { ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'arr+20' is out of bounds.\n", errout.str()); } - void ctu(const char code[]) { +#define ctu(code) ctu_(code, __FILE__, __LINE__) + void ctu_(const char code[], const char* file, int line) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); CTU::FileInfo *ctu = CTU::getFileInfo(&tokenizer); // Check code.. std::list fileInfo; - CheckBufferOverrun check(&tokenizer, &settings0, this); - fileInfo.push_back(check.getFileInfo(&tokenizer, &settings0)); - check.analyseWholeProgram(ctu, fileInfo, settings0, *this); + CheckBufferOverrun checkBO(&tokenizer, &settings0, this); + fileInfo.push_back(checkBO.getFileInfo(&tokenizer, &settings0)); + checkBO.analyseWholeProgram(ctu, fileInfo, settings0, *this); while (!fileInfo.empty()) { delete fileInfo.back(); fileInfo.pop_back(); diff --git a/test/testcharvar.cpp b/test/testcharvar.cpp index e0b307ca995..344eccc8b0f 100644 --- a/test/testcharvar.cpp +++ b/test/testcharvar.cpp @@ -41,14 +41,15 @@ class TestCharVar : public TestFixture { TEST_CASE(bitop); } - void check(const char code[]) { +#define check(code) check_(code, __FILE__, __LINE__) + void check_(const char code[], const char* file, int line) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check char variable usage.. CheckOther checkOther(&tokenizer, &settings, this); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index b899ad463e9..d5a509bb761 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -493,6 +493,7 @@ class TestCondition : public TestFixture { ASSERT_EQUALS("",errout.str()); //correct for negative 'a' } +#define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__) void multicompare() { check("void foo(int x)\n" "{\n" @@ -532,14 +533,14 @@ class TestCondition : public TestFixture { ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str()); } - void checkPureFunction(const char code[]) { + void checkPureFunction_(const char code[], const char* file, int line) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); CheckCondition checkCondition; checkCondition.runChecks(&tokenizer, &settings1, this); diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index cadefb10075..0c76701584a 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -55,7 +55,8 @@ class TestExceptionSafety : public TestFixture { TEST_CASE(rethrowNoCurrentException3); } - void check(const char code[], bool inconclusive = false) { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], bool inconclusive = false) { // Clear the error buffer.. errout.str(""); @@ -64,7 +65,7 @@ class TestExceptionSafety : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check char variable usage.. CheckExceptionSafety checkExceptionSafety(&tokenizer, &settings, this); diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 68c939de8fc..58f20365df3 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -95,7 +95,8 @@ class TestFunctions : public TestFixture { TEST_CASE(returnLocalStdMove5); } - void check(const char code[], const char filename[]="test.cpp", const Settings* settings_=nullptr) { +#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) { // Clear the error buffer.. errout.str(""); @@ -105,7 +106,7 @@ class TestFunctions : public TestFixture { // Tokenize.. Tokenizer tokenizer(settings_, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)); + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); CheckFunctions checkFunctions(&tokenizer, settings_, this); checkFunctions.runChecks(&tokenizer, settings_, this); diff --git a/test/testinternal.cpp b/test/testinternal.cpp index efb8830e198..f4f26920f56 100644 --- a/test/testinternal.cpp +++ b/test/testinternal.cpp @@ -46,14 +46,15 @@ class TestInternal : public TestFixture { TEST_CASE(checkRedundantTokCheck); } - void check(const char code[]) { +#define check(code) check_(code, __FILE__, __LINE__) + void check_(const char code[], const char* file, int line) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckInternal checkInternal; diff --git a/test/testio.cpp b/test/testio.cpp index 31e7a0e37b6..8060b739a7c 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -77,7 +77,8 @@ class TestIO : public TestFixture { TEST_CASE(testStdDistance); // #10304 } - void check(const char* code, bool inconclusive = false, bool portability = false, Settings::PlatformType platform = Settings::Unspecified, bool onlyFormatStr = false) { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char* code, bool inconclusive = false, bool portability = false, Settings::PlatformType platform = Settings::Unspecified, bool onlyFormatStr = false) { // Clear the error buffer.. errout.str(""); @@ -92,7 +93,7 @@ class TestIO : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckIO checkIO(&tokenizer, &settings, this); diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index e443501621b..e503e76990f 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -30,15 +30,15 @@ class TestPostfixOperator : public TestFixture { private: Settings settings; - - void check(const char code[]) { +#define check(code) check_(code, __FILE__, __LINE__) + void check_(const char code[], const char* file, int line) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check for postfix operators.. CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this); diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index 908d22185b7..f7732b00f42 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -50,14 +50,15 @@ class TestSizeof : public TestFixture { TEST_CASE(customStrncat); } - void check(const char code[]) { +#define check(code) check_(code, __FILE__, __LINE__) + void check_(const char code[], const char* file, int line) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check... CheckSizeof checkSizeof(&tokenizer, &settings, this); diff --git a/test/teststl.cpp b/test/teststl.cpp index ae46aaca7d5..3f642786a07 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -173,7 +173,8 @@ class TestStl : public TestFixture { TEST_CASE(checkMutexes); } - void check(const char code[], const bool inconclusive=false, const Standards::cppstd_t cppstandard=Standards::CPPLatest) { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], const bool inconclusive = false, const Standards::cppstd_t cppstandard = Standards::CPPLatest) { // Clear the error buffer.. errout.str(""); @@ -191,18 +192,19 @@ class TestStl : public TestFixture { checkStl.runChecks(&tokenizer, &settings, this); } - void check(const std::string &code, const bool inconclusive=false) { - check(code.c_str(), inconclusive); + void check_(const char* file, int line, const std::string& code, const bool inconclusive = false) { + check_(file, line, code.c_str(), inconclusive); } - void checkNormal(const char code[]) { +#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__) + void checkNormal_(const char code[], const char* file, int line) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckStl checkStl(&tokenizer, &settings, this); diff --git a/test/teststring.cpp b/test/teststring.cpp index 02e3191ac1b..fecfe5e774f 100644 --- a/test/teststring.cpp +++ b/test/teststring.cpp @@ -60,14 +60,15 @@ class TestString : public TestFixture { TEST_CASE(deadStrcmp); } - void check(const char code[], const char filename[] = "test.cpp") { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], const char filename[] = "test.cpp") { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)); + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); // Check char variable usage.. CheckString checkString(&tokenizer, &settings, this); diff --git a/test/testtype.cpp b/test/testtype.cpp index b1ae1e20c83..e3fa69c7db7 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -40,7 +40,8 @@ class TestType : public TestFixture { TEST_CASE(checkFloatToIntegerOverflow); } - void check(const char code[], Settings* settings = nullptr, const char filename[] = "test.cpp", const std::string& standard = "c++11") { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], Settings* settings = nullptr, const char filename[] = "test.cpp", const std::string& standard = "c++11") { // Clear the error buffer.. errout.str(""); @@ -55,7 +56,7 @@ class TestType : public TestFixture { // Tokenize.. Tokenizer tokenizer(settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)); + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); // Check.. CheckType checkType(&tokenizer, settings, this); diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index 1798821a47d..7e8a73771fe 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -68,7 +68,8 @@ class TestUnusedFunctions : public TestFixture { TEST_CASE(operatorOverload); } - void check(const char code[], Settings::PlatformType platform = Settings::Native) { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], Settings::PlatformType platform = Settings::Native) { // Clear the error buffer.. errout.str(""); @@ -77,13 +78,13 @@ class TestUnusedFunctions : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check for unused functions.. CheckUnusedFunctions checkUnusedFunctions(&tokenizer, &settings, this); checkUnusedFunctions.parseTokens(tokenizer, "someFile.c", &settings); // check() returns error if and only if errout is not empty. - if (checkUnusedFunctions.check(this, settings)) { + if ((checkUnusedFunctions.check)(this, settings)) { ASSERT(errout.str() != ""); } else { ASSERT_EQUALS("", errout.str()); @@ -445,7 +446,7 @@ class TestUnusedFunctions : public TestFixture { } // Check for unused functions.. - c.check(this, settings); + (c.check)(this, settings); ASSERT_EQUALS("[test1.cpp:1]: (style) The function 'f' is never used.\n", errout.str()); } From 1a66371bed77be739ee46e403eb168c8edbe5f91 Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 29 Oct 2021 20:20:53 +0200 Subject: [PATCH 11/18] Unused parameters --- test/teststl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/teststl.cpp b/test/teststl.cpp index 3f642786a07..789822b20f9 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -188,7 +188,7 @@ class TestStl : public TestFixture { CheckStl checkStl(&tokenizer, &settings, this); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); checkStl.runChecks(&tokenizer, &settings, this); } From 6d476c233d3e3d63b0a34643a232d0af071382ac Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 2 Nov 2021 19:57:13 +0100 Subject: [PATCH 12/18] More ASSERT_LOC --- test/testastutils.cpp | 92 +++++++++++++++++++---------------- test/testsimplifytemplate.cpp | 11 +++-- test/testtoken.cpp | 13 ++--- test/testtokenize.cpp | 5 +- 4 files changed, 66 insertions(+), 55 deletions(-) diff --git a/test/testastutils.cpp b/test/testastutils.cpp index a57da2a6d88..fb5d5586292 100644 --- a/test/testastutils.cpp +++ b/test/testastutils.cpp @@ -33,29 +33,30 @@ class TestAstUtils : public TestFixture { private: void run() OVERRIDE { - TEST_CASE(findLambdaEndToken); - TEST_CASE(findLambdaStartToken); - TEST_CASE(isNullOperand); - TEST_CASE(isReturnScope); - TEST_CASE(isSameExpression); - TEST_CASE(isVariableChanged); - TEST_CASE(isVariableChangedByFunctionCall); - TEST_CASE(nextAfterAstRightmostLeaf); + TEST_CASE(findLambdaEndTokenTest); + TEST_CASE(findLambdaStartTokenTest); + TEST_CASE(isNullOperandTest); + TEST_CASE(isReturnScopeTest); + TEST_CASE(isSameExpressionTest); + TEST_CASE(isVariableChangedTest); + TEST_CASE(isVariableChangedByFunctionCallTest); + TEST_CASE(nextAfterAstRightmostLeafTest); TEST_CASE(isUsedAsBool); } - bool findLambdaEndToken(const char code[]) { +#define findLambdaEndToken(code) findLambdaEndToken_(code, __FILE__, __LINE__) + bool findLambdaEndToken_(const char code[], const char* file, int line) { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; - const Token * const tokEnd = ::findLambdaEndToken(tokenizer.tokens()); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); + const Token * const tokEnd = (::findLambdaEndToken)(tokenizer.tokens()); return tokEnd && tokEnd->next() == nullptr; } - void findLambdaEndToken() { + void findLambdaEndTokenTest() { const Token* nullTok = nullptr; - ASSERT(nullptr == ::findLambdaEndToken(nullTok)); + ASSERT(nullptr == (::findLambdaEndToken)(nullTok)); ASSERT_EQUALS(false, findLambdaEndToken("void f() { }")); ASSERT_EQUALS(true, findLambdaEndToken("[]{ }")); ASSERT_EQUALS(true, findLambdaEndToken("[]{ return 0; }")); @@ -77,17 +78,18 @@ class TestAstUtils : public TestFixture { ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> const * const* int { return x; }")); } - bool findLambdaStartToken(const char code[]) { +#define findLambdaStartToken(code) findLambdaStartToken_(code, __FILE__, __LINE__) + bool findLambdaStartToken_(const char code[], const char* file, int line) { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; - const Token * const tokStart = ::findLambdaStartToken(tokenizer.list.back()); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); + const Token * const tokStart = (::findLambdaStartToken)(tokenizer.list.back()); return tokStart && tokStart == tokenizer.list.front(); } - void findLambdaStartToken() { - ASSERT(nullptr == ::findLambdaStartToken(nullptr)); + void findLambdaStartTokenTest() { + ASSERT(nullptr == (::findLambdaStartToken)(nullptr)); ASSERT_EQUALS(false, findLambdaStartToken("void f() { }")); ASSERT_EQUALS(true, findLambdaStartToken("[]{ }")); ASSERT_EQUALS(true, findLambdaStartToken("[]{ return 0; }")); @@ -109,15 +111,16 @@ class TestAstUtils : public TestFixture { ASSERT_EQUALS(true, findLambdaStartToken("[](void) constexpr -> const * const* int { return x; }")); } - bool isNullOperand(const char code[]) { +#define isNullOperand(code) isNullOperand_(code, __FILE__, __LINE__) + bool isNullOperand_(const char code[], const char* file, int line) { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; - return ::isNullOperand(tokenizer.tokens()); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); + return (::isNullOperand)(tokenizer.tokens()); } - void isNullOperand() { + void isNullOperandTest() { ASSERT_EQUALS(true, isNullOperand("(void*)0;")); ASSERT_EQUALS(true, isNullOperand("(void*)0U;")); ASSERT_EQUALS(true, isNullOperand("(void*)0x0LL;")); @@ -130,18 +133,19 @@ class TestAstUtils : public TestFixture { ASSERT_EQUALS(false, isNullOperand("(void*)1;")); } - bool isReturnScope(const char code[], int offset) { +#define isReturnScope(code, offset) isReturnScope_(code, offset, __FILE__, __LINE__) + bool isReturnScope_(const char code[], int offset, const char* file, int line) { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); const Token * const tok = (offset < 0) ? tokenizer.list.back()->tokAt(1+offset) : tokenizer.tokens()->tokAt(offset); - return ::isReturnScope(tok); + return (::isReturnScope)(tok); } - void isReturnScope() { + void isReturnScopeTest() { ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return; } }", -2)); ASSERT_EQUALS(true, isReturnScope("int f() { if (a) { return {}; } }", -2)); // #8891 ASSERT_EQUALS(true, isReturnScope("std::string f() { if (a) { return std::string{}; } }", -2)); // #8891 @@ -160,19 +164,20 @@ class TestAstUtils : public TestFixture { ASSERT_EQUALS(true, isReturnScope("void positiveTokenOffset() { return; }", 7)); } - bool isSameExpression(const char code[], const char tokStr1[], const char tokStr2[]) { +#define isSameExpression(code, tokStr1, tokStr2) isSameExpression_(code, tokStr1, tokStr2, __FILE__, __LINE__) + bool isSameExpression_(const char code[], const char tokStr1[], const char tokStr2[], const char* file, int line) { Settings settings; Library library; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); tokenizer.simplifyTokens1(""); const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), tokStr1, strlen(tokStr1)); const Token * const tok2 = Token::findsimplematch(tok1->next(), tokStr2, strlen(tokStr2)); - return ::isSameExpression(false, false, tok1, tok2, library, false, true, nullptr); + return (::isSameExpression)(false, false, tok1, tok2, library, false, true, nullptr); } - void isSameExpression() { + void isSameExpressionTest() { ASSERT_EQUALS(true, isSameExpression("x = 1 + 1;", "1", "1")); ASSERT_EQUALS(false, isSameExpression("x = 1 + 1u;", "1", "1u")); ASSERT_EQUALS(true, isSameExpression("x = 1.0 + 1.0;", "1.0", "1.0")); @@ -199,17 +204,18 @@ class TestAstUtils : public TestFixture { ASSERT_EQUALS(true, true); } - bool isVariableChanged(const char code[], const char startPattern[], const char endPattern[]) { +#define isVariableChanged(code, startPattern, endPattern) isVariableChanged_(code, startPattern, endPattern, __FILE__, __LINE__) + bool isVariableChanged_(const char code[], const char startPattern[], const char endPattern[], const char* file, int line) { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), startPattern, strlen(startPattern)); const Token * const tok2 = Token::findsimplematch(tokenizer.tokens(), endPattern, strlen(endPattern)); - return ::isVariableChanged(tok1,tok2,1,false,&settings,true); + return (::isVariableChanged)(tok1, tok2, 1, false, &settings, true); } - void isVariableChanged() { + void isVariableChangedTest() { // #8211 - no lhs for >> , do not crash isVariableChanged("void f() {\n" " int b;\n" @@ -221,16 +227,17 @@ class TestAstUtils : public TestFixture { "}\n", "= a", "}")); } - bool isVariableChangedByFunctionCall(const char code[], const char pattern[], bool *inconclusive) { +#define isVariableChangedByFunctionCall(code, pattern, inconclusive) isVariableChangedByFunctionCall_(code, pattern, inconclusive, __FILE__, __LINE__) + bool isVariableChangedByFunctionCall_(const char code[], const char pattern[], bool *inconclusive, const char* file, int line) { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); const Token * const argtok = Token::findmatch(tokenizer.tokens(), pattern); - return ::isVariableChangedByFunctionCall(argtok, 0, &settings, inconclusive); + return (::isVariableChangedByFunctionCall)(argtok, 0, &settings, inconclusive); } - void isVariableChangedByFunctionCall() { + void isVariableChangedByFunctionCallTest() { const char *code; bool inconclusive; @@ -243,16 +250,17 @@ class TestAstUtils : public TestFixture { ASSERT_EQUALS(true, inconclusive); } - bool nextAfterAstRightmostLeaf(const char code[], const char parentPattern[], const char rightPattern[]) { +#define nextAfterAstRightmostLeaf(code, parentPattern, rightPattern) nextAfterAstRightmostLeaf_(code, parentPattern, rightPattern, __FILE__, __LINE__) + bool nextAfterAstRightmostLeaf_(const char code[], const char parentPattern[], const char rightPattern[], const char* file, int line) { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); const Token * tok = Token::findsimplematch(tokenizer.tokens(), parentPattern, strlen(parentPattern)); - return Token::simpleMatch(::nextAfterAstRightmostLeaf(tok), rightPattern, strlen(rightPattern)); + return Token::simpleMatch((::nextAfterAstRightmostLeaf)(tok), rightPattern, strlen(rightPattern)); } - void nextAfterAstRightmostLeaf() { + void nextAfterAstRightmostLeafTest() { ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("void f(int a, int b) { int x = a + b; }", "=", "; }")); ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a); }", "=", "; }")); ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a)[b]; }", "=", "; }")); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 85c52d1563c..8c313e6b345 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -261,7 +261,7 @@ class TestSimplifyTemplate : public TestFixture { TEST_CASE(templateAlias5); // Test TemplateSimplifier::instantiateMatch - TEST_CASE(instantiateMatch); + TEST_CASE(instantiateMatchTest); TEST_CASE(templateParameterWithoutName); // #8602 Template default parameter without name yields syntax error TEST_CASE(templateTypeDeduction1); // #8962 @@ -5594,16 +5594,17 @@ class TestSimplifyTemplate : public TestFixture { ASSERT_EQUALS(expected, tok(code)); } - bool instantiateMatch(const char code[], const std::size_t numberOfArguments, const char patternAfter[]) { +#define instantiateMatch(code, numberOfArguments, patternAfter) instantiateMatch_(code, numberOfArguments, patternAfter, __FILE__, __LINE__) + bool instantiateMatch_(const char code[], const std::size_t numberOfArguments, const char patternAfter[], const char* file, int line) { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp", "")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp", ""), file, line); - return TemplateSimplifier::instantiateMatch(tokenizer.tokens(), numberOfArguments, false, patternAfter); + return (TemplateSimplifier::instantiateMatch)(tokenizer.tokens(), numberOfArguments, false, patternAfter); } - void instantiateMatch() { + void instantiateMatchTest() { // Ticket #8175 ASSERT_EQUALS(false, instantiateMatch("ConvertHelper < From, To > c ;", diff --git a/test/testtoken.cpp b/test/testtoken.cpp index b7206044f98..b3c851d3da7 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -132,12 +132,13 @@ class TestToken : public TestFixture { TokenList::deleteTokens(token); } - bool Match(const std::string &code, const std::string &pattern, unsigned int varid=0) { +#define MatchCheck(...) MatchCheck_(__FILE__, __LINE__, __VA_ARGS__) + bool MatchCheck_(const char* file, int line, const std::string& code, const std::string& pattern, unsigned int varid = 0) { static const Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(";" + code + ";"); try { - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); } catch (...) {} return Token::Match(tokenizer.tokens()->next(), pattern.c_str(), varid); } @@ -762,7 +763,7 @@ class TestToken : public TestFixture { std::vector::const_iterator test_op, test_ops_end = test_ops.end(); for (test_op = test_ops.begin(); test_op != test_ops_end; ++test_op) { - ASSERT_EQUALS(true, Match(*test_op, "%op%")); + ASSERT_EQUALS(true, MatchCheck(*test_op, "%op%")); } // Negative test against other operators @@ -771,7 +772,7 @@ class TestToken : public TestFixture { std::vector::const_iterator other_op, other_ops_end = other_ops.end(); for (other_op = other_ops.begin(); other_op != other_ops_end; ++other_op) { - ASSERT_EQUALS_MSG(false, Match(*other_op, "%op%"), "Failing other operator: " + *other_op); + ASSERT_EQUALS_MSG(false, MatchCheck(*other_op, "%op%"), "Failing other operator: " + *other_op); } } @@ -784,7 +785,7 @@ class TestToken : public TestFixture { std::vector::const_iterator test_op, test_ops_end = test_ops.end(); for (test_op = test_ops.begin(); test_op != test_ops_end; ++test_op) { - ASSERT_EQUALS(true, Match(*test_op, "%cop%")); + ASSERT_EQUALS(true, MatchCheck(*test_op, "%cop%")); } // Negative test against other operators @@ -794,7 +795,7 @@ class TestToken : public TestFixture { std::vector::const_iterator other_op, other_ops_end = other_ops.end(); for (other_op = other_ops.begin(); other_op != other_ops_end; ++other_op) { - ASSERT_EQUALS_MSG(false, Match(*other_op, "%cop%"), "Failing other operator: " + *other_op); + ASSERT_EQUALS_MSG(false, MatchCheck(*other_op, "%cop%"), "Failing other operator: " + *other_op); } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index ed9752ced41..7b481224ffd 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6352,10 +6352,11 @@ class TestTokenizer : public TestFixture { tokenizeAndStringify(code.c_str()); // just survive... } - bool isStartOfExecutableScope(int offset, const char code[]) { +#define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__) + bool isStartOfExecutableScope_(int offset, const char code[], const char* file, int line) { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); return Tokenizer::startOfExecutableScope(tokenizer.tokens()->tokAt(offset)) != nullptr; } From 639f45ee80f31e6c71a58caaa15cd54c46a74729 Mon Sep 17 00:00:00 2001 From: chrchr Date: Wed, 3 Nov 2021 09:42:43 +0100 Subject: [PATCH 13/18] ASSERT_LOC --- test/testvalueflow.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 6970a09685d..2fce08d6350 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -469,17 +469,18 @@ class TestValueFlow : public TestFixture { settings.debugwarnings = false; } - std::list tokenValues(const char code[], const char tokstr[], const Settings *s = nullptr) { +#define tokenValues(...) tokenValues_(__FILE__, __LINE__, __VA_ARGS__) + std::list tokenValues_(const char* file, int line, const char code[], const char tokstr[], const Settings *s = nullptr) { Tokenizer tokenizer(s ? s : &settings, this); std::istringstream istr(code); errout.str(""); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); const Token *tok = Token::findmatch(tokenizer.tokens(), tokstr); return tok ? tok->values() : std::list(); } - std::list tokenValues(const char code[], const char tokstr[], ValueFlow::Value::ValueType vt, const Settings *s = nullptr) { - std::list values = tokenValues(code, tokstr, s); + std::list tokenValues_(const char* file, int line, const char code[], const char tokstr[], ValueFlow::Value::ValueType vt, const Settings *s = nullptr) { + std::list values = tokenValues_(file, line, code, tokstr, s); values.remove_if([&](const ValueFlow::Value& v) { return v.valueType != vt; }); @@ -505,8 +506,9 @@ class TestValueFlow : public TestFixture { return result; } - ValueFlow::Value valueOfTok(const char code[], const char tokstr[]) { - std::list values = tokenValues(code, tokstr); +#define valueOfTok(code, tokstr) valueOfTok_(code, tokstr, __FILE__, __LINE__) + ValueFlow::Value valueOfTok_(const char code[], const char tokstr[], const char* file, int line) { + std::list values = tokenValues_(file, line, code, tokstr); return values.size() == 1U && !values.front().isTokValue() ? values.front() : ValueFlow::Value(); } From 17b6484a7113dd48dd9980dae5185369f3ab360d Mon Sep 17 00:00:00 2001 From: chrchr Date: Wed, 3 Nov 2021 09:48:35 +0100 Subject: [PATCH 14/18] format --- test/testautovariables.cpp | 1 + test/testbool.cpp | 1 + test/testunusedvar.cpp | 1 - test/testvaarg.cpp | 1 + 4 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 1b378fd2046..10c9f8009dd 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -29,6 +29,7 @@ class TestAutoVariables : public TestFixture { private: Settings settings; + #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) void check_(const char* file, int line, const char code[], bool inconclusive = false, const char* filename = "test.cpp") { // Clear the error buffer.. diff --git a/test/testbool.cpp b/test/testbool.cpp index a1a5b313d39..3d63745ce5f 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -74,6 +74,7 @@ class TestBool : public TestFixture { TEST_CASE(returnNonBoolLogicalOp); TEST_CASE(returnNonBoolClass); } + #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) void check_(const char* file, int line, const char code[], bool experimental = false, const char filename[] = "test.cpp") { // Clear the error buffer.. diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 38cb1887aa9..791207d2baf 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -1574,7 +1574,6 @@ class TestUnusedVar : public TestFixture { ASSERT_EQUALS("[test.cpp:3]: (style) struct member 'S::E' is never used.\n", errout.str()); } - void functionVariableUsage_(const char* file, int line, const char code[], const char filename[] = "test.cpp") { // Clear the error buffer.. errout.str(""); diff --git a/test/testvaarg.cpp b/test/testvaarg.cpp index 2f09e9b634c..46d9a790f30 100644 --- a/test/testvaarg.cpp +++ b/test/testvaarg.cpp @@ -29,6 +29,7 @@ class TestVaarg : public TestFixture { private: Settings settings; + #define check(code) check_(code, __FILE__, __LINE__) void check_(const char code[], const char* file, int line) { // Clear the error buffer.. From 96a051299b756905dd0174532faf1f1c99b3acdb Mon Sep 17 00:00:00 2001 From: chrchr Date: Wed, 3 Nov 2021 10:20:42 +0100 Subject: [PATCH 15/18] format --- test/testunusedvar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 791207d2baf..64642c28498 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -1565,7 +1565,7 @@ class TestUnusedVar : public TestFixture { "input.skip(sizeof(struct Header));"); ASSERT_EQUALS("", errout.str()); } - + void structmember16() { checkStructMemberUsage("struct S {\n" " static const int N = 128;\n" // <- used From dbf0e71772379eec447eebd96776ddfa399c2ced Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 8 Nov 2021 20:09:04 +0100 Subject: [PATCH 16/18] More ASSERT_LOC() --- test/testconstructors.cpp | 9 +++++---- test/testexprengine.cpp | 22 +++++++++++++--------- test/testleakautovar.cpp | 17 +++++++++-------- test/testmemleak.cpp | 30 ++++++++++++++++-------------- test/testnullpointer.cpp | 17 +++++++++-------- test/testother.cpp | 14 ++++++++------ test/testsimplifytemplate.cpp | 5 +++-- test/testsimplifytypedef.cpp | 11 ++++++----- test/testsimplifyusing.cpp | 5 +++-- test/testsummaries.cpp | 5 +++-- test/testsymboldatabase.cpp | 10 ++++++---- test/testuninitvar.cpp | 25 ++++++++++++++----------- test/testvarid.cpp | 15 +++++++++------ 13 files changed, 104 insertions(+), 81 deletions(-) diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index d54e44f98b8..1c3772dba1b 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -30,7 +30,8 @@ class TestConstructors : public TestFixture { private: Settings settings; - void check(const char code[], bool inconclusive = false) { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], bool inconclusive = false) { // Clear the error buffer.. errout.str(""); @@ -39,21 +40,21 @@ class TestConstructors : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check class constructors.. CheckClass checkClass(&tokenizer, &settings, this); checkClass.constructors(); } - void check(const char code[], const Settings &s) { + void check_(const char* file, int line, const char code[], const Settings &s) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&s, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check class constructors.. CheckClass checkClass(&tokenizer, &s, this); diff --git a/test/testexprengine.cpp b/test/testexprengine.cpp index e7b830adbec..c4197c78370 100644 --- a/test/testexprengine.cpp +++ b/test/testexprengine.cpp @@ -175,12 +175,13 @@ class TestExprEngine : public TestFixture { return ret; } - std::string expr(const char code[], const std::string &binop) { +#define expr(code, binop) expr_(code, binop, __FILE__, __LINE__) + std::string expr_(const char code[], const std::string &binop, const char* file, int line) { Settings settings; settings.platform(cppcheck::Platform::Unix64); Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); std::string ret; ExprEngine::Callback f = [&](const Token *tok, const ExprEngine::Value &value, ExprEngine::DataBase *dataBase) { if (tok->str() != binop) @@ -197,7 +198,8 @@ class TestExprEngine : public TestFixture { return ret; } - std::string functionCallContractExpr(const char code[], const Settings &s) { +#define functionCallContractExpr(...) functionCallContractExpr_(code, s, __FILE__, __LINE__) + std::string functionCallContractExpr_(const char code[], const Settings &s, const char* file, int line) { Settings settings; settings.bugHunting = true; settings.debugBugHunting = true; @@ -205,7 +207,7 @@ class TestExprEngine : public TestFixture { settings.platform(cppcheck::Platform::Unix64); Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); std::vector callbacks; std::ostringstream trace; ExprEngine::executeAllFunctions(this, &tokenizer, &settings, callbacks, trace); @@ -217,20 +219,21 @@ class TestExprEngine : public TestFixture { return TestExprEngine::cleanupExpr(ret.substr(pos1, pos2+1-pos1)); } - std::string getRange(const char code[], const std::string &str, int linenr = 0) { +#define getRange(...) getRange_(__FILE__, __LINE__, __VA_ARGS__) + std::string getRange_(const char* file, int line, const char code[], const std::string &str, int linenr = 0) { Settings settings; settings.platform(cppcheck::Platform::Unix64); settings.library.smartPointers["std::shared_ptr"]; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); std::string ret; ExprEngine::Callback f = [&](const Token *tok, const ExprEngine::Value &value, ExprEngine::DataBase *dataBase) { (void)dataBase; if ((linenr == 0 || linenr == tok->linenr()) && tok->expressionString() == str) { if (!ret.empty()) ret += ","; - ret += value.getRange(); + ret += (value.getRange)(); } }; std::vector callbacks; @@ -240,7 +243,8 @@ class TestExprEngine : public TestFixture { return ret; } - std::string trackExecution(const char code[], Settings *settings = nullptr) { +#define trackExecution(...) trackExecution_(__FILE__, __LINE__, __VA_ARGS__) + std::string trackExecution_(const char* file, int line, const char code[], Settings *settings = nullptr) { Settings s; if (!settings) settings = &s; @@ -250,7 +254,7 @@ class TestExprEngine : public TestFixture { settings->library.smartPointers["std::shared_ptr"]; Tokenizer tokenizer(settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); std::vector callbacks; std::ostringstream ret; ExprEngine::executeAllFunctions(this, &tokenizer, settings, callbacks, ret); diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 58f6930194c..a92d7afe088 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -201,14 +201,15 @@ class TestLeakAutoVar : public TestFixture { TEST_CASE(functionCallCastConfig); // #9652 } - void check(const char code[], bool cpp = false) { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], bool cpp = false) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, cpp ? "test.cpp" : "test.c")); + ASSERT_LOC(tokenizer.tokenize(istr, cpp ? "test.cpp" : "test.c"), file, line); // Check for leaks.. CheckLeakAutoVar c; @@ -217,14 +218,14 @@ class TestLeakAutoVar : public TestFixture { c.runChecks(&tokenizer, &settings, this); } - void check(const char code[], Settings & settings_) { + void check_(const char* file, int line, const char code[], Settings & settings_) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings_, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check for leaks.. CheckLeakAutoVar c; @@ -2307,14 +2308,14 @@ class TestLeakAutoVarStrcpy : public TestFixture { private: Settings settings; - void check(const char code[]) { + void check_(const char* file, int line, const char code[]) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check for leaks.. CheckLeakAutoVar checkLeak; @@ -2357,14 +2358,14 @@ class TestLeakAutoVarWindows : public TestFixture { private: Settings settings; - void check(const char code[]) { + void check_(const char* file, int line, const char code[]) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.c")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.c"), file, line); // Check for leaks.. CheckLeakAutoVar checkLeak; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 1ffea91ddd4..d16316392dd 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -39,18 +39,19 @@ class TestMemleak : private TestFixture { TEST_CASE(open); } - CheckMemoryLeak::AllocType functionReturnType(const char code[]) { +#define functionReturnType(code) functionReturnType_(code, __FILE__, __LINE__) + CheckMemoryLeak::AllocType functionReturnType_(const char code[], const char* file, int line) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); const CheckMemoryLeak c(&tokenizer, this, &settings); - return c.functionReturnType(&tokenizer.getSymbolDatabase()->scopeList.front().functionList.front()); + return (c.functionReturnType)(&tokenizer.getSymbolDatabase()->scopeList.front().functionList.front()); } void testFunctionReturnType() { @@ -122,7 +123,8 @@ class TestMemleakInFunction : public TestFixture { Settings settings1; Settings settings2; - void check(const char code[]) { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[]) { // Clear the error buffer.. errout.str(""); @@ -131,7 +133,7 @@ class TestMemleakInFunction : public TestFixture { // Tokenize.. Tokenizer tokenizer(settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check for memory leaks.. CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, settings, this); @@ -467,18 +469,18 @@ class TestMemleakInClass : public TestFixture { * Tokenize and execute leak check for given code * @param code Source code */ - void check(const char code[]) { + void check_(const char* file, int line, const char code[]) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check for memory leaks.. CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this); - checkMemoryLeak.check(); + (checkMemoryLeak.check)(); } void run() OVERRIDE { @@ -1639,18 +1641,18 @@ class TestMemleakStructMember : public TestFixture { private: Settings settings; - void check(const char code[], bool isCPP = true) { + void check_(const char* file, int line, const char code[], bool isCPP = true) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, isCPP ? "test.cpp" : "test.c")); + ASSERT_LOC(tokenizer.tokenize(istr, isCPP ? "test.cpp" : "test.c"), file, line); // Check for memory leaks.. CheckMemoryLeakStructMember checkMemoryLeakStructMember(&tokenizer, &settings, this); - checkMemoryLeakStructMember.check(); + (checkMemoryLeakStructMember.check)(); } void run() OVERRIDE { @@ -2120,18 +2122,18 @@ class TestMemleakNoVar : public TestFixture { private: Settings settings; - void check(const char code[]) { + void check_(const char* file, int line, const char code[]) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check for memory leaks.. CheckMemoryLeakNoVar checkMemoryLeakNoVar(&tokenizer, &settings, this); - checkMemoryLeakNoVar.check(); + (checkMemoryLeakNoVar.check)(); } void run() OVERRIDE { diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 2b8f21a8a62..51d98aba99d 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -155,10 +155,11 @@ class TestNullPointer : public TestFixture { TEST_CASE(addNull); TEST_CASE(isPointerDeRefFunctionDecl); - TEST_CASE(ctu); + TEST_CASE(ctuTest); } - void check(const char code[], bool inconclusive = false, const char filename[] = "test.cpp") { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], bool inconclusive = false, const char filename[] = "test.cpp") { // Clear the error buffer.. errout.str(""); @@ -167,8 +168,7 @@ class TestNullPointer : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - if (!tokenizer.tokenize(istr, filename)) - return; + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); // Check for null pointer dereferences.. CheckNullPointer checkNullPointer; @@ -3666,7 +3666,7 @@ class TestNullPointer : public TestFixture { Settings settings1; Tokenizer tokenizer(&settings1,this); std::istringstream code("void f() { int a,b,c; x(a,b,c); }"); - ASSERT(tokenizer.tokenize(code, "test.c")); + ASSERT_EQUALS(true, tokenizer.tokenize(code, "test.c")); const Token *xtok = Token::findsimplematch(tokenizer.tokens(), "x"); // nothing bad.. @@ -3988,14 +3988,15 @@ class TestNullPointer : public TestFixture { ASSERT_EQUALS("", errout.str()); } - void ctu(const char code[]) { +#define ctu(code) ctu_(code, __FILE__, __LINE__) + void ctu_(const char code[], const char* file, int line) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); CTU::FileInfo *ctu = CTU::getFileInfo(&tokenizer); @@ -4011,7 +4012,7 @@ class TestNullPointer : public TestFixture { delete ctu; } - void ctu() { + void ctuTest() { setMultiline(); ctu("void f(int *fp) {\n" diff --git a/test/testother.cpp b/test/testother.cpp index a0a3c40a585..ad1c552b827 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -259,7 +259,8 @@ class TestOther : public TestFixture { TEST_CASE(constVariableArrayMember); // #10371 } - void check(const char code[], const char *filename = nullptr, bool experimental = false, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], const char *filename = nullptr, bool experimental = false, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) { // Clear the error buffer.. errout.str(""); @@ -279,7 +280,7 @@ class TestOther : public TestFixture { // Tokenize.. Tokenizer tokenizer(settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename ? filename : "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, filename ? filename : "test.cpp"), file, line); // Check.. CheckOther checkOther(&tokenizer, settings, this); @@ -288,8 +289,8 @@ class TestOther : public TestFixture { (void)runSimpleChecks; // TODO Remove this } - void check(const char code[], Settings *s) { - check(code,"test.cpp",false,true,true,false,s); + void check_(const char* file, int line, const char code[], Settings *s) { + check_(file, line, code, "test.cpp", false, true, true, false, s); } void checkP(const char code[], const char *filename = "test.cpp") { @@ -1440,7 +1441,8 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:5]: (style) C-style pointer casting\n", errout.str()); } - void checkInvalidPointerCast(const char code[], bool portability = true, bool inconclusive = false) { +#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__) + void checkInvalidPointerCast_(const char* file, int line, const char code[], bool portability = true, bool inconclusive = false) { // Clear the error buffer.. errout.str(""); @@ -1454,7 +1456,7 @@ class TestOther : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); CheckOther checkOtherCpp(&tokenizer, &settings, this); checkOtherCpp.invalidPointerCast(); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 8c313e6b345..443ac0e2ee7 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -302,7 +302,8 @@ class TestSimplifyTemplate : public TestFixture { TEST_CASE(explicitBool2); } - std::string tok(const char code[], bool debugwarnings = false, Settings::PlatformType type = Settings::Native) { +#define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__) + std::string tok_(const char* file, int line, const char code[], bool debugwarnings = false, Settings::PlatformType type = Settings::Native) { errout.str(""); settings.debugwarnings = debugwarnings; @@ -310,7 +311,7 @@ class TestSimplifyTemplate : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); return tokenizer.tokens()->stringifyList(nullptr, true); } diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index d7302019227..6f351f9d6c2 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -198,7 +198,8 @@ class TestSimplifyTypedef : public TestFixture { TEST_CASE(simplifyTypedefMacro); } - std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) { +#define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__) + std::string tok_(const char* file, int line, const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) { errout.str(""); settings0.certainty.enable(Certainty::inconclusive); @@ -207,7 +208,7 @@ class TestSimplifyTypedef : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); return tokenizer.tokens()->stringifyList(nullptr, !simplify); } @@ -249,15 +250,15 @@ class TestSimplifyTypedef : public TestFixture { return tokenizer.tokens()->stringifyList(nullptr, false); } - - void checkSimplifyTypedef(const char code[]) { +#define checkSimplifyTypedef(code) checkSimplifyTypedef_(code, __FILE__, __LINE__) + void checkSimplifyTypedef_(const char code[], const char* file, int line) { errout.str(""); // Tokenize.. settings2.certainty.enable(Certainty::inconclusive); settings2.debugwarnings = true; // show warnings about unhandled typedef Tokenizer tokenizer(&settings2, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); } diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 91e4933afca..ba223d3db7b 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -95,7 +95,8 @@ class TestSimplifyUsing : public TestFixture { TEST_CASE(scopeInfo2); } - std::string tok(const char code[], Settings::PlatformType type = Settings::Native, bool debugwarnings = true) { +#define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__) + std::string tok_(const char* file, int line, const char code[], Settings::PlatformType type = Settings::Native, bool debugwarnings = true) { errout.str(""); settings0.certainty.enable(Certainty::inconclusive); @@ -104,7 +105,7 @@ class TestSimplifyUsing : public TestFixture { Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); return tokenizer.tokens()->stringifyList(nullptr); } diff --git a/test/testsummaries.cpp b/test/testsummaries.cpp index 70b00133828..673a0459994 100644 --- a/test/testsummaries.cpp +++ b/test/testsummaries.cpp @@ -36,7 +36,8 @@ class TestSummaries : public TestFixture { TEST_CASE(createSummariesNoreturn); } - std::string createSummaries(const char code[], const char filename[] = "test.cpp") { +#define createSummaries(...) createSummaries_(__FILE__, __LINE__, __VA_ARGS__) + std::string createSummaries_(const char* file, int line, const char code[], const char filename[] = "test.cpp") { // Clear the error buffer.. errout.str(""); @@ -44,7 +45,7 @@ class TestSummaries : public TestFixture { Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) {}; + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); return Summaries::create(&tokenizer, ""); } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 51e1776f4e5..8f3852524f7 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -2132,7 +2132,8 @@ class TestSymbolDatabase : public TestFixture { ASSERT_EQUALS("char", arg1->typeEndToken()->str()); } - void check(const char code[], bool debug = true, const char filename[] = "test.cpp") { +#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) + void check_(const char* file, int line, const char code[], bool debug = true, const char filename[] = "test.cpp") { // Clear the error log errout.str(""); @@ -2142,7 +2143,7 @@ class TestSymbolDatabase : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)); + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); // force symbol database creation tokenizer.createSymbolDatabase(); @@ -7115,10 +7116,11 @@ class TestSymbolDatabase : public TestFixture { ASSERT(class_scope->functionList.begin()->functionScope == &*scope); } - std::string typeOf(const char code[], const char pattern[], const char filename[] = "test.cpp", const Settings *settings = nullptr) { +#define typeOf(...) typeOf_(__FILE__, __LINE__, __VA_ARGS__) + std::string typeOf_(const char* file, int line, const char code[], const char pattern[], const char filename[] = "test.cpp", const Settings *settings = nullptr) { Tokenizer tokenizer(settings ? settings : &settings2, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) {}; + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); const Token* tok; for (tok = tokenizer.list.back(); tok; tok = tok->previous()) if (Token::simpleMatch(tok, pattern, strlen(pattern))) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 36baf7b8cbe..fb7ca9954a5 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -86,7 +86,7 @@ class TestUninitVar : public TestFixture { TEST_CASE(trac_4871); TEST_CASE(syntax_error); // Ticket #5073 TEST_CASE(trac_5970); - TEST_CASE(valueFlowUninit); + TEST_CASE(valueFlowUninitTest); TEST_CASE(valueFlowUninitBreak); TEST_CASE(valueFlowUninitStructMembers); TEST_CASE(uninitvar_ipa); @@ -96,10 +96,11 @@ class TestUninitVar : public TestFixture { TEST_CASE(isVariableUsageDeref); // *p // whole program analysis - TEST_CASE(ctu); + TEST_CASE(ctuTest); } - void checkUninitVar(const char code[], const char fname[] = "test.cpp", bool debugwarnings = false) { +#define checkUninitVar(...) checkUninitVar_(__FILE__, __LINE__, __VA_ARGS__) + void checkUninitVar_(const char* file, int line, const char code[], const char fname[] = "test.cpp", bool debugwarnings = false) { // Clear the error buffer.. errout.str(""); @@ -107,7 +108,7 @@ class TestUninitVar : public TestFixture { settings.debugwarnings = debugwarnings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, fname)); + ASSERT_LOC(tokenizer.tokenize(istr, fname), file, line); // Check for redundant code.. CheckUninitVar checkuninitvar(&tokenizer, &settings, this); @@ -3390,6 +3391,7 @@ class TestUninitVar : public TestFixture { TODO_ASSERT_EQUALS("error", "", errout.str()); } +#define valueFlowUninit(...) valueFlowUninit_(__FILE__, __LINE__, __VA_ARGS__) void valueFlowUninit2_value() { valueFlowUninit("void f() {\n" @@ -4497,7 +4499,7 @@ class TestUninitVar : public TestFixture { // FP Unknown type ASSERT_EQUALS("", errout.str()); } - void valueFlowUninit(const char code[], const char fname[] = "test.cpp") + void valueFlowUninit_(const char* file, int line, const char code[], const char fname[] = "test.cpp") { // Clear the error buffer.. errout.str(""); @@ -4508,14 +4510,15 @@ class TestUninitVar : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, fname)); + ASSERT_LOC(tokenizer.tokenize(istr, fname), file, line); // Check for redundant code.. CheckUninitVar checkuninitvar(&tokenizer, &settings, this); - checkuninitvar.valueFlowUninit(); + (checkuninitvar.valueFlowUninit)(); } - void valueFlowUninit() { +#define ctu(code) ctu_(__FILE__, __LINE__, code) + void valueFlowUninitTest() { // #9735 - FN ctu("typedef struct\n" "{\n" @@ -5944,14 +5947,14 @@ class TestUninitVar : public TestFixture { ASSERT_EQUALS("", errout.str()); } - void ctu(const char code[]) { + void ctu_(const char* file, int line, const char code[]) { // Clear the error buffer.. errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); CTU::FileInfo *ctu = CTU::getFileInfo(&tokenizer); @@ -5967,7 +5970,7 @@ class TestUninitVar : public TestFixture { delete ctu; } - void ctu() { + void ctuTest() { ctu("void f(int *p) {\n" " a = *p;\n" "}\n" diff --git a/test/testvarid.cpp b/test/testvarid.cpp index c9dcd7da8a5..aae6278df0e 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -219,7 +219,8 @@ class TestVarID : public TestFixture { TEST_CASE(structuredBindings); } - std::string tokenize(const char code[], const char filename[] = "test.cpp") { +#define tokenize(...) tokenize_(__FILE__, __LINE__, __VA_ARGS__) + std::string tokenize_(const char* file, int line, const char code[], const char filename[] = "test.cpp") { errout.str(""); Settings settings; @@ -230,7 +231,7 @@ class TestVarID : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) {}; + ASSERT_LOC((tokenizer.tokenize)(istr, filename), file, line); // result.. Token::stringifyOptions options = Token::stringifyOptions::forDebugVarId(); @@ -238,7 +239,8 @@ class TestVarID : public TestFixture { return tokenizer.tokens()->stringifyList(options); } - std::string tokenizeExpr(const char code[], const char filename[] = "test.cpp") { +#define tokenizeExpr(...) tokenizeExpr_(__FILE__, __LINE__, __VA_ARGS__) + std::string tokenizeExpr_(const char* file, int line, const char code[], const char filename[] = "test.cpp") { errout.str(""); Settings settings; @@ -249,7 +251,7 @@ class TestVarID : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) {}; + ASSERT_LOC((tokenizer.tokenize)(istr, filename), file, line); // result.. Token::stringifyOptions options = Token::stringifyOptions::forDebugExprId(); @@ -257,7 +259,8 @@ class TestVarID : public TestFixture { return tokenizer.tokens()->stringifyList(options); } - std::string compareVaridsForVariable(const char code[], const char varname[], const char filename[] = "test.cpp") { +#define compareVaridsForVariable(...) compareVaridsForVariable_(__FILE__, __LINE__, __VA_ARGS__) + std::string compareVaridsForVariable_(const char* file, int line, const char code[], const char varname[], const char filename[] = "test.cpp") { errout.str(""); Settings settings; @@ -268,7 +271,7 @@ class TestVarID : public TestFixture { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) {}; + ASSERT_LOC((tokenizer.tokenize)(istr, filename), file, line); unsigned int varid = ~0U; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { From a8f2d11efb5b1f8c75af8ae74d00a667f5601098 Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 9 Nov 2021 14:10:50 +0100 Subject: [PATCH 17/18] More ASSERT_LOC, ASSERT --- test/testclass.cpp | 41 +++++++++++++++++++++--------------- test/testgarbage.cpp | 10 +++++---- test/testother.cpp | 5 +++-- test/testtokenize.cpp | 4 ++-- test/testunusedfunctions.cpp | 2 +- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/test/testclass.cpp b/test/testclass.cpp index c924b614fa7..c3f7978341c 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -228,7 +228,8 @@ class TestClass : public TestFixture { TEST_CASE(getFileInfo); } - void checkCopyCtorAndEqOperator(const char code[]) { +#define checkCopyCtorAndEqOperator(code) checkCopyCtorAndEqOperator_(code, __FILE__, __LINE__) + void checkCopyCtorAndEqOperator_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); Settings settings; @@ -237,11 +238,11 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckClass checkClass(&tokenizer, &settings, this); - checkClass.checkCopyCtorAndEqOperator(); + (checkClass.checkCopyCtorAndEqOperator)(); } void copyCtorAndEqOperator() { @@ -333,18 +334,19 @@ class TestClass : public TestFixture { ASSERT_EQUALS("", errout.str()); } - void checkExplicitConstructors(const char code[]) { +#define checkExplicitConstructors(code) checkExplicitConstructors_(code, __FILE__, __LINE__) + void checkExplicitConstructors_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckClass checkClass(&tokenizer, &settings0, this); - checkClass.checkExplicitConstructors(); + (checkClass.checkExplicitConstructors)(); } void explicitConstructors() { @@ -442,18 +444,19 @@ class TestClass : public TestFixture { ASSERT_EQUALS("[test.cpp:1]: (style) Struct 'A' has a constructor with 1 argument that is not explicit.\n", errout.str()); } - void checkDuplInheritedMembers(const char code[]) { +#define checkDuplInheritedMembers(code) checkDuplInheritedMembers_(code, __FILE__, __LINE__) + void checkDuplInheritedMembers_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckClass checkClass(&tokenizer, &settings1, this); - checkClass.checkDuplInheritedMembers(); + (checkClass.checkDuplInheritedMembers)(); } void duplInheritedMembers() { @@ -596,14 +599,15 @@ class TestClass : public TestFixture { ASSERT_EQUALS("", errout.str()); } - void checkCopyConstructor(const char code[]) { +#define checkCopyConstructor(code) checkCopyConstructor_(code, __FILE__, __LINE__) + void checkCopyConstructor_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckClass checkClass(&tokenizer, &settings0, this); @@ -1027,14 +1031,15 @@ class TestClass : public TestFixture { } // Check that operator Equal returns reference to this - void checkOpertorEqRetRefThis(const char code[]) { +#define checkOpertorEqRetRefThis(code) checkOpertorEqRetRefThis_(code, __FILE__, __LINE__) + void checkOpertorEqRetRefThis_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckClass checkClass(&tokenizer, &settings0, this); @@ -1490,14 +1495,15 @@ class TestClass : public TestFixture { } // Check that operator Equal checks for assignment to self - void checkOpertorEqToSelf(const char code[]) { +#define checkOpertorEqToSelf(code) checkOpertorEqToSelf_(code, __FILE__, __LINE__) + void checkOpertorEqToSelf_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckClass checkClass(&tokenizer, &settings1, this); @@ -2448,7 +2454,8 @@ class TestClass : public TestFixture { } // Check that base classes have virtual destructors - void checkVirtualDestructor(const char code[], bool inconclusive = false) { +#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__) + void checkVirtualDestructor_(const char* file, int line, const char code[], bool inconclusive = false) { // Clear the error log errout.str(""); @@ -2458,7 +2465,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckClass checkClass(&tokenizer, &settings0, this); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 77ed424f147..3b563e061d4 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -259,6 +259,7 @@ class TestGarbage : public TestFixture { TEST_CASE(nonGarbageCode1); // #8346 } +#define checkCodeInternal(code, filename) checkCodeInternal_(code, filename, __FILE__, __LINE__) std::string checkCode(const std::string &code, bool cpp = true) { // double the tests - run each example as C as well as C++ const char* const filename = cpp ? "test.cpp" : "test.c"; @@ -272,13 +273,13 @@ class TestGarbage : public TestFixture { return checkCodeInternal(code, filename); } - std::string checkCodeInternal(const std::string &code, const char* filename) { + std::string checkCodeInternal_(const std::string &code, const char* filename, const char* file, int line) { errout.str(""); // tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) {}; + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); // call all "runChecks" in all registered Check classes for (std::list::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { @@ -288,11 +289,12 @@ class TestGarbage : public TestFixture { return tokenizer.tokens()->stringifyList(false, false, false, true, false, nullptr, nullptr); } - std::string getSyntaxError(const char code[]) { +#define getSyntaxError(code) getSyntaxError_(code, __FILE__, __LINE__) + std::string getSyntaxError_(const char code[], const char* file, int line) { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); try { - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); } catch (InternalError& e) { if (e.id != "syntaxError") return ""; diff --git a/test/testother.cpp b/test/testother.cpp index ad1c552b827..d55e3558345 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1300,7 +1300,8 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:4]: (style) The scope of the variable 'x' can be reduced.\n", errout.str()); } - void checkOldStylePointerCast(const char code[]) { +#define checkOldStylePointerCast(code) checkOldStylePointerCast_(code, __FILE__, __LINE__) + void checkOldStylePointerCast_(const char code[], const char* file, int line) { // Clear the error buffer.. errout.str(""); @@ -1311,7 +1312,7 @@ class TestOther : public TestFixture { // Tokenize.. Tokenizer tokenizerCpp(&settings, this); std::istringstream istr(code); - tokenizerCpp.tokenize(istr, "test.cpp"); + ASSERT_LOC(tokenizerCpp.tokenize(istr, "test.cpp"), file, line); CheckOther checkOtherCpp(&tokenizerCpp, &settings, this); checkOtherCpp.warningOldStylePointerCast(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7b481224ffd..caba52e97ed 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3312,7 +3312,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< class"); const Token* tok2 = Token::findsimplematch(tok1, "> class"); ASSERT_EQUALS(true, tok1->link() == tok2); @@ -3325,7 +3325,7 @@ class TestTokenizer : public TestFixture { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< template"); const Token* tok2 = Token::findsimplematch(tok1, "> struct"); ASSERT_EQUALS(true, tok1->link() == tok2); diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index 7e8a73771fe..e7f9de50986 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -440,7 +440,7 @@ class TestUnusedFunctions : public TestFixture { Tokenizer tokenizer2(&settings, this); std::istringstream istr(code); - tokenizer2.tokenize(istr, fname.str().c_str()); + ASSERT(tokenizer2.tokenize(istr, fname.str().c_str())); c.parseTokens(tokenizer2, "someFile.c", &settings); } From 6d204b0a49e0511a4bb9d7bb30807536c148bdb0 Mon Sep 17 00:00:00 2001 From: chrchr Date: Wed, 17 Nov 2021 15:36:24 +0100 Subject: [PATCH 18/18] More ASSERT_LOC --- test/testclass.cpp | 86 ++++++++++++++++++++++--------------- test/testsimplifytokens.cpp | 49 ++++++++++++--------- test/testtokenize.cpp | 19 ++++---- test/testvalueflow.cpp | 68 ++++++++++++++++------------- 4 files changed, 128 insertions(+), 94 deletions(-) diff --git a/test/testclass.cpp b/test/testclass.cpp index 3bb5424457a..c737d052813 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -219,13 +219,13 @@ class TestClass : public TestFixture { TEST_CASE(override1); TEST_CASE(overrideCVRefQualifiers); - TEST_CASE(checkThisUseAfterFree); + TEST_CASE(thisUseAfterFree); TEST_CASE(unsafeClassRefMember); TEST_CASE(ctuOneDefinitionRule); - TEST_CASE(getFileInfo); + TEST_CASE(testGetFileInfo); } #define checkCopyCtorAndEqOperator(code) checkCopyCtorAndEqOperator_(code, __FILE__, __LINE__) @@ -2749,21 +2749,23 @@ class TestClass : public TestFixture { ASSERT_EQUALS("", errout.str()); } - void checkNoMemset(const char code[]) { + +#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__) + void checkNoMemset_(const char* file, int line, const char code[]) { Settings settings; settings.severity.enable(Severity::warning); settings.severity.enable(Severity::portability); - checkNoMemset(code,settings); + checkNoMemset_(file, line, code, settings); } - void checkNoMemset(const char code[], const Settings &settings) { + void checkNoMemset_(const char* file, int line, const char code[], const Settings &settings) { // Clear the error log errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckClass checkClass(&tokenizer, &settings, this); @@ -3345,15 +3347,15 @@ class TestClass : public TestFixture { ASSERT_EQUALS("", errout.str()); } - - void checkThisSubtraction(const char code[]) { +#define checkThisSubtraction(code) checkThisSubtraction_(code, __FILE__, __LINE__) + void checkThisSubtraction_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckClass checkClass(&tokenizer, &settings1, this); @@ -3378,7 +3380,8 @@ class TestClass : public TestFixture { "[test.cpp:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout.str()); } - void checkConst(const char code[], Settings *s = nullptr, bool inconclusive = true) { +#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__) + void checkConst_(const char* file, int line, const char code[], Settings *s = nullptr, bool inconclusive = true) { // Clear the error log errout.str(""); @@ -3390,10 +3393,10 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(s, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); CheckClass checkClass(&tokenizer, s, this); - checkClass.checkConst(); + (checkClass.checkConst)(); } void const1() { @@ -6566,7 +6569,8 @@ class TestClass : public TestFixture { ASSERT_EQUALS("", errout.str()); } - void checkInitializerListOrder(const char code[]) { +#define checkInitializerListOrder(code) checkInitializerListOrder_(code, __FILE__, __LINE__) + void checkInitializerListOrder_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); @@ -6576,7 +6580,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); CheckClass checkClass(&tokenizer, &settings0, this); checkClass.initializerListOrder(); @@ -6600,7 +6604,8 @@ class TestClass : public TestFixture { "[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list.\n", errout.str()); } - void checkInitializationListUsage(const char code[]) { +#define checkInitializationListUsage(code) checkInitializationListUsage_(code, __FILE__, __LINE__) + void checkInitializationListUsage_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); @@ -6611,7 +6616,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); CheckClass checkClass(&tokenizer, &settings, this); checkClass.initializationListUsage(); @@ -6815,17 +6820,18 @@ class TestClass : public TestFixture { } - void checkSelfInitialization(const char code[]) { +#define checkSelfInitialization(code) checkSelfInitialization_(code, __FILE__, __LINE__) + void checkSelfInitialization_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); CheckClass checkClass(&tokenizer, &settings0, this); - checkClass.checkSelfInitialization(); + (checkClass.checkSelfInitialization)(); } void selfInitialization() { @@ -6908,7 +6914,9 @@ class TestClass : public TestFixture { ASSERT_EQUALS("", errout.str()); } - void checkVirtualFunctionCall(const char code[], Settings *s = nullptr, bool inconclusive = true) { + +#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__) + void checkVirtualFunctionCall_(const char* file, int line, const char code[], Settings *s = nullptr, bool inconclusive = true) { // Clear the error log errout.str(""); @@ -6923,7 +6931,7 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(s, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); CheckClass checkClass(&tokenizer, s, this); checkClass.checkVirtualFunctionCallInConstructor(); @@ -7182,7 +7190,9 @@ class TestClass : public TestFixture { ASSERT_EQUALS("", errout.str()); } - void checkOverride(const char code[]) { + +#define checkOverride(code) checkOverride_(code, __FILE__, __LINE__) + void checkOverride_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); Settings settings; @@ -7191,11 +7201,11 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckClass checkClass(&tokenizer, &settings, this); - checkClass.checkOverride(); + (checkClass.checkOverride)(); } void override1() { @@ -7264,7 +7274,9 @@ class TestClass : public TestFixture { ASSERT_EQUALS("", errout.str()); } - void checkUnsafeClassRefMember(const char code[]) { + +#define checkUnsafeClassRefMember(code) checkUnsafeClassRefMember_(code, __FILE__, __LINE__) + void checkUnsafeClassRefMember_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); Settings settings; @@ -7274,11 +7286,11 @@ class TestClass : public TestFixture { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckClass checkClass(&tokenizer, &settings, this); - checkClass.checkUnsafeClassRefMember(); + (checkClass.checkUnsafeClassRefMember)(); } void unsafeClassRefMember() { @@ -7286,21 +7298,23 @@ class TestClass : public TestFixture { ASSERT_EQUALS("[test.cpp:1]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues.\n", errout.str()); } - void checkThisUseAfterFree(const char code[]) { + +#define checkThisUseAfterFree(code) checkThisUseAfterFree_(code, __FILE__, __LINE__) + void checkThisUseAfterFree_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckClass checkClass(&tokenizer, &settings1, this); - checkClass.checkThisUseAfterFree(); + (checkClass.checkThisUseAfterFree)(); } - void checkThisUseAfterFree() { + void thisUseAfterFree() { setMultiline(); // Calling method.. @@ -7481,24 +7495,26 @@ class TestClass : public TestFixture { ASSERT_EQUALS("", errout.str()); } - void getFileInfo(const char code[]) { + +#define getFileInfo(code) getFileInfo_(code, __FILE__, __LINE__) + void getFileInfo_(const char code[], const char* file, int line) { // Clear the error log errout.str(""); // Tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")); + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. CheckClass checkClass(&tokenizer, &settings1, this); - Check::FileInfo * fileInfo = checkClass.getFileInfo(&tokenizer, &settings1); + Check::FileInfo * fileInfo = (checkClass.getFileInfo)(&tokenizer, &settings1); delete fileInfo; } - void getFileInfo() { + void testGetFileInfo() { getFileInfo("void foo() { union { struct { }; }; }"); // don't crash getFileInfo("struct sometype { sometype(); }; sometype::sometype() = delete;"); // don't crash } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index f34597ef7c2..2a2d540aef8 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -370,14 +370,15 @@ class TestSimplifyTokens : public TestFixture { TEST_CASE(simplifyVarDeclInitLists); } - std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native) { +#define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__) + std::string tok_(const char* file, int line, const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native) { errout.str(""); settings0.platform(type); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); if (simplify) tokenizer.simplifyTokenList2(); @@ -385,14 +386,15 @@ class TestSimplifyTokens : public TestFixture { return tokenizer.tokens()->stringifyList(nullptr, !simplify); } - std::string tokWithWindows(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native) { +#define tokWithWindows(...) tokWithWindows_(__FILE__, __LINE__, __VA_ARGS__) + std::string tokWithWindows_(const char* file, int line, const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native) { errout.str(""); settings_windows.platform(type); Tokenizer tokenizer(&settings_windows, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); if (simplify) tokenizer.simplifyTokenList2(); @@ -400,44 +402,47 @@ class TestSimplifyTokens : public TestFixture { return tokenizer.tokens()->stringifyList(nullptr, !simplify); } - std::string tok(const char code[], const char filename[], bool simplify = true) { + std::string tok_(const char* file, int line, const char code[], const char filename[], bool simplify = true) { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) {}; + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); if (simplify) tokenizer.simplifyTokenList2(); return tokenizer.tokens()->stringifyList(nullptr, false); } - std::string tokWithNewlines(const char code[]) { +#define tokWithNewlines(code) tokWithNewlines_(code, __FILE__, __LINE__) + std::string tokWithNewlines_(const char code[], const char* file, int line) { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); tokenizer.simplifyTokenList2(); return tokenizer.tokens()->stringifyList(false, false, false, true, false); } - std::string tokWithStdLib(const char code[]) { +#define tokWithStdLib(code) tokWithStdLib_(code, __FILE__, __LINE__) + std::string tokWithStdLib_(const char code[], const char* file, int line) { errout.str(""); Tokenizer tokenizer(&settings_std, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); tokenizer.simplifyTokenList2(); return tokenizer.tokens()->stringifyList(nullptr, false); } - std::string tokenizeAndStringify(const char code[], bool simplify = false, bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) { +#define tokenizeAndStringify(...) tokenizeAndStringify_(__FILE__, __LINE__, __VA_ARGS__) + std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool simplify = false, bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) { errout.str(""); settings1.debugwarnings = true; @@ -447,7 +452,7 @@ class TestSimplifyTokens : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) {}; + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr); if (simplify) tokenizer.simplifyTokenList2(); @@ -467,12 +472,13 @@ class TestSimplifyTokens : public TestFixture { return ""; } - std::string tokenizeDebugListing(const char code[], bool simplify = false, const char filename[] = "test.cpp") { +#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") { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) {}; + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); if (simplify) tokenizer.simplifyTokenList2(); @@ -3101,14 +3107,14 @@ class TestSimplifyTokens : public TestFixture { } } - - std::string simplifyIfAndWhileAssign(const char code[]) { +#define simplifyIfAndWhileAssign(code) simplifyIfAndWhileAssign_(code, __FILE__, __LINE__) + std::string simplifyIfAndWhileAssign_(const char code[], const char* file, int line) { // tokenize.. Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); - tokenizer.simplifyIfAndWhileAssign(); + (tokenizer.simplifyIfAndWhileAssign)(); return tokenizer.tokens()->stringifyList(nullptr, false); } @@ -5234,14 +5240,15 @@ class TestSimplifyTokens : public TestFixture { "}")); } - std::string simplifyKnownVariables(const char code[]) { +#define simplifyKnownVariables(code) simplifyKnownVariables_(code, __FILE__, __LINE__) + std::string simplifyKnownVariables_(const char code[], const char* file, int line) { errout.str(""); Tokenizer tokenizer(&settings0, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); - tokenizer.simplifyKnownVariables(); + (tokenizer.simplifyKnownVariables)(); return tokenizer.tokens()->stringifyList(nullptr, false); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index ca8144d14e0..71f1588f365 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -443,7 +443,8 @@ class TestTokenizer : public TestFixture { TEST_CASE(simplifyIfSwitchForInit4); } - std::string tokenizeAndStringify(const char code[], bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) { +#define tokenizeAndStringify(...) tokenizeAndStringify_(__FILE__, __LINE__, __VA_ARGS__) + std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) { errout.str(""); settings1.debugwarnings = true; @@ -453,7 +454,7 @@ class TestTokenizer : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings1, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) {}; + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr); // filter out ValueFlow messages.. const std::string debugwarnings = errout.str(); @@ -471,7 +472,8 @@ class TestTokenizer : public TestFixture { return ""; } - std::string tokenizeAndStringifyWindows(const char code[], bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) { +#define tokenizeAndStringifyWindows(...) tokenizeAndStringifyWindows_(__FILE__, __LINE__, __VA_ARGS__) + std::string tokenizeAndStringifyWindows_(const char* file, int linenr, const char code[], bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) { errout.str(""); settings_windows.debugwarnings = true; @@ -481,7 +483,7 @@ class TestTokenizer : public TestFixture { // tokenize.. Tokenizer tokenizer(&settings_windows, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) {}; + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr); // filter out ValueFlow messages.. const std::string debugwarnings = errout.str(); @@ -499,19 +501,20 @@ class TestTokenizer : public TestFixture { return ""; } - std::string tokenizeAndStringify(const char code[], const Settings &settings, const char filename[] = "test.cpp") { + std::string tokenizeAndStringify_(const char* file, int line, const char code[], const Settings &settings, const char filename[] = "test.cpp") { errout.str(""); // tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) {}; + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); if (!tokenizer.tokens()) return ""; return tokenizer.tokens()->stringifyList(false, true, false, true, false, nullptr, nullptr); } - std::string tokenizeDebugListing(const char code[], const char filename[] = "test.cpp") { +#define tokenizeDebugListing(...) tokenizeDebugListing_(__FILE__, __LINE__, __VA_ARGS__) + std::string tokenizeDebugListing_(const char* file, int line, const char code[], const char filename[] = "test.cpp") { errout.str(""); settings2.standards.c = Standards::C89; @@ -519,7 +522,7 @@ class TestTokenizer : public TestFixture { Tokenizer tokenizer(&settings2, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, filename)) {}; + ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); // result.. return tokenizer.tokens()->stringifyList(true,true,true,true,false); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 42bb4b775bd..13823a49ab0 100755 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -178,11 +178,12 @@ class TestValueFlow : public TestFixture { return !val.isImpossible(); } - bool testValueOfXKnown(const char code[], unsigned int linenr, int value) { +#define testValueOfXKnown(...) testValueOfXKnown_(__FILE__, __LINE__, __VA_ARGS__) + bool testValueOfXKnown_(const char* file, int line, const char code[], unsigned int linenr, int value) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -198,11 +199,11 @@ class TestValueFlow : public TestFixture { return false; } - bool testValueOfXKnown(const char code[], unsigned int linenr, const std::string& expr, int value) { + bool testValueOfXKnown_(const char* file, int line, const char code[], unsigned int linenr, const std::string& expr, int value) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token* tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -218,11 +219,12 @@ class TestValueFlow : public TestFixture { return false; } - bool testValueOfXImpossible(const char code[], unsigned int linenr, int value) { +#define testValueOfXImpossible(...) testValueOfXImpossible_(__FILE__, __LINE__, __VA_ARGS__) + bool testValueOfXImpossible_(const char* file, int line, const char code[], unsigned int linenr, int value) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -238,12 +240,12 @@ class TestValueFlow : public TestFixture { return false; } - bool testValueOfXImpossible(const char code[], unsigned int linenr, const std::string& expr, int value) + bool testValueOfXImpossible_(const char* file, int line, const char code[], unsigned int linenr, const std::string& expr, int value) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token* tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -259,11 +261,12 @@ class TestValueFlow : public TestFixture { return false; } - bool testValueOfXInconclusive(const char code[], unsigned int linenr, int value) { +#define testValueOfXInconclusive(code, linenr, value) testValueOfXInconclusive_(code, linenr, value, __FILE__, __LINE__) + bool testValueOfXInconclusive_(const char code[], unsigned int linenr, int value, const char* file, int line) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -279,11 +282,12 @@ class TestValueFlow : public TestFixture { return false; } - bool testValueOfX(const char code[], unsigned int linenr, int value) { +#define testValueOfX(...) testValueOfX_(__FILE__, __LINE__, __VA_ARGS__) + bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, int value) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -297,12 +301,12 @@ class TestValueFlow : public TestFixture { return false; } - bool testValueOfX(const char code[], unsigned int linenr, const std::string& expr, int value) + bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, const std::string& expr, int value) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token* tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -317,11 +321,11 @@ class TestValueFlow : public TestFixture { return false; } - bool testValueOfX(const char code[], unsigned int linenr, float value, float diff) { + bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, float value, float diff) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -336,11 +340,12 @@ class TestValueFlow : public TestFixture { return false; } - std::string getErrorPathForX(const char code[], unsigned int linenr) { +#define getErrorPathForX(code, linenr) getErrorPathForX_(code, linenr, __FILE__, __LINE__) + std::string getErrorPathForX_(const char code[], unsigned int linenr, const char* file, int line) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() != "x" || tok->linenr() != linenr) @@ -360,11 +365,11 @@ class TestValueFlow : public TestFixture { return ""; } - bool testValueOfX(const char code[], unsigned int linenr, const char value[], ValueFlow::Value::ValueType type) { + bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, const char value[], ValueFlow::Value::ValueType type) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -378,11 +383,12 @@ class TestValueFlow : public TestFixture { return false; } - bool testLifetimeOfX(const char code[], unsigned int linenr, const char value[], ValueFlow::Value::LifetimeScope lifetimeScope = ValueFlow::Value::LifetimeScope::Local) { +#define testLifetimeOfX(...) testLifetimeOfX_(__FILE__, __LINE__, __VA_ARGS__) + bool testLifetimeOfX_(const char* file, int line, const char code[], unsigned int linenr, const char value[], ValueFlow::Value::LifetimeScope lifetimeScope = ValueFlow::Value::LifetimeScope::Local) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -396,11 +402,11 @@ class TestValueFlow : public TestFixture { return false; } - bool testValueOfX(const char code[], unsigned int linenr, int value, ValueFlow::Value::ValueType type) { + bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, int value, ValueFlow::Value::ValueType type) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -414,11 +420,11 @@ class TestValueFlow : public TestFixture { return false; } - bool testValueOfX(const char code[], unsigned int linenr, ValueFlow::Value::MoveKind moveKind) { + bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, ValueFlow::Value::MoveKind moveKind) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -432,11 +438,12 @@ class TestValueFlow : public TestFixture { return false; } - bool testConditionalValueOfX(const char code[], unsigned int linenr, int value) { +#define testConditionalValueOfX(code, linenr, value) testConditionalValueOfX_(code, linenr, value, __FILE__, __LINE__) + bool testConditionalValueOfX_(const char code[], unsigned int linenr, int value, const char* file, int line) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) false; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { if (tok->str() == "x" && tok->linenr() == linenr) { @@ -488,12 +495,13 @@ class TestValueFlow : public TestFixture { return values; } - std::vector lifetimeValues(const char code[], const char tokstr[], const Settings *s = nullptr) { +#define lifetimeValues(...) lifetimeValues_(__FILE__, __LINE__, __VA_ARGS__) + std::vector lifetimeValues_(const char* file, int line, const char code[], const char tokstr[], const Settings *s = nullptr) { std::vector result; Tokenizer tokenizer(s ? s : &settings, this); std::istringstream istr(code); errout.str(""); - ASSERT(tokenizer.tokenize(istr, "test.cpp")) {}; + ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); const Token *tok = Token::findmatch(tokenizer.tokens(), tokstr); if (!tok) return result;