testunusedvar: Added simple testing for unused variables
This commit is contained in:
parent
6881a364a2
commit
534445951c
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
||||||
SRCS=CheckBufferOverrun.cpp CheckClass.cpp CheckHeaders.cpp CheckMemoryLeak.cpp CheckOther.cpp CommonCheck.cpp tokenize.cpp
|
SRCS=CheckBufferOverrun.cpp CheckClass.cpp CheckHeaders.cpp CheckMemoryLeak.cpp CheckOther.cpp CommonCheck.cpp tokenize.cpp
|
||||||
OBJS=$(SRCS:%.cpp=%.o)
|
OBJS=$(SRCS:%.cpp=%.o)
|
||||||
TESTS=testbufferoverrun.o testcharvar.o testconstructors.o testdivision.o testmemleak.o
|
TESTS=testbufferoverrun.o testcharvar.o testconstructors.o testdivision.o testmemleak.o testunusedvar.o
|
||||||
|
|
||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
g++ -Wall -pedantic -g -I. -o $@ -c $^
|
g++ -Wall -pedantic -g -I. -o $@ -c $^
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
|
||||||
|
// Check for unused variables..
|
||||||
|
|
||||||
|
#include "MiniCppUnit.h"
|
||||||
|
#include "tokenize.h"
|
||||||
|
#include "CheckOther.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
extern std::ostringstream errout;
|
||||||
|
|
||||||
|
class TestUnusedVar : public TestFixture<TestUnusedVar>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
void check( const char code[] )
|
||||||
|
{
|
||||||
|
// Tokenize..
|
||||||
|
tokens = tokens_back = NULL;
|
||||||
|
std::istringstream istr(code);
|
||||||
|
TokenizeCode( istr );
|
||||||
|
SimplifyTokenList();
|
||||||
|
|
||||||
|
// Clear the error buffer..
|
||||||
|
errout.str("");
|
||||||
|
|
||||||
|
// Check for unused variables..
|
||||||
|
CheckStructMemberUsage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
TEST_FIXTURE( TestUnusedVar )
|
||||||
|
{
|
||||||
|
TEST_CASE( structmember1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void structmember1()
|
||||||
|
{
|
||||||
|
check( "struct abc\n"
|
||||||
|
"{\n"
|
||||||
|
" int a;\n"
|
||||||
|
" int b;\n"
|
||||||
|
" int c;\n"
|
||||||
|
"};\n" );
|
||||||
|
ASSERT_EQUALS( std::string("[test.cpp:2]: struct member 'abc::a' is never read\n"
|
||||||
|
"[test.cpp:3]: struct member 'abc::b' is never read\n"
|
||||||
|
"[test.cpp:4]: struct member 'abc::c' is never read\n"), errout.str() );
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
REGISTER_FIXTURE( TestUnusedVar )
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue