"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/testastutils.cpp" between
cppcheck-1.86.tar.gz and cppcheck-1.87.tar.gz

About: Cppcheck is a static analysis tool for C/C++ code. It checks for memory leaks, mismatching allocation-deallocation, buffer overrun, and many more.

testastutils.cpp  (cppcheck-1.86):testastutils.cpp  (cppcheck-1.87)
/* /*
* Cppcheck - A tool for static C/C++ code analysis * Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2018 Cppcheck team. * Copyright (C) 2007-2019 Cppcheck team.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
skipping to change at line 33 skipping to change at line 33
#include "tokenize.h" #include "tokenize.h"
#include "tokenlist.h" #include "tokenlist.h"
class TestAstUtils : public TestFixture { class TestAstUtils : public TestFixture {
public: public:
TestAstUtils() : TestFixture("TestAstUtils") { TestAstUtils() : TestFixture("TestAstUtils") {
} }
private: private:
void run() override { void run() OVERRIDE {
TEST_CASE(findLambdaEndToken); TEST_CASE(findLambdaEndToken);
TEST_CASE(isReturnScope); TEST_CASE(isReturnScope);
TEST_CASE(isVariableChanged); TEST_CASE(isVariableChanged);
TEST_CASE(isVariableChangedByFunctionCall); TEST_CASE(isVariableChangedByFunctionCall);
TEST_CASE(nextAfterAstRightmostLeaf); TEST_CASE(nextAfterAstRightmostLeaf);
} }
bool findLambdaEndToken(const char code[]) { bool findLambdaEndToken(const char code[]) {
Settings settings; Settings settings;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
skipping to change at line 86 skipping to change at line 86
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
const Token * const tok = (offset < 0) const Token * const tok = (offset < 0)
? tokenizer.list.back()->tokAt(1+offset) ? tokenizer.list.back()->tokAt(1+offset)
: tokenizer.tokens()->tokAt(offset); : tokenizer.tokens()->tokAt(offset);
return ::isReturnScope(tok); return ::isReturnScope(tok);
} }
void isReturnScope() { void isReturnScope() {
ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return; } }", -2) ); 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
ASSERT_EQUALS(true, isReturnScope("std::string f() { if (a) { return std
::string{\"\"}; } }", -2)); // #8891
ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return (ab){0}; } }", -2)); // #7103 ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return (ab){0}; } }", -2)); // #7103
ASSERT_EQUALS(false, isReturnScope("void f() { if (a) { return (ab){0}; } }", -4)); // #7103 ASSERT_EQUALS(false, isReturnScope("void f() { if (a) { return (ab){0}; } }", -4)); // #7103
ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string (x);}; } }", -4)); // #7144 ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string (x);}; } }", -4)); // #7144
ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string (x);}; } }", -2)); // #7144 ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string (x);}; } }", -2)); // #7144
ASSERT_EQUALS(false, isReturnScope("void f() { [=]() { return data; }; }
", -1));
ASSERT_EQUALS(true, isReturnScope("auto f() { return [=]() { return data
; }; }", -1));
ASSERT_EQUALS(true, isReturnScope("auto f() { return [=]() { return data
; }(); }", -1));
ASSERT_EQUALS(false, isReturnScope("auto f() { [=]() { return data; }();
}", -1));
} }
bool isVariableChanged(const char code[], const char startPattern[], const c har endPattern[]) { bool isVariableChanged(const char code[], const char startPattern[], const c har endPattern[]) {
Settings settings; Settings settings;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), st artPattern); const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), st artPattern);
const Token * const tok2 = Token::findsimplematch(tokenizer.tokens(), en dPattern); const Token * const tok2 = Token::findsimplematch(tokenizer.tokens(), en dPattern);
return ::isVariableChanged(tok1,tok2,1,false,&settings,true); return ::isVariableChanged(tok1,tok2,1,false,&settings,true);
 End of changes. 4 change blocks. 
2 lines changed or deleted 16 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)