Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 74 additions & 74 deletions Makefile

Large diffs are not rendered by default.

16 changes: 3 additions & 13 deletions test/fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#define fixtureH

#include "check.h"
#include "checks.h"
#include "color.h"
#include "config.h"
#include "errorlogger.h"
Expand All @@ -33,7 +32,6 @@
#include <cstddef>
#include <cstdint>
#include <exception>
#include <list>
#include <memory>
#include <set>
#include <sstream>
Expand Down Expand Up @@ -136,21 +134,13 @@ class TestFixture : public ErrorLogger {

void processOptions(const options& args);

template<typename T>
static T& getCheck()
static Check& getCheck(Check& check)
{
for (Check *check : CheckInstances::get()) {
//cppcheck-suppress useStlAlgorithm
if (T* c = dynamic_cast<T*>(check))
return *c;
}
throw std::runtime_error("instance not found");
return check;
}

template<typename T>
static void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
static void runChecks(Check& check, const Tokenizer &tokenizer, ErrorLogger *errorLogger)
{
Check& check = getCheck<T>();
check.runChecks(tokenizer, errorLogger);
}

Expand Down
4 changes: 2 additions & 2 deletions test/testassert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class TestAssert : public TestFixture {
SimpleTokenizer tokenizer(settings, *this);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check..
runChecks<CheckAssert>(tokenizer, this);
CheckAssert check;
runChecks(check, tokenizer, this);
}

void run() override {
Expand Down
3 changes: 2 additions & 1 deletion test/testautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class TestAutoVariables : public TestFixture {
SimpleTokenizer tokenizer(settings1, *this, options.cpp);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

runChecks<CheckAutoVariables>(tokenizer, this);
CheckAutoVariables check;
runChecks(check, tokenizer, this);
}

void run() override {
Expand Down
4 changes: 2 additions & 2 deletions test/testbool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class TestBool : public TestFixture {
SimpleTokenizer tokenizer(settings, *this, options.cpp);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check...
runChecks<CheckBool>(tokenizer, this);
CheckBool check;
runChecks(check, tokenizer, this);
}


Expand Down
19 changes: 10 additions & 9 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class TestBufferOverrun : public TestFixture {
SimpleTokenizer tokenizer(settings, *this, cpp);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check for buffer overruns..
runChecks<CheckBufferOverrun>(tokenizer, this);
CheckBufferOverrun check;
runChecks(check, tokenizer, this);
}

// TODO: get rid of this
Expand All @@ -66,8 +66,8 @@ class TestBufferOverrun : public TestFixture {
SimpleTokenizer tokenizer(settings0_i, *this);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check for buffer overruns..
runChecks<CheckBufferOverrun>(tokenizer, this);
CheckBufferOverrun check;
runChecks(check, tokenizer, this);
}

#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
Expand All @@ -79,8 +79,8 @@ class TestBufferOverrun : public TestFixture {
// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);

// Check for buffer overruns..
runChecks<CheckBufferOverrun>(tokenizer, this);
CheckBufferOverrun check;
runChecks(check, tokenizer, this);
}

void run() override {
Expand Down Expand Up @@ -5169,7 +5169,8 @@ class TestBufferOverrun : public TestFixture {

void getErrorMessages() {
// Ticket #2292: segmentation fault when using --errorlist
const Check& c = getCheck<CheckBufferOverrun>();
CheckBufferOverrun check;
const Check& c = getCheck(check);
c.getErrorMessages(this, nullptr);
// we are not interested in the output - just consume it
ignore_errout();
Expand Down Expand Up @@ -5362,9 +5363,9 @@ class TestBufferOverrun : public TestFixture {

CTU::FileInfo *ctu = CTU::getFileInfo(tokenizer);

// Check code..
std::list<Check::FileInfo*> fileInfo;
Check& c = getCheck<CheckBufferOverrun>();
CheckBufferOverrun check;
Check& c = getCheck(check);
fileInfo.push_back(c.getFileInfo(tokenizer, settings0, ""));
c.analyseWholeProgram(*ctu, fileInfo, settings0, *this); // TODO: check result
while (!fileInfo.empty()) {
Expand Down
7 changes: 4 additions & 3 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9278,7 +9278,8 @@ class TestClass : public TestFixture {


void ctu(const std::vector<std::string> &code) {
Check &check = getCheck<CheckClass>();
CheckClass checkClass;
Check &check = getCheck(checkClass);

// getFileInfo
std::list<Check::FileInfo*> fileInfo;
Expand Down Expand Up @@ -9330,8 +9331,8 @@ class TestClass : public TestFixture {
SimpleTokenizer tokenizer(settings1, *this);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check..
const Check& c = getCheck<CheckClass>();
CheckClass check;
const Check& c = getCheck(check);
Check::FileInfo * fileInfo = (c.getFileInfo)(tokenizer, settings1, "");

delete fileInfo;
Expand Down
11 changes: 6 additions & 5 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ class TestCondition : public TestFixture {
// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);

// Run checks..
runChecks<CheckCondition>(tokenizer, this);
CheckCondition check;
runChecks(check, tokenizer, this);
}

#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
Expand All @@ -162,8 +162,8 @@ class TestCondition : public TestFixture {
// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);

// Run checks..
runChecks<CheckCondition>(tokenizer, this);
CheckCondition check;
runChecks(check, tokenizer, this);
}

void assignAndCompare() {
Expand Down Expand Up @@ -527,7 +527,8 @@ class TestCondition : public TestFixture {
SimpleTokenizer tokenizer(settings1, *this);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

runChecks<CheckCondition>(tokenizer, this);
CheckCondition check;
runChecks(check, tokenizer, this);
}

void multicompare() {
Expand Down
4 changes: 2 additions & 2 deletions test/testexceptionsafety.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class TestExceptionSafety : public TestFixture {
SimpleTokenizer tokenizer(settings1, *this);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check char variable usage..
runChecks<CheckExceptionSafety>(tokenizer, this);
CheckExceptionSafety check;
runChecks(check, tokenizer, this);
}

void destructors() {
Expand Down
3 changes: 2 additions & 1 deletion test/testfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ class TestFunctions : public TestFixture {
SimpleTokenizer tokenizer(s, *this, cpp);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

runChecks<CheckFunctions>(tokenizer, this);
CheckFunctions check;
runChecks(check, tokenizer, this);
}

void prohibitedFunctions_posix() {
Expand Down
4 changes: 2 additions & 2 deletions test/testinternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class TestInternal : public TestFixture {
SimpleTokenizer tokenizer(settings, *this);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check..
runChecks<CheckInternal>(tokenizer, this);
CheckInternal check;
runChecks(check, tokenizer, this);
}

void simplePatternInTokenMatch() {
Expand Down
3 changes: 2 additions & 1 deletion test/testio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ class TestIO : public TestFixture {
checkIO.checkWrongPrintfScanfArguments();
return;
}
runChecks<CheckIO>(tokenizer, this);
CheckIO check;
runChecks(check, tokenizer, this);
}

void coutCerrMisusage() {
Expand Down
32 changes: 13 additions & 19 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,17 @@ class TestLeakAutoVar : public TestFixture {
template<size_t size>
void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {
const Settings& settings1 = options.s ? *options.s : settings;

// Tokenize..
SimpleTokenizer tokenizer(settings1, *this, options.cpp);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check for leaks..
runChecks<CheckLeakAutoVar>(tokenizer, this);
check_(file, line, code, settings1, options.cpp);
}

template<size_t size>
void check_(const char* file, int line, const char (&code)[size], const Settings & s) {
void check_(const char* file, int line, const char (&code)[size], const Settings & s, bool cpp = true) {
// Tokenize..
SimpleTokenizer tokenizer(s, *this);
SimpleTokenizer tokenizer(s, *this, cpp);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check for leaks..
runChecks<CheckLeakAutoVar>(tokenizer, this);
CheckLeakAutoVar check;
runChecks(check, tokenizer, this);
}

void assign1() {
Expand Down Expand Up @@ -3272,8 +3266,8 @@ class TestLeakAutoVarRecursiveCountLimit : public TestFixture {
// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);

// Check for leaks..
runChecks<CheckLeakAutoVar>(tokenizer, this);
CheckLeakAutoVar check;
runChecks(check, tokenizer, this);
}

void run() override {
Expand Down Expand Up @@ -3319,8 +3313,8 @@ class TestLeakAutoVarStrcpy : public TestFixture {
SimpleTokenizer tokenizer(settings, *this);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check for leaks..
runChecks<CheckLeakAutoVar>(tokenizer, this);
CheckLeakAutoVar check;
runChecks(check, tokenizer, this);
}

void run() override {
Expand Down Expand Up @@ -3424,8 +3418,8 @@ class TestLeakAutoVarWindows : public TestFixture {
SimpleTokenizer tokenizer(settings, *this, false);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check for leaks..
runChecks<CheckLeakAutoVar>(tokenizer, this);
CheckLeakAutoVar check;
runChecks(check, tokenizer, this);
}

void run() override {
Expand Down Expand Up @@ -3497,8 +3491,8 @@ class TestLeakAutoVarPosix : public TestFixture {
SimpleTokenizer tokenizer(settings, *this);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check for leaks..
runChecks<CheckLeakAutoVar>(tokenizer, this);
CheckLeakAutoVar check;
runChecks(check, tokenizer, this);
}

void run() override {
Expand Down
24 changes: 9 additions & 15 deletions test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,17 @@ class TestNullPointer : public TestFixture {
template<size_t size>
void check_(const char* file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {
const Settings& settings1 = options.inconclusive ? settings_i : settings;

// Tokenize..
SimpleTokenizer tokenizer(settings1, *this, options.cpp);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check for null pointer dereferences..
runChecks<CheckNullPointer>(tokenizer, this);
check_(file, line, code, settings1, options.cpp);
}

template<size_t size>
void check_(const char* file, int line, const char (&code)[size], bool cpp, const Settings& s) {
void check_(const char* file, int line, const char (&code)[size], const Settings& s, bool cpp = true) {
// Tokenize..
SimpleTokenizer tokenizer(s, *this, cpp);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check for null pointer dereferences..
runChecks<CheckNullPointer>(tokenizer, this);
CheckNullPointer check;
runChecks(check, tokenizer, this);
}

#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
Expand All @@ -217,8 +211,8 @@ class TestNullPointer : public TestFixture {
// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);

// Check for null pointer dereferences..
runChecks<CheckNullPointer>(tokenizer, this);
CheckNullPointer check;
runChecks(check, tokenizer, this);
}


Expand Down Expand Up @@ -1349,7 +1343,7 @@ class TestNullPointer : public TestFixture {
ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: i [nullPointer]\n", errout_str());

const Settings s = settingsBuilder(settings).c(Standards::C17).build();
check(code, false, s); // C17 file => nullptr does not mean NULL
check(code, s, false); // C17 file => nullptr does not mean NULL
ASSERT_EQUALS("", errout_str());

check(code, dinit(CheckOptions, $.cpp = false));
Expand Down Expand Up @@ -4698,9 +4692,9 @@ class TestNullPointer : public TestFixture {

CTU::FileInfo *ctu = CTU::getFileInfo(tokenizer);

// Check code..
CheckNullPointer check;
Check& c = getCheck(check);
std::list<Check::FileInfo*> fileInfo;
Check& c = getCheck<CheckNullPointer>();
fileInfo.push_back(c.getFileInfo(tokenizer, settings, ""));
c.analyseWholeProgram(*ctu, fileInfo, settings, *this); // TODO: check result
while (!fileInfo.empty()) {
Expand Down
12 changes: 6 additions & 6 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ class TestOther : public TestFixture {
SimpleTokenizer tokenizer(*settings, *this, opt.cpp);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check..
runChecks<CheckOther>(tokenizer, this);
CheckOther check;
runChecks(check, tokenizer, this);
}

struct CheckPOptions
Expand All @@ -384,8 +384,8 @@ class TestOther : public TestFixture {
// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);

// Check..
runChecks<CheckOther>(tokenizer, this);
CheckOther check;
runChecks(check, tokenizer, this);
}

template<size_t size>
Expand Down Expand Up @@ -12314,8 +12314,8 @@ class TestOther : public TestFixture {
SimpleTokenizer tokenizer(settings, *this, cpp);
ASSERT_LOC(tokenizer.tokenize(code), file, line);

// Check..
runChecks<CheckOther>(tokenizer, this);
CheckOther check;
runChecks(check, tokenizer, this);
}

void testEvaluationOrder() {
Expand Down
Loading
Loading