2008-11-06 01:11:37 +01:00
|
|
|
/*
|
2008-11-06 00:48:17 +01:00
|
|
|
* 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/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check for unused variables..
|
|
|
|
|
2008-11-22 21:00:36 +01:00
|
|
|
#define UNIT_TESTING
|
2008-11-06 00:48:17 +01:00
|
|
|
#include "testsuite.h"
|
|
|
|
#include "tokenize.h"
|
|
|
|
#include "CheckOther.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
extern std::ostringstream errout;
|
|
|
|
|
|
|
|
class TestIncompleteStatement : public TestFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TestIncompleteStatement() : TestFixture("TestIncompleteStatement")
|
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void check( const char code[] )
|
|
|
|
{
|
|
|
|
// Tokenize..
|
2008-11-22 21:00:36 +01:00
|
|
|
Tokenizer tokenizer;
|
|
|
|
std::istringstream istr(code);
|
2008-11-25 19:34:51 +01:00
|
|
|
tokenizer.tokenize( istr, "test.cpp" );
|
|
|
|
tokenizer.simplifyTokenList();
|
2008-11-06 00:48:17 +01:00
|
|
|
|
|
|
|
// Clear the error buffer..
|
|
|
|
errout.str("");
|
|
|
|
|
2008-11-22 21:00:36 +01:00
|
|
|
// Check for unused variables..
|
2008-11-20 23:19:26 +01:00
|
|
|
CheckOther checkOther( &tokenizer, this );
|
2008-11-11 07:42:09 +01:00
|
|
|
checkOther.CheckIncompleteStatement();
|
2008-11-06 00:48:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void run()
|
|
|
|
{
|
|
|
|
TEST_CASE( test1 );
|
|
|
|
TEST_CASE( test2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void test1()
|
|
|
|
{
|
|
|
|
check( "void foo()\n"
|
|
|
|
"{\n"
|
|
|
|
" const char def[] =\n"
|
|
|
|
"#ifdef ABC\n"
|
|
|
|
" \"abc\";\n"
|
|
|
|
"#else\n"
|
|
|
|
" \"not abc\";\n"
|
|
|
|
"#endif\n"
|
|
|
|
"}\n" );
|
|
|
|
|
|
|
|
ASSERT_EQUALS( std::string(""), errout.str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void test2()
|
|
|
|
{
|
|
|
|
// Todo: remove the ';' before the string
|
|
|
|
|
|
|
|
check( "void foo()\n"
|
|
|
|
"{\n"
|
|
|
|
" ;\"abc\";\n"
|
|
|
|
"}\n" );
|
|
|
|
|
|
|
|
ASSERT_EQUALS( std::string("[test.cpp:3]: Redundant code: Found a statement that begins with string constant\n"), errout.str() );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_TEST( TestIncompleteStatement )
|
|
|
|
|
|
|
|
|