Skip to content

Commit 9a402a8

Browse files
committed
added unit tests for sarif and ran uncrustify
1 parent e676f87 commit 9a402a8

21 files changed

Lines changed: 369 additions & 266 deletions

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ ifndef INCLUDE_FOR_CLI
171171
endif
172172

173173
ifndef INCLUDE_FOR_TEST
174-
INCLUDE_FOR_TEST=-Ilib -Ifrontend -Icli -isystem externals/simplecpp -isystem externals/tinyxml2
174+
INCLUDE_FOR_TEST=-Ilib -Ifrontend -Icli -isystem externals/simplecpp -isystem externals/tinyxml2 -isystem externals/picojson
175175
endif
176176

177177
BIN=$(DESTDIR)$(PREFIX)/bin
@@ -316,6 +316,7 @@ TESTOBJ = test/fixture.o \
316316
test/testpreprocessor.o \
317317
test/testprocessexecutor.o \
318318
test/testprogrammemory.o \
319+
test/testsarif.o \
319320
test/testsettings.o \
320321
test/testsimplifytemplate.o \
321322
test/testsimplifytokens.o \
@@ -834,6 +835,9 @@ test/testprocessexecutor.o: test/testprocessexecutor.cpp cli/executor.h cli/proc
834835
test/testprogrammemory.o: test/testprogrammemory.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/settings.h lib/standards.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
835836
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testprogrammemory.cpp
836837

838+
test/testsarif.o: test/testsarif.cpp lib/config.h lib/json.h test/fixture.h test/helpers.h
839+
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testsarif.cpp
840+
837841
test/testsettings.o: test/testsettings.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h
838842
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testsettings.cpp
839843

cli/cppcheckexecutor.cpp

Lines changed: 165 additions & 95 deletions
Large diffs are not rendered by default.

lib/checkersreport.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
193193
const bool cppcheckPremium = isCppcheckPremium(mSettings);
194194

195195
auto reportSection = [&fout, cppcheckPremium]
196-
(const std::string& title,
197-
const Settings& settings,
198-
const std::set<std::string>& activeCheckers,
199-
const std::map<std::string, std::string>& premiumCheckers,
200-
const std::string& substring) {
196+
(const std::string& title,
197+
const Settings& settings,
198+
const std::set<std::string>& activeCheckers,
199+
const std::map<std::string, std::string>& premiumCheckers,
200+
const std::string& substring) {
201201
fout << std::endl << std::endl;
202202
fout << title << std::endl;
203203
fout << std::string(title.size(), '-') << std::endl;

lib/clangimport.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,12 +1499,12 @@ void clangimport::AstNode::createTokensForCXXRecord(TokenList &tokenList)
14991499
std::vector<AstNodePtr> children2;
15001500
std::copy_if(children.cbegin(), children.cend(), std::back_inserter(children2), [](const AstNodePtr& child) {
15011501
return child->nodeType == CXXConstructorDecl ||
1502-
child->nodeType == CXXDestructorDecl ||
1503-
child->nodeType == CXXMethodDecl ||
1504-
child->nodeType == FieldDecl ||
1505-
child->nodeType == VarDecl ||
1506-
child->nodeType == AccessSpecDecl ||
1507-
child->nodeType == TypedefDecl;
1502+
child->nodeType == CXXDestructorDecl ||
1503+
child->nodeType == CXXMethodDecl ||
1504+
child->nodeType == FieldDecl ||
1505+
child->nodeType == VarDecl ||
1506+
child->nodeType == AccessSpecDecl ||
1507+
child->nodeType == TypedefDecl;
15081508
});
15091509
Scope *scope = createScope(tokenList, isStruct ? ScopeType::eStruct : ScopeType::eClass, children2, classToken);
15101510
const std::string addr = mExtTokens[0];

lib/symboldatabase.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5767,11 +5767,11 @@ static bool hasMatchingConstructor(const Scope* classScope, const ValueType* arg
57675767
return false;
57685768
const ValueType* vt = f.getArgumentVar(0)->valueType();
57695769
return vt &&
5770-
vt->type == argType->type &&
5771-
(argType->sign == ValueType::Sign::UNKNOWN_SIGN || vt->sign == argType->sign) &&
5772-
vt->pointer == argType->pointer &&
5773-
(vt->constness & 1) >= (argType->constness & 1) &&
5774-
(vt->volatileness & 1) >= (argType->volatileness & 1);
5770+
vt->type == argType->type &&
5771+
(argType->sign == ValueType::Sign::UNKNOWN_SIGN || vt->sign == argType->sign) &&
5772+
vt->pointer == argType->pointer &&
5773+
(vt->constness & 1) >= (argType->constness & 1) &&
5774+
(vt->volatileness & 1) >= (argType->volatileness & 1);
57755775
});
57765776
}
57775777

lib/token.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,7 +2541,7 @@ bool Token::hasKnownSymbolicValue(const Token* tok) const
25412541
return mImpl->mValues &&
25422542
std::any_of(mImpl->mValues->begin(), mImpl->mValues->end(), [&](const ValueFlow::Value& value) {
25432543
return value.isKnown() && value.isSymbolicValue() && value.tokvalue &&
2544-
value.tokvalue->exprId() == tok->exprId();
2544+
value.tokvalue->exprId() == tok->exprId();
25452545
});
25462546
}
25472547

@@ -2614,7 +2614,7 @@ const ValueFlow::Value* Token::getMovedValue() const
26142614
return nullptr;
26152615
const auto it = std::find_if(mImpl->mValues->begin(), mImpl->mValues->end(), [](const ValueFlow::Value& value) {
26162616
return value.isMovedValue() && !value.isImpossible() &&
2617-
value.moveKind != ValueFlow::Value::MoveKind::NonMovedVariable;
2617+
value.moveKind != ValueFlow::Value::MoveKind::NonMovedVariable;
26182618
});
26192619
return it == mImpl->mValues->end() ? nullptr : &*it;
26202620
}

lib/tokenize.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10930,10 +10930,10 @@ bool Tokenizer::hasIfdef(const Token *start, const Token *end) const
1093010930
const auto& directives = mDirectives;
1093110931
return std::any_of(directives.cbegin(), directives.cend(), [&](const Directive& d) {
1093210932
return startsWith(d.str, "#if") &&
10933-
d.linenr >= start->linenr() &&
10934-
d.linenr <= end->linenr() &&
10935-
start->fileIndex() < list.getFiles().size() &&
10936-
d.file == list.getFiles()[start->fileIndex()];
10933+
d.linenr >= start->linenr() &&
10934+
d.linenr <= end->linenr() &&
10935+
start->fileIndex() < list.getFiles().size() &&
10936+
d.file == list.getFiles()[start->fileIndex()];
1093710937
});
1093810938
}
1093910939

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2760,7 +2760,7 @@ static void valueFlowLifetimeFunction(Token *tok, const TokenList &tokenlist, Er
27602760
const Token* varTok = args[iArg - 1];
27612761
if (varTok->variable() && varTok->variable()->isLocal())
27622762
LifetimeStore{ varTok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::LifetimeKind::Address }.byRef(
2763-
tok->next(), tokenlist, errorLogger, settings);
2763+
tok->next(), tokenlist, errorLogger, settings);
27642764
}
27652765
}
27662766
}

lib/vf_settokenvalue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ namespace ValueFlow
528528
args2.begin(),
529529
[&](const Token* atok, const Token* btok) {
530530
return atok->getKnownIntValue() ==
531-
btok->getKnownIntValue();
531+
btok->getKnownIntValue();
532532
});
533533
} else {
534534
equal = false;

samples/passedByValue_1/bad.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ class C
22
{
33
public:
44
explicit C(std::string s)
5-
: _s(s)
6-
{
7-
}
5+
: _s(s)
6+
{}
87
void foo();
98
private:
109
std::string _s;

0 commit comments

Comments
 (0)