Redundant condition: Added a test case when a condition is not redundant

This commit is contained in:
Daniel Marjamäki 2008-12-19 21:15:18 +00:00
parent e272630604
commit 11f05fe7e9
2 changed files with 73 additions and 1 deletions

View File

@ -1,6 +1,6 @@
SRCS=checkbufferoverrun.cpp checkclass.cpp checkheaders.cpp checkmemoryleak.cpp checkfunctionusage.cpp checkother.cpp filelister.cpp preprocessor.cpp tokenize.cpp cppcheck.cpp settings.cpp token.cpp cppcheckexecutor.cpp
OBJS=$(SRCS:%.cpp=%.o)
TESTS=testbufferoverrun.o testcharvar.o testclass.o testconstructors.o testdivision.o testfunctionusage.o testincompletestatement.o testmemleak.o testpreprocessor.o testredundantif.o testsimplifytokens.o testtokenize.o testtoken.o testunusedprivfunc.o testunusedvar.o testfilelister.o
TESTS=testbufferoverrun.o testcharvar.o testclass.o testconstructors.o testdivision.o testfunctionusage.o testincompletestatement.o testother.o testmemleak.o testpreprocessor.o testredundantif.o testsimplifytokens.o testtokenize.o testtoken.o testunusedprivfunc.o testunusedvar.o testfilelister.o
BIN = ${DESTDIR}/usr/bin
all: ${OBJS} main.o
@ -45,6 +45,8 @@ testfunctionusage.o: testfunctionusage.cpp tokenize.h settings.h errorlogger.h t
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
testincompletestatement.o: testincompletestatement.cpp testsuite.h errorlogger.h tokenize.h settings.h token.h checkother.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
testother.o: testother.cpp testsuite.h errorlogger.h tokenize.h settings.h token.h checkother.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
testmemleak.o: testmemleak.cpp tokenize.h settings.h errorlogger.h token.h checkmemoryleak.h testsuite.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
testpreprocessor.o: testpreprocessor.cpp testsuite.h errorlogger.h preprocessor.h

70
testother.cpp Normal file
View File

@ -0,0 +1,70 @@
/*
* c++check - c/c++ syntax checking
* Copyright (C) 2007 Daniel Marjamäki
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/
*/
#include "tokenize.h"
#include "checkother.h"
#include "testsuite.h"
#include <sstream>
extern std::ostringstream errout;
class TestOther : public TestFixture
{
public:
TestOther() : TestFixture("TestOther")
{ }
private:
void run()
{
// TODO TEST_CASE( delete1 );
}
void check( const char code[] )
{
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize( istr, "test.cpp" );
// Clear the error buffer..
errout.str("");
// Check for redundant code..
CheckOther checkOther( &tokenizer, this );
checkOther.WarningRedundantCode();
}
void delete1()
{
check( "void foo()\n"
"{\n"
" if (p)\n"
" {\n"
" delete p;\n"
" abc = 123;\n"
" }\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
};
REGISTER_TEST( TestOther )