reduced usage of mutable `Settings` objects in tests (#4798)

This commit is contained in:
Oliver Stöneberg 2023-05-02 11:48:24 +02:00 committed by GitHub
parent 9d21379c7d
commit 2935c855c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 309 additions and 464 deletions

View File

@ -667,13 +667,13 @@ cli/stacktrace.o: cli/stacktrace.cpp cli/stacktrace.h lib/config.h lib/utils.h
cli/threadexecutor.o: cli/threadexecutor.cpp cli/cppcheckexecutor.h cli/executor.h cli/threadexecutor.h lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h cli/threadexecutor.o: cli/threadexecutor.cpp cli/cppcheckexecutor.h cli/executor.h cli/threadexecutor.h lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/threadexecutor.cpp $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/threadexecutor.cpp
test/fixture.o: test/fixture.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/suppressions.h test/fixture.h test/options.h test/redirect.h test/fixture.o: test/fixture.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h test/options.h test/redirect.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/fixture.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/fixture.cpp
test/helpers.o: test/helpers.cpp externals/simplecpp/simplecpp.h lib/config.h lib/errortypes.h lib/mathlib.h lib/path.h lib/preprocessor.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/helpers.h test/helpers.o: test/helpers.cpp externals/simplecpp/simplecpp.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/helpers.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/helpers.cpp
test/main.o: test/main.cpp externals/simplecpp/simplecpp.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/preprocessor.h lib/suppressions.h test/fixture.h test/options.h test/main.o: test/main.cpp externals/simplecpp/simplecpp.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h test/options.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/main.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/main.cpp
test/options.o: test/options.cpp test/options.h test/options.o: test/options.cpp test/options.h
@ -682,7 +682,7 @@ test/options.o: test/options.cpp test/options.h
test/test64bit.o: test/test64bit.cpp lib/check.h lib/check64bit.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/test64bit.o: test/test64bit.cpp lib/check.h lib/check64bit.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/test64bit.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/test64bit.cpp
test/testanalyzerinformation.o: test/testanalyzerinformation.cpp lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/platform.h lib/suppressions.h lib/utils.h test/fixture.h test/testanalyzerinformation.o: test/testanalyzerinformation.cpp lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testanalyzerinformation.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testanalyzerinformation.cpp
test/testassert.o: test/testassert.cpp lib/check.h lib/checkassert.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/testassert.o: test/testassert.cpp lib/check.h lib/checkassert.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
@ -715,7 +715,7 @@ test/testclass.o: test/testclass.cpp externals/simplecpp/simplecpp.h lib/check.h
test/testcmdlineparser.o: test/testcmdlineparser.cpp cli/cmdlineparser.h cli/cppcheckexecutor.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h test/fixture.h test/redirect.h test/testcmdlineparser.o: test/testcmdlineparser.cpp cli/cmdlineparser.h cli/cppcheckexecutor.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h test/fixture.h test/redirect.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcmdlineparser.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcmdlineparser.cpp
test/testcolor.o: test/testcolor.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/suppressions.h test/fixture.h test/testcolor.o: test/testcolor.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcolor.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcolor.cpp
test/testcondition.o: test/testcondition.cpp externals/simplecpp/simplecpp.h lib/check.h lib/checkcondition.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/testcondition.o: test/testcondition.cpp externals/simplecpp/simplecpp.h lib/check.h lib/checkcondition.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
@ -733,7 +733,7 @@ test/testerrorlogger.o: test/testerrorlogger.cpp externals/tinyxml2/tinyxml2.h l
test/testexceptionsafety.o: test/testexceptionsafety.cpp lib/check.h lib/checkexceptionsafety.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/testexceptionsafety.o: test/testexceptionsafety.cpp lib/check.h lib/checkexceptionsafety.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testexceptionsafety.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testexceptionsafety.cpp
test/testfilelister.o: test/testfilelister.cpp cli/filelister.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/pathmatch.h lib/suppressions.h test/fixture.h test/testfilelister.o: test/testfilelister.cpp cli/filelister.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/pathmatch.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testfilelister.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testfilelister.cpp
test/testfunctions.o: test/testfunctions.cpp lib/check.h lib/checkfunctions.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/testfunctions.o: test/testfunctions.cpp lib/check.h lib/checkfunctions.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
@ -760,7 +760,7 @@ test/testleakautovar.o: test/testleakautovar.cpp externals/simplecpp/simplecpp.h
test/testlibrary.o: test/testlibrary.cpp externals/tinyxml2/tinyxml2.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.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 test/testlibrary.o: test/testlibrary.cpp externals/tinyxml2/tinyxml2.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.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
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testlibrary.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testlibrary.cpp
test/testmathlib.o: test/testmathlib.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/mathlib.h lib/suppressions.h test/fixture.h test/testmathlib.o: test/testmathlib.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testmathlib.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testmathlib.cpp
test/testmemleak.o: test/testmemleak.cpp lib/check.h lib/checkmemoryleak.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/testmemleak.o: test/testmemleak.cpp lib/check.h lib/checkmemoryleak.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
@ -769,19 +769,19 @@ test/testmemleak.o: test/testmemleak.cpp lib/check.h lib/checkmemoryleak.h lib/c
test/testnullpointer.o: test/testnullpointer.cpp externals/simplecpp/simplecpp.h lib/check.h lib/checknullpointer.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/testnullpointer.o: test/testnullpointer.cpp externals/simplecpp/simplecpp.h lib/check.h lib/checknullpointer.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testnullpointer.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testnullpointer.cpp
test/testoptions.o: test/testoptions.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/suppressions.h test/fixture.h test/options.h test/testoptions.o: test/testoptions.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h test/options.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testoptions.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testoptions.cpp
test/testother.o: test/testother.cpp externals/simplecpp/simplecpp.h lib/check.h lib/checkother.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/testother.o: test/testother.cpp externals/simplecpp/simplecpp.h lib/check.h lib/checkother.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testother.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testother.cpp
test/testpath.o: test/testpath.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/path.h lib/suppressions.h test/fixture.h test/testpath.o: test/testpath.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testpath.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testpath.cpp
test/testpathmatch.o: test/testpathmatch.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/pathmatch.h lib/suppressions.h test/fixture.h test/testpathmatch.o: test/testpathmatch.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/pathmatch.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testpathmatch.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testpathmatch.cpp
test/testplatform.o: test/testplatform.cpp externals/tinyxml2/tinyxml2.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/platform.h lib/suppressions.h test/fixture.h test/testplatform.o: test/testplatform.cpp externals/tinyxml2/tinyxml2.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testplatform.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testplatform.cpp
test/testpostfixoperator.o: test/testpostfixoperator.cpp lib/check.h lib/checkpostfixoperator.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/testpostfixoperator.o: test/testpostfixoperator.cpp lib/check.h lib/checkpostfixoperator.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
@ -832,7 +832,7 @@ test/testsymboldatabase.o: test/testsymboldatabase.cpp lib/check.h lib/color.h l
test/testthreadexecutor.o: test/testthreadexecutor.cpp cli/executor.h cli/threadexecutor.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h test/redirect.h test/testthreadexecutor.o: test/testthreadexecutor.cpp cli/executor.h cli/threadexecutor.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h test/redirect.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testthreadexecutor.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testthreadexecutor.cpp
test/testtimer.o: test/testtimer.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/suppressions.h lib/timer.h test/fixture.h test/testtimer.o: test/testtimer.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testtimer.cpp $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testtimer.cpp
test/testtoken.o: test/testtoken.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.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 test/testtoken.o: test/testtoken.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.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

View File

@ -20,6 +20,7 @@
#include "errortypes.h" #include "errortypes.h"
#include "options.h" #include "options.h"
#include "path.h"
#include "redirect.h" #include "redirect.h"
#include <cstdio> #include <cstdio>
@ -74,7 +75,6 @@ unsigned int TestFixture::countTests;
std::size_t TestFixture::fails_counter = 0; std::size_t TestFixture::fails_counter = 0;
std::size_t TestFixture::todos_counter = 0; std::size_t TestFixture::todos_counter = 0;
std::size_t TestFixture::succeeded_todos_counter = 0; std::size_t TestFixture::succeeded_todos_counter = 0;
std::set<std::string> TestFixture::missingLibs;
TestFixture::TestFixture(const char * const _name) TestFixture::TestFixture(const char * const _name)
: mVerbose(false), : mVerbose(false),
@ -284,11 +284,6 @@ void TestFixture::assertNoThrowFail(const char * const filename, const unsigned
} }
void TestFixture::complainMissingLib(const char * const libname)
{
missingLibs.insert(libname);
}
void TestFixture::printHelp() void TestFixture::printHelp()
{ {
std::cout << "Testrunner - run Cppcheck tests\n" std::cout << "Testrunner - run Cppcheck tests\n"
@ -372,12 +367,6 @@ std::size_t TestFixture::runTests(const options& args)
std::cerr << "Tests failed: " << fails_counter << std::endl << std::endl; std::cerr << "Tests failed: " << fails_counter << std::endl << std::endl;
std::cerr << errmsg.str(); std::cerr << errmsg.str();
if (!missingLibs.empty()) {
std::cerr << "Missing libraries: ";
for (const std::string & missingLib : missingLibs)
std::cerr << missingLib << " ";
std::cerr << std::endl << std::endl;
}
std::cerr.flush(); std::cerr.flush();
return fails_counter + succeeded_todos_counter; return fails_counter + succeeded_todos_counter;
} }
@ -409,3 +398,16 @@ void TestFixture::setTemplateFormat(const std::string &templateFormat)
mTemplateLocation = ""; mTemplateLocation = "";
} }
} }
TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::library(const char lib[]) {
// TODO: exename is not yet set
LOAD_LIB_2_EXE(settings.library, lib, fixture.exename.c_str());
// strip extension
std::string lib_s(lib);
const std::string ext(".cfg");
const auto pos = lib_s.find(ext);
if (pos != std::string::npos)
lib_s.erase(pos, ext.size());
settings.libraries.emplace_back(lib_s);
return *this;
}

View File

@ -24,6 +24,7 @@
#include "color.h" #include "color.h"
#include "config.h" #include "config.h"
#include "errorlogger.h" #include "errorlogger.h"
#include "settings.h"
#include <cstddef> #include <cstddef>
#include <list> #include <list>
@ -43,7 +44,6 @@ private:
static std::size_t fails_counter; static std::size_t fails_counter;
static std::size_t todos_counter; static std::size_t todos_counter;
static std::size_t succeeded_todos_counter; static std::size_t succeeded_todos_counter;
static std::set<std::string> missingLibs;
bool mVerbose; bool mVerbose;
std::string mTemplateFormat; std::string mTemplateFormat;
std::string mTemplateLocation; std::string mTemplateLocation;
@ -95,7 +95,6 @@ protected:
void assertThrow(const char * const filename, const unsigned int linenr) const; void assertThrow(const char * const filename, const unsigned int linenr) const;
void assertThrowFail(const char * const filename, const unsigned int linenr) const; void assertThrowFail(const char * const filename, const unsigned int linenr) const;
void assertNoThrowFail(const char * const filename, const unsigned int linenr) const; void assertNoThrowFail(const char * const filename, const unsigned int linenr) const;
static void complainMissingLib(const char * const libname);
static std::string deleteLineNumber(const std::string &message); static std::string deleteLineNumber(const std::string &message);
void setVerbose(bool v) { void setVerbose(bool v) {
@ -127,6 +126,72 @@ protected:
T& check = getCheck<T>(); T& check = getCheck<T>();
check.runChecks(tokenizer, settings, errorLogger); check.runChecks(tokenizer, settings, errorLogger);
} }
// TODO: bail out on redundant settings
class SettingsBuilder
{
public:
explicit SettingsBuilder(const TestFixture &fixture) : fixture(fixture) {}
SettingsBuilder(const TestFixture &fixture, Settings settings) : fixture(fixture), settings(std::move(settings)) {}
SettingsBuilder& severity(Severity::SeverityType sev) {
settings.severity.enable(sev);
return *this;
}
SettingsBuilder& certainty(Certainty cert, bool b = true) {
settings.certainty.setEnabled(cert, b);
return *this;
}
SettingsBuilder& clang() {
settings.clang = true;
return *this;
}
SettingsBuilder& checkLibrary() {
settings.checkLibrary = true;
return *this;
}
SettingsBuilder& checkUnusedTemplates() {
settings.checkUnusedTemplates = true;
return *this;
}
SettingsBuilder& debugwarnings(bool b = true) {
settings.debugwarnings = b;
return *this;
}
SettingsBuilder& c(Standards::cstd_t std) {
settings.standards.c = std;
return *this;
}
SettingsBuilder& cpp(Standards::cppstd_t std) {
settings.standards.cpp = std;
return *this;
}
SettingsBuilder& library(const char lib[]);
Settings build() {
return std::move(settings);
}
private:
const TestFixture &fixture;
Settings settings;
};
SettingsBuilder settingsBuilder() const {
return SettingsBuilder(*this);
}
SettingsBuilder settingsBuilder(Settings settings) const {
return SettingsBuilder(*this, std::move(settings));
}
public: public:
void reportOut(const std::string &outmsg, Color c = Color::Reset) override; void reportOut(const std::string &outmsg, Color c = Color::Reset) override;
void reportErr(const ErrorMessage &msg) override; void reportErr(const ErrorMessage &msg) override;
@ -165,13 +230,8 @@ extern std::ostringstream output;
#define EXPECT_EQ( EXPECTED, ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL) #define EXPECT_EQ( EXPECTED, ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance_ ## CLASSNAME; } #define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance_ ## CLASSNAME; }
#define LOAD_LIB_2(LIB, NAME) \ #define LOAD_LIB_2_EXE( LIB, NAME, EXE ) do { if (((LIB).load((EXE), NAME).errorcode != Library::ErrorCode::OK)) throw std::runtime_error("library '" + std::string(NAME) + "' not found"); } while (false)
do { \ #define LOAD_LIB_2( LIB, NAME ) LOAD_LIB_2_EXE(LIB, NAME, exename.c_str())
if (((LIB).load(exename.c_str(), NAME).errorcode != Library::ErrorCode::OK)) { \
complainMissingLib(NAME); \
abort(); \
} \
} while (false)
#define PLATFORM( P, T ) do { std::string errstr; assertEquals(__FILE__, __LINE__, true, P.set(cppcheck::Platform::toString(T), errstr, {exename}), errstr); } while (false) #define PLATFORM( P, T ) do { std::string errstr; assertEquals(__FILE__, __LINE__, true, P.set(cppcheck::Platform::toString(T), errstr, {exename}), errstr); } while (false)

View File

@ -19,6 +19,7 @@
#ifndef helpersH #ifndef helpersH
#define helpersH #define helpersH
#include "settings.h"
#include "tokenize.h" #include "tokenize.h"
#include "tokenlist.h" #include "tokenlist.h"
@ -27,13 +28,12 @@
class Token; class Token;
class Preprocessor; class Preprocessor;
class Settings;
class Suppressions; class Suppressions;
class givenACodeSampleToTokenize { class givenACodeSampleToTokenize {
private: private:
Tokenizer tokenizer; Tokenizer tokenizer;
static const Settings settings; const Settings settings;
public: public:
explicit givenACodeSampleToTokenize(const char sample[], bool createOnly = false, bool cpp = true) explicit givenACodeSampleToTokenize(const char sample[], bool createOnly = false, bool cpp = true)

View File

@ -30,11 +30,9 @@ public:
Test64BitPortability() : TestFixture("Test64BitPortability") {} Test64BitPortability() : TestFixture("Test64BitPortability") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().severity(Severity::portability).library("std.cfg").build();
void run() override { void run() override {
settings.severity.enable(Severity::portability);
TEST_CASE(novardecl); TEST_CASE(novardecl);
TEST_CASE(functionpar); TEST_CASE(functionpar);
TEST_CASE(structmember); TEST_CASE(structmember);
@ -51,7 +49,6 @@ private:
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
LOAD_LIB_2(settings.library, "std.cfg");
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);

View File

@ -32,7 +32,7 @@ public:
TestAssert() : TestFixture("TestAssert") {} TestAssert() : TestFixture("TestAssert") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().severity(Severity::warning).build();
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[], const char *filename = "test.cpp") { void check_(const char* file, int line, const char code[], const char *filename = "test.cpp") {
@ -49,8 +49,6 @@ private:
} }
void run() override { void run() override {
settings.severity.enable(Severity::warning);
TEST_CASE(assignmentInAssert); TEST_CASE(assignmentInAssert);
TEST_CASE(functionCallInAssert); TEST_CASE(functionCallInAssert);
TEST_CASE(memberFunctionCallInAssert); TEST_CASE(memberFunctionCallInAssert);

View File

@ -50,7 +50,7 @@ private:
#define findLambdaEndToken(code) findLambdaEndToken_(code, __FILE__, __LINE__) #define findLambdaEndToken(code) findLambdaEndToken_(code, __FILE__, __LINE__)
bool findLambdaEndToken_(const char code[], const char* file, int line) { bool findLambdaEndToken_(const char code[], const char* file, int line) {
Settings settings; const Settings settings;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
@ -84,7 +84,7 @@ private:
#define findLambdaStartToken(code) findLambdaStartToken_(code, __FILE__, __LINE__) #define findLambdaStartToken(code) findLambdaStartToken_(code, __FILE__, __LINE__)
bool findLambdaStartToken_(const char code[], const char* file, int line) { bool findLambdaStartToken_(const char code[], const char* file, int line) {
Settings settings; const Settings settings;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
@ -117,7 +117,7 @@ private:
#define isNullOperand(code) isNullOperand_(code, __FILE__, __LINE__) #define isNullOperand(code) isNullOperand_(code, __FILE__, __LINE__)
bool isNullOperand_(const char code[], const char* file, int line) { bool isNullOperand_(const char code[], const char* file, int line) {
Settings settings; const Settings settings;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
@ -139,7 +139,7 @@ private:
#define isReturnScope(code, offset) isReturnScope_(code, offset, __FILE__, __LINE__) #define isReturnScope(code, offset) isReturnScope_(code, offset, __FILE__, __LINE__)
bool isReturnScope_(const char code[], int offset, const char* file, int line) { bool isReturnScope_(const char code[], int offset, const char* file, int line) {
Settings settings; const Settings settings;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
@ -170,7 +170,7 @@ private:
#define isSameExpression(code, tokStr1, tokStr2) isSameExpression_(code, tokStr1, tokStr2, __FILE__, __LINE__) #define isSameExpression(code, tokStr1, tokStr2) isSameExpression_(code, tokStr1, tokStr2, __FILE__, __LINE__)
bool isSameExpression_(const char code[], const char tokStr1[], const char tokStr2[], const char* file, int line) { bool isSameExpression_(const char code[], const char tokStr1[], const char tokStr2[], const char* file, int line) {
Settings settings; const Settings settings;
Library library; Library library;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
@ -210,7 +210,7 @@ private:
#define isVariableChanged(code, startPattern, endPattern) isVariableChanged_(code, startPattern, endPattern, __FILE__, __LINE__) #define isVariableChanged(code, startPattern, endPattern) isVariableChanged_(code, startPattern, endPattern, __FILE__, __LINE__)
bool isVariableChanged_(const char code[], const char startPattern[], const char endPattern[], const char* file, int line) { bool isVariableChanged_(const char code[], const char startPattern[], const char endPattern[], const char* file, int line) {
Settings settings; const Settings settings;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
@ -240,7 +240,7 @@ private:
#define isVariableChangedByFunctionCall(code, pattern, inconclusive) isVariableChangedByFunctionCall_(code, pattern, inconclusive, __FILE__, __LINE__) #define isVariableChangedByFunctionCall(code, pattern, inconclusive) isVariableChangedByFunctionCall_(code, pattern, inconclusive, __FILE__, __LINE__)
bool isVariableChangedByFunctionCall_(const char code[], const char pattern[], bool *inconclusive, const char* file, int line) { bool isVariableChangedByFunctionCall_(const char code[], const char pattern[], bool *inconclusive, const char* file, int line) {
Settings settings; const Settings settings;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
@ -416,7 +416,7 @@ private:
#define nextAfterAstRightmostLeaf(code, parentPattern, rightPattern) nextAfterAstRightmostLeaf_(code, parentPattern, rightPattern, __FILE__, __LINE__) #define nextAfterAstRightmostLeaf(code, parentPattern, rightPattern) nextAfterAstRightmostLeaf_(code, parentPattern, rightPattern, __FILE__, __LINE__)
bool nextAfterAstRightmostLeaf_(const char code[], const char parentPattern[], const char rightPattern[], const char* file, int line) { bool nextAfterAstRightmostLeaf_(const char code[], const char parentPattern[], const char rightPattern[], const char* file, int line) {
Settings settings; const Settings settings;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
@ -441,7 +441,7 @@ private:
enum class Result {False, True, Fail}; enum class Result {False, True, Fail};
Result isUsedAsBool(const char code[], const char pattern[]) { Result isUsedAsBool(const char code[], const char pattern[]) {
Settings settings; const Settings settings;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
if (!tokenizer.tokenize(istr, "test.cpp")) if (!tokenizer.tokenize(istr, "test.cpp"))

View File

@ -32,30 +32,24 @@ public:
TestAutoVariables() : TestFixture("TestAutoVariables") {} TestAutoVariables() : TestFixture("TestAutoVariables") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).library("std.cfg").library("qt.cfg").build();
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[], bool inconclusive = true, const char* filename = "test.cpp") { void check_(const char* file, int line, const char code[], bool inconclusive = true, const char* filename = "test.cpp") {
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive); const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, inconclusive).build();
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings1, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
runChecks<CheckAutoVariables>(&tokenizer, &settings, this); runChecks<CheckAutoVariables>(&tokenizer, &settings1, this);
} }
void run() override { void run() override {
settings.severity.enable(Severity::warning);
settings.severity.enable(Severity::style);
LOAD_LIB_2(settings.library, "std.cfg");
LOAD_LIB_2(settings.library, "qt.cfg");
settings.libraries.emplace_back("qt");
TEST_CASE(testautovar1); TEST_CASE(testautovar1);
TEST_CASE(testautovar2); TEST_CASE(testautovar2);
TEST_CASE(testautovar3); // ticket #2925 TEST_CASE(testautovar3); // ticket #2925

View File

@ -31,13 +31,9 @@ public:
TestBool() : TestFixture("TestBool") {} TestBool() : TestFixture("TestBool") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).certainty(Certainty::inconclusive).build();
void run() override { void run() override {
settings.severity.enable(Severity::style);
settings.severity.enable(Severity::warning);
settings.certainty.enable(Certainty::inconclusive);
TEST_CASE(bitwiseOnBoolean); // if (bool & bool) TEST_CASE(bitwiseOnBoolean); // if (bool & bool)
TEST_CASE(incrementBoolean); TEST_CASE(incrementBoolean);
TEST_CASE(assignBoolToPointer); TEST_CASE(assignBoolToPointer);

View File

@ -31,12 +31,9 @@ public:
TestBoost() : TestFixture("TestBoost") {} TestBoost() : TestFixture("TestBoost") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::performance).build();
void run() override { void run() override {
settings.severity.enable(Severity::style);
settings.severity.enable(Severity::performance);
TEST_CASE(BoostForeachContainerModification); TEST_CASE(BoostForeachContainerModification);
} }

View File

@ -42,22 +42,22 @@ public:
TestBufferOverrun() : TestFixture("TestBufferOverrun") {} TestBufferOverrun() : TestFixture("TestBufferOverrun") {}
private: private:
Settings settings0; Settings settings0 = settingsBuilder().library("std.cfg").severity(Severity::warning).severity(Severity::style).severity(Severity::portability).build();
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[], const char filename[] = "test.cpp") { void check_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
settings0.certainty.enable(Certainty::inconclusive); const Settings settings = settingsBuilder(settings0).certainty(Certainty::inconclusive).build();
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings0, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
// Check for buffer overruns.. // Check for buffer overruns..
runChecks<CheckBufferOverrun>(&tokenizer, &settings0, this); runChecks<CheckBufferOverrun>(&tokenizer, &settings, this);
} }
void check_(const char* file, int line, const char code[], const Settings &settings, const char filename[] = "test.cpp") { void check_(const char* file, int line, const char code[], const Settings &settings, const char filename[] = "test.cpp") {
@ -77,14 +77,14 @@ private:
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings* settings = &settings0; Settings settings = settings0;
settings->severity.enable(Severity::style); settings.severity.enable(Severity::style);
settings->severity.enable(Severity::warning); settings.severity.enable(Severity::warning);
settings->severity.enable(Severity::portability); settings.severity.enable(Severity::portability);
settings->severity.enable(Severity::performance); settings.severity.enable(Severity::performance);
settings->standards.c = Standards::CLatest; settings.standards.c = Standards::CLatest;
settings->standards.cpp = Standards::CPPLatest; settings.standards.cpp = Standards::CPPLatest;
settings->certainty.enable(Certainty::inconclusive); settings.certainty.enable(Certainty::inconclusive);
// Raw tokens.. // Raw tokens..
std::vector<std::string> files(1, filename); std::vector<std::string> files(1, filename);
@ -97,21 +97,15 @@ private:
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI()); simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());
// Tokenizer.. // Tokenizer..
Tokenizer tokenizer(settings, this); Tokenizer tokenizer(&settings, this);
tokenizer.createTokens(std::move(tokens2)); tokenizer.createTokens(std::move(tokens2));
tokenizer.simplifyTokens1(""); tokenizer.simplifyTokens1("");
// Check for buffer overruns.. // Check for buffer overruns..
runChecks<CheckBufferOverrun>(&tokenizer, settings, this); runChecks<CheckBufferOverrun>(&tokenizer, &settings, this);
} }
void run() override { void run() override {
LOAD_LIB_2(settings0.library, "std.cfg");
settings0.severity.enable(Severity::warning);
settings0.severity.enable(Severity::style);
settings0.severity.enable(Severity::portability);
TEST_CASE(noerr1); TEST_CASE(noerr1);
TEST_CASE(noerr2); TEST_CASE(noerr2);
TEST_CASE(noerr3); TEST_CASE(noerr3);
@ -3356,6 +3350,7 @@ private:
void buffer_overrun_errorpath() { void buffer_overrun_errorpath() {
setMultiline(); setMultiline();
const Settings settingsOld = settings0;
settings0.templateLocation = "{file}:{line}:note:{info}"; settings0.templateLocation = "{file}:{line}:note:{info}";
check("void f() {\n" check("void f() {\n"
@ -3365,6 +3360,10 @@ private:
ASSERT_EQUALS("test.cpp:3:error:Buffer is accessed out of bounds: p\n" ASSERT_EQUALS("test.cpp:3:error:Buffer is accessed out of bounds: p\n"
"test.cpp:2:note:Assign p, buffer with size 10\n" "test.cpp:2:note:Assign p, buffer with size 10\n"
"test.cpp:3:note:Buffer overrun\n", errout.str()); "test.cpp:3:note:Buffer overrun\n", errout.str());
// TODO: need to reset this but it breaks other tests
(void)settingsOld;
//settings0 = settingsOld;
} }
void buffer_overrun_bailoutIfSwitch() { void buffer_overrun_bailoutIfSwitch() {
@ -5526,9 +5525,7 @@ private:
void checkPipeParameterSize() { // #3521 void checkPipeParameterSize() { // #3521
Settings settings; const Settings settings = settingsBuilder().library("posix.cfg").build();
LOAD_LIB_2(settings.library, "posix.cfg");
settings.libraries.emplace_back("posix");
check("void f(){\n" check("void f(){\n"
"int pipefd[1];\n" // <-- array of two integers is needed "int pipefd[1];\n" // <-- array of two integers is needed

View File

@ -31,12 +31,10 @@ public:
TestCharVar() : TestFixture("TestCharVar") {} TestCharVar() : TestFixture("TestCharVar") {}
private: private:
Settings settings; Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).build();
void run() override { void run() override {
PLATFORM(settings.platform, cppcheck::Platform::Type::Unspecified); PLATFORM(settings.platform, cppcheck::Platform::Type::Unspecified);
settings.severity.enable(Severity::warning);
settings.severity.enable(Severity::portability);
TEST_CASE(array_index_1); TEST_CASE(array_index_1);
TEST_CASE(array_index_2); TEST_CASE(array_index_2);

View File

@ -137,8 +137,7 @@ private:
} }
std::string parse(const char clang[]) { std::string parse(const char clang[]) {
Settings settings; const Settings settings = settingsBuilder().clang().build();
settings.clang = true;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(clang); std::istringstream istr(clang);
clangimport::parseClangAstDump(&tokenizer, istr); clangimport::parseClangAstDump(&tokenizer, istr);
@ -1049,8 +1048,7 @@ private:
#define GET_SYMBOL_DB(AST) \ #define GET_SYMBOL_DB(AST) \
Settings settings; \ Settings settings = settingsBuilder().clang().build(); \
settings.clang = true; \
{ \ { \
std::string errstr; \ std::string errstr; \
ASSERT_EQUALS_MSG(true, settings.platform.set("unix64", errstr, {exename.c_str()}), errstr); \ ASSERT_EQUALS_MSG(true, settings.platform.set("unix64", errstr, {exename.c_str()}), errstr); \

View File

@ -36,13 +36,10 @@ public:
TestClass() : TestFixture("TestClass") {} TestClass() : TestFixture("TestClass") {}
private: private:
Settings settings0; Settings settings0 = settingsBuilder().severity(Severity::style).build();
Settings settings1; Settings settings1 = settingsBuilder().severity(Severity::warning).build();
void run() override { void run() override {
settings0.severity.enable(Severity::style);
settings1.severity.enable(Severity::warning);
// Load std.cfg configuration // Load std.cfg configuration
{ {
const char xmldata[] = "<?xml version=\"1.0\"?>\n" const char xmldata[] = "<?xml version=\"1.0\"?>\n"
@ -262,8 +259,7 @@ private:
void checkCopyCtorAndEqOperator_(const char code[], const char* file, int line) { void checkCopyCtorAndEqOperator_(const char code[], const char* file, int line) {
// Clear the error log // Clear the error log
errout.str(""); errout.str("");
Settings settings; Settings settings = settingsBuilder().severity(Severity::warning).build();
settings.severity.enable(Severity::warning);
Preprocessor preprocessor(settings); Preprocessor preprocessor(settings);
@ -2890,9 +2886,7 @@ private:
#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__) #define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)
void checkNoMemset_(const char* file, int line, const char code[]) { void checkNoMemset_(const char* file, int line, const char code[]) {
Settings settings; Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).build();
settings.severity.enable(Severity::warning);
settings.severity.enable(Severity::portability);
checkNoMemset_(file, line, code, settings); checkNoMemset_(file, line, code, settings);
} }
@ -3156,8 +3150,7 @@ private:
errout.str()); errout.str());
// #1655 // #1655
Settings s; Settings s = settingsBuilder().library("std.cfg").build();
LOAD_LIB_2(s.library, "std.cfg");
checkNoMemset("void f() {\n" checkNoMemset("void f() {\n"
" char c[] = \"abc\";\n" " char c[] = \"abc\";\n"
" std::string s;\n" " std::string s;\n"
@ -7231,10 +7224,7 @@ private:
} }
void qualifiedNameMember() { // #10872 void qualifiedNameMember() { // #10872
Settings s; Settings s = settingsBuilder().severity(Severity::style).debugwarnings().library("std.cfg").build();
s.severity.enable(Severity::style);
s.debugwarnings = true;
LOAD_LIB_2(s.library, "std.cfg");
checkConst("struct data {};\n" checkConst("struct data {};\n"
" struct S {\n" " struct S {\n"
" std::vector<data> std;\n" " std::vector<data> std;\n"
@ -7289,8 +7279,7 @@ private:
errout.str(""); errout.str("");
// Check.. // Check..
Settings settings; Settings settings = settingsBuilder().severity(Severity::performance).build();
settings.severity.enable(Severity::performance);
Preprocessor preprocessor(settings); Preprocessor preprocessor(settings);
@ -7970,8 +7959,8 @@ private:
void checkOverride_(const char code[], const char* file, int line) { void checkOverride_(const char code[], const char* file, int line) {
// Clear the error log // Clear the error log
errout.str(""); errout.str("");
Settings settings;
settings.severity.enable(Severity::style); Settings settings = settingsBuilder().severity(Severity::style).build();
Preprocessor preprocessor(settings); Preprocessor preprocessor(settings);
@ -8147,9 +8136,9 @@ private:
void checkUnsafeClassRefMember_(const char code[], const char* file, int line) { void checkUnsafeClassRefMember_(const char code[], const char* file, int line) {
// Clear the error log // Clear the error log
errout.str(""); errout.str("");
Settings settings;
Settings settings = settingsBuilder().severity(Severity::warning).build();
settings.safeChecks.classes = true; settings.safeChecks.classes = true;
settings.severity.enable(Severity::warning);
Preprocessor preprocessor(settings); Preprocessor preprocessor(settings);
@ -8328,7 +8317,7 @@ private:
void ctu(const std::vector<std::string> &code) { void ctu(const std::vector<std::string> &code) {
Settings settings; const Settings settings;
auto &check = getCheck<CheckClass>(); auto &check = getCheck<CheckClass>();
// getFileInfo // getFileInfo

View File

@ -37,9 +37,8 @@
class TestCmdlineParser : public TestFixture { class TestCmdlineParser : public TestFixture {
public: public:
TestCmdlineParser() TestCmdlineParser() : TestFixture("TestCmdlineParser")
: TestFixture("TestCmdlineParser") {
, defParser(settings, settings.nomsg, settings.nofail) {
#if defined(_WIN64) || defined(_WIN32) #if defined(_WIN64) || defined(_WIN32)
CmdLineParser::SHOW_DEF_PLATFORM_MSG = false; CmdLineParser::SHOW_DEF_PLATFORM_MSG = false;
#endif #endif
@ -53,7 +52,7 @@ public:
private: private:
Settings settings; // TODO: reset after each test Settings settings; // TODO: reset after each test
CmdLineParser defParser; // TODO: reset after each test CmdLineParser defParser{settings, settings.nomsg, settings.nofail}; // TODO: reset after each test
void run() override { void run() override {
TEST_CASE(nooptions); TEST_CASE(nooptions);

View File

@ -39,28 +39,19 @@ public:
TestCondition() : TestFixture("TestCondition") {} TestCondition() : TestFixture("TestCondition") {}
private: private:
Settings settings0; Settings settings0 = settingsBuilder().library("qt.cfg").library("std.cfg").severity(Severity::style).severity(Severity::warning).build();
Settings settings1; Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();
void run() override { void run() override {
// known platform.. // known platform..
PLATFORM(settings0.platform, cppcheck::Platform::Type::Native); PLATFORM(settings0.platform, cppcheck::Platform::Type::Native);
PLATFORM(settings1.platform, cppcheck::Platform::Type::Native); PLATFORM(settings1.platform, cppcheck::Platform::Type::Native);
LOAD_LIB_2(settings0.library, "qt.cfg");
settings0.libraries.emplace_back("qt");
LOAD_LIB_2(settings0.library, "std.cfg");
settings0.severity.enable(Severity::style);
settings0.severity.enable(Severity::warning);
const char cfg[] = "<?xml version=\"1.0\"?>\n" const char cfg[] = "<?xml version=\"1.0\"?>\n"
"<def>\n" "<def>\n"
" <function name=\"bar\"> <pure/> </function>\n" " <function name=\"bar\"> <pure/> </function>\n"
"</def>"; "</def>";
ASSERT(settings1.library.loadxmldata(cfg, sizeof(cfg))); ASSERT(settings1.library.loadxmldata(cfg, sizeof(cfg)));
settings1.severity.enable(Severity::style);
settings1.severity.enable(Severity::warning);
TEST_CASE(assignAndCompare); // assignment and comparison don't match TEST_CASE(assignAndCompare); // assignment and comparison don't match
TEST_CASE(mismatchingBitAnd); // overlapping bitmasks TEST_CASE(mismatchingBitAnd); // overlapping bitmasks
@ -5644,8 +5635,7 @@ private:
} }
void compareOutOfTypeRange() { void compareOutOfTypeRange() {
Settings settingsUnix64; Settings settingsUnix64 = settingsBuilder().severity(Severity::style).build();
settingsUnix64.severity.enable(Severity::style);
PLATFORM(settingsUnix64.platform, cppcheck::Platform::Type::Unix64); PLATFORM(settingsUnix64.platform, cppcheck::Platform::Type::Unix64);
check("void f(unsigned char c) {\n" check("void f(unsigned char c) {\n"

View File

@ -32,22 +32,22 @@ public:
TestConstructors() : TestFixture("TestConstructors") {} TestConstructors() : TestFixture("TestConstructors") {}
private: private:
Settings settings; Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[], bool inconclusive = false) { void check_(const char* file, int line, const char code[], bool inconclusive = false) {
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive); const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, inconclusive).build();
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings1, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
// Check class constructors.. // Check class constructors..
CheckClass checkClass(&tokenizer, &settings, this); CheckClass checkClass(&tokenizer, &settings1, this);
checkClass.constructors(); checkClass.constructors();
} }
@ -66,9 +66,6 @@ private:
} }
void run() override { void run() override {
settings.severity.enable(Severity::style);
settings.severity.enable(Severity::warning);
TEST_CASE(simple1); TEST_CASE(simple1);
TEST_CASE(simple2); TEST_CASE(simple2);
TEST_CASE(simple3); TEST_CASE(simple3);
@ -1950,9 +1947,8 @@ private:
} }
void initvar_smartptr() { // #10237 void initvar_smartptr() { // #10237
Settings s; // TODO: test should probably not pass without library
// TODO: test shuld probably not pass without library const Settings s = settingsBuilder() /*.library("std.cfg")*/.build();
//LOAD_LIB_2(s.library, "std.cfg");
check("struct S {\n" check("struct S {\n"
" explicit S(const std::shared_ptr<S>& sp) {\n" " explicit S(const std::shared_ptr<S>& sp) {\n"
" set(*sp);\n" " set(*sp);\n"
@ -1994,11 +1990,7 @@ private:
"{ }", true); "{ }", true);
ASSERT_EQUALS("[test.cpp:13]: (warning, inconclusive) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='.\n", errout.str()); ASSERT_EQUALS("[test.cpp:13]: (warning, inconclusive) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='.\n", errout.str());
Settings s; const Settings s = settingsBuilder().certainty(Certainty::inconclusive).severity(Severity::style).severity(Severity::warning).library("std.cfg").build();
s.certainty.setEnabled(Certainty::inconclusive, true);
s.severity.enable(Severity::style);
s.severity.enable(Severity::warning);
LOAD_LIB_2(s.library, "std.cfg");
check("struct S {\n" check("struct S {\n"
" S& operator=(const S& s) { return *this; }\n" " S& operator=(const S& s) { return *this; }\n"
" std::mutex m;\n" " std::mutex m;\n"
@ -3610,10 +3602,8 @@ private:
} }
void uninitVarInheritClassInit() { void uninitVarInheritClassInit() {
Settings s;
// TODO: test should probably not pass without library // TODO: test should probably not pass without library
//LOAD_LIB_2(s.library, "vcl.cfg"); const Settings s = settingsBuilder() /*.library("vcl.cfg")*/.build();
//s.libraries.emplace_back("vcl");
check("class Fred: public TObject\n" check("class Fred: public TObject\n"
"{\n" "{\n"

View File

@ -31,11 +31,11 @@
class TestErrorLogger : public TestFixture { class TestErrorLogger : public TestFixture {
public: public:
TestErrorLogger() : TestFixture("TestErrorLogger"), fooCpp5("foo.cpp", 5, 1), barCpp8("bar.cpp", 8, 1) {} TestErrorLogger() : TestFixture("TestErrorLogger") {}
private: private:
const ErrorMessage::FileLocation fooCpp5; const ErrorMessage::FileLocation fooCpp5{"foo.cpp", 5, 1};
const ErrorMessage::FileLocation barCpp8; const ErrorMessage::FileLocation barCpp8{"bar.cpp", 8, 1};
void run() override { void run() override {
TEST_CASE(PatternSearchReplace); TEST_CASE(PatternSearchReplace);

View File

@ -29,8 +29,7 @@
class TestFileLister : public TestFixture { class TestFileLister : public TestFixture {
public: public:
TestFileLister() TestFileLister() : TestFixture("TestFileLister") {}
: TestFixture("TestFileLister") {}
private: private:
void run() override { void run() override {

View File

@ -33,20 +33,10 @@ public:
TestFunctions() : TestFixture("TestFunctions") {} TestFunctions() : TestFixture("TestFunctions") {}
private: private:
Settings settings; Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).severity(Severity::performance).severity(Severity::portability).
certainty(Certainty::inconclusive).c(Standards::C11).cpp(Standards::CPP11).library("std.cfg").library("posix.cfg").build();
void run() override { void run() override {
settings.severity.enable(Severity::style);
settings.severity.enable(Severity::warning);
settings.severity.enable(Severity::performance);
settings.severity.enable(Severity::portability);
settings.certainty.enable(Certainty::inconclusive);
settings.standards.c = Standards::C11;
settings.standards.cpp = Standards::CPP11;
LOAD_LIB_2(settings.library, "std.cfg");
LOAD_LIB_2(settings.library, "posix.cfg");
settings.libraries.emplace_back("posix");
// Prohibited functions // Prohibited functions
TEST_CASE(prohibitedFunctions_posix); TEST_CASE(prohibitedFunctions_posix);
TEST_CASE(prohibitedFunctions_index); TEST_CASE(prohibitedFunctions_index);

View File

@ -35,13 +35,13 @@ public:
TestIncompleteStatement() : TestFixture("TestIncompleteStatement") {} TestIncompleteStatement() : TestFixture("TestIncompleteStatement") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().severity(Severity::warning).build();
void check(const char code[], bool inconclusive = false) { void check(const char code[], bool inconclusive = false) {
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive); const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, inconclusive).build();
// Raw tokens.. // Raw tokens..
std::vector<std::string> files(1, "test.cpp"); std::vector<std::string> files(1, "test.cpp");
@ -54,18 +54,16 @@ private:
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI()); simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings1, this);
tokenizer.createTokens(std::move(tokens2)); tokenizer.createTokens(std::move(tokens2));
tokenizer.simplifyTokens1(""); tokenizer.simplifyTokens1("");
// Check for incomplete statements.. // Check for incomplete statements..
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings1, this);
checkOther.checkIncompleteStatement(); checkOther.checkIncompleteStatement();
} }
void run() override { void run() override {
settings.severity.enable(Severity::warning);
TEST_CASE(test1); TEST_CASE(test1);
TEST_CASE(test2); TEST_CASE(test2);
TEST_CASE(test3); TEST_CASE(test3);

View File

@ -35,14 +35,10 @@ public:
TestIO() : TestFixture("TestIO") {} TestIO() : TestFixture("TestIO") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().library("std.cfg").library("windows.cfg").library("qt.cfg").build();
Settings settings1 = settingsBuilder().library("std.cfg").library("windows.cfg").library("qt.cfg").build();
void run() override { void run() override {
LOAD_LIB_2(settings.library, "std.cfg");
LOAD_LIB_2(settings.library, "windows.cfg");
LOAD_LIB_2(settings.library, "qt.cfg");
settings.libraries.emplace_back("qt");
TEST_CASE(coutCerrMisusage); TEST_CASE(coutCerrMisusage);
TEST_CASE(wrongMode_simple); TEST_CASE(wrongMode_simple);
@ -91,22 +87,22 @@ private:
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
settings.severity.clear(); settings1.severity.clear();
settings.severity.enable(Severity::warning); settings1.severity.enable(Severity::warning);
settings.severity.enable(Severity::style); settings1.severity.enable(Severity::style);
if (portability) if (portability)
settings.severity.enable(Severity::portability); settings1.severity.enable(Severity::portability);
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive); settings1.certainty.setEnabled(Certainty::inconclusive, inconclusive);
PLATFORM(settings.platform, platform); PLATFORM(settings1.platform, platform);
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings1, this);
std::istringstream istr(code); std::istringstream istr(code);
const std::string file_in = cpp ? "test.cpp" : "test.c"; const std::string file_in = cpp ? "test.cpp" : "test.c";
ASSERT_LOC(tokenizer.tokenize(istr, file_in.c_str()), file, line); ASSERT_LOC(tokenizer.tokenize(istr, file_in.c_str()), file, line);
// Check.. // Check..
CheckIO checkIO(&tokenizer, &settings, this); CheckIO checkIO(&tokenizer, &settings1, this);
checkIO.checkWrongPrintfScanfArguments(); checkIO.checkWrongPrintfScanfArguments();
if (!onlyFormatStr) { if (!onlyFormatStr) {
checkIO.checkCoutCerrMisusage(); checkIO.checkCoutCerrMisusage();

View File

@ -2654,7 +2654,7 @@ public:
TestLeakAutoVarRecursiveCountLimit() : TestFixture("TestLeakAutoVarRecursiveCountLimit") {} TestLeakAutoVarRecursiveCountLimit() : TestFixture("TestLeakAutoVarRecursiveCountLimit") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().library("std.cfg").checkLibrary().build();
void checkP(const char code[], bool cpp = false) { void checkP(const char code[], bool cpp = false) {
// Clear the error buffer.. // Clear the error buffer..
@ -2675,15 +2675,11 @@ private:
tokenizer.createTokens(std::move(tokens2)); tokenizer.createTokens(std::move(tokens2));
tokenizer.simplifyTokens1(""); tokenizer.simplifyTokens1("");
settings.checkLibrary = true;
// Check for leaks.. // Check for leaks..
runChecks<CheckLeakAutoVar>(&tokenizer, &settings, this); runChecks<CheckLeakAutoVar>(&tokenizer, &settings, this);
} }
void run() override { void run() override {
LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(recursiveCountLimit); // #5872 #6157 #9097 TEST_CASE(recursiveCountLimit); // #5872 #6157 #9097
} }
@ -2714,7 +2710,7 @@ public:
TestLeakAutoVarStrcpy() : TestFixture("TestLeakAutoVarStrcpy") {} TestLeakAutoVarStrcpy() : TestFixture("TestLeakAutoVarStrcpy") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().library("std.cfg").checkLibrary().build();
void check_(const char* file, int line, const char code[]) { void check_(const char* file, int line, const char code[]) {
// Clear the error buffer.. // Clear the error buffer..
@ -2725,15 +2721,11 @@ private:
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
settings.checkLibrary = true;
// Check for leaks.. // Check for leaks..
runChecks<CheckLeakAutoVar>(&tokenizer, &settings, this); runChecks<CheckLeakAutoVar>(&tokenizer, &settings, this);
} }
void run() override { void run() override {
LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(returnedValue); // #9298 TEST_CASE(returnedValue); // #9298
TEST_CASE(deallocuse2); TEST_CASE(deallocuse2);
TEST_CASE(fclose_false_positive); // #9575 TEST_CASE(fclose_false_positive); // #9575
@ -2778,7 +2770,7 @@ public:
TestLeakAutoVarWindows() : TestFixture("TestLeakAutoVarWindows") {} TestLeakAutoVarWindows() : TestFixture("TestLeakAutoVarWindows") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().library("windows.cfg").build();
void check_(const char* file, int line, const char code[]) { void check_(const char* file, int line, const char code[]) {
// Clear the error buffer.. // Clear the error buffer..
@ -2794,8 +2786,6 @@ private:
} }
void run() override { void run() override {
LOAD_LIB_2(settings.library, "windows.cfg");
TEST_CASE(heapDoubleFree); TEST_CASE(heapDoubleFree);
} }

View File

@ -41,7 +41,7 @@ public:
TestLibrary() : TestFixture("TestLibrary") {} TestLibrary() : TestFixture("TestLibrary") {}
private: private:
Settings settings; const Settings settings;
void run() override { void run() override {
TEST_CASE(isCompliantValidationExpression); TEST_CASE(isCompliantValidationExpression);

View File

@ -38,7 +38,7 @@ public:
TestMemleak() : TestFixture("TestMemleak") {} TestMemleak() : TestFixture("TestMemleak") {}
private: private:
Settings settings; const Settings settings;
void run() override { void run() override {
TEST_CASE(testFunctionReturnType); TEST_CASE(testFunctionReturnType);
@ -125,34 +125,25 @@ public:
TestMemleakInFunction() : TestFixture("TestMemleakInFunction") {} TestMemleakInFunction() : TestFixture("TestMemleakInFunction") {}
private: private:
Settings settings0; const Settings settings = settingsBuilder().library("std.cfg").library("posix.cfg").build();
Settings settings1;
Settings settings2;
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[]) { void check_(const char* file, int line, const char code[]) {
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings *settings = &settings1;
// Tokenize.. // Tokenize..
Tokenizer tokenizer(settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
// Check for memory leaks.. // Check for memory leaks..
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, settings, this); CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this);
checkMemoryLeak.checkReallocUsage(); checkMemoryLeak.checkReallocUsage();
} }
void run() override { void run() override {
LOAD_LIB_2(settings1.library, "std.cfg");
LOAD_LIB_2(settings1.library, "posix.cfg");
settings1.libraries.emplace_back("posix");
LOAD_LIB_2(settings2.library, "std.cfg");
TEST_CASE(realloc1); TEST_CASE(realloc1);
TEST_CASE(realloc2); TEST_CASE(realloc2);
TEST_CASE(realloc3); TEST_CASE(realloc3);
@ -470,7 +461,7 @@ public:
TestMemleakInClass() : TestFixture("TestMemleakInClass") {} TestMemleakInClass() : TestFixture("TestMemleakInClass") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).library("std.cfg").build();
/** /**
* Tokenize and execute leak check for given code * Tokenize and execute leak check for given code
@ -491,11 +482,6 @@ private:
} }
void run() override { void run() override {
settings.severity.enable(Severity::warning);
settings.severity.enable(Severity::style);
LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(class1); TEST_CASE(class1);
TEST_CASE(class2); TEST_CASE(class2);
TEST_CASE(class3); TEST_CASE(class3);
@ -1686,7 +1672,7 @@ public:
TestMemleakStructMember() : TestFixture("TestMemleakStructMember") {} TestMemleakStructMember() : TestFixture("TestMemleakStructMember") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().library("std.cfg").library("posix.cfg").build();
void check_(const char* file, int line, const char code[], bool isCPP = true) { void check_(const char* file, int line, const char code[], bool isCPP = true) {
// Clear the error buffer.. // Clear the error buffer..
@ -1703,10 +1689,6 @@ private:
} }
void run() override { void run() override {
LOAD_LIB_2(settings.library, "std.cfg");
LOAD_LIB_2(settings.library, "posix.cfg");
settings.libraries.emplace_back("posix");
// testing that errors are detected // testing that errors are detected
TEST_CASE(err); TEST_CASE(err);
@ -2274,7 +2256,7 @@ public:
TestMemleakNoVar() : TestFixture("TestMemleakNoVar") {} TestMemleakNoVar() : TestFixture("TestMemleakNoVar") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().certainty(Certainty::inconclusive).severity(Severity::warning).library("std.cfg").library("posix.cfg").build();
void check_(const char* file, int line, const char code[]) { void check_(const char* file, int line, const char code[]) {
// Clear the error buffer.. // Clear the error buffer..
@ -2291,13 +2273,6 @@ private:
} }
void run() override { void run() override {
settings.certainty.setEnabled(Certainty::inconclusive, true);
settings.severity.enable(Severity::warning);
LOAD_LIB_2(settings.library, "std.cfg");
LOAD_LIB_2(settings.library, "posix.cfg");
settings.libraries.emplace_back("posix");
// pass allocated memory to function.. // pass allocated memory to function..
TEST_CASE(functionParameter); TEST_CASE(functionParameter);

View File

@ -41,12 +41,9 @@ public:
TestNullPointer() : TestFixture("TestNullPointer") {} TestNullPointer() : TestFixture("TestNullPointer") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().library("std.cfg").severity(Severity::warning).build();
void run() override { void run() override {
LOAD_LIB_2(settings.library, "std.cfg");
settings.severity.enable(Severity::warning);
TEST_CASE(nullpointerAfterLoop); TEST_CASE(nullpointerAfterLoop);
TEST_CASE(nullpointer1); TEST_CASE(nullpointer1);
TEST_CASE(nullpointer2); TEST_CASE(nullpointer2);
@ -183,22 +180,22 @@ private:
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive); const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, inconclusive).build();
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings1, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
// Check for null pointer dereferences.. // Check for null pointer dereferences..
runChecks<CheckNullPointer>(&tokenizer, &settings, this); runChecks<CheckNullPointer>(&tokenizer, &settings1, this);
} }
void checkP(const char code[]) { void checkP(const char code[]) {
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
settings.certainty.setEnabled(Certainty::inconclusive, false); const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, false).build();
// Raw tokens.. // Raw tokens..
std::vector<std::string> files(1, "test.cpp"); std::vector<std::string> files(1, "test.cpp");
@ -211,12 +208,12 @@ private:
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI()); simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());
// Tokenizer.. // Tokenizer..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings1, this);
tokenizer.createTokens(std::move(tokens2)); tokenizer.createTokens(std::move(tokens2));
tokenizer.simplifyTokens1(""); tokenizer.simplifyTokens1("");
// Check for null pointer dereferences.. // Check for null pointer dereferences..
runChecks<CheckNullPointer>(&tokenizer, &settings, this); runChecks<CheckNullPointer>(&tokenizer, &settings1, this);
} }
@ -4052,7 +4049,7 @@ private:
} }
void functioncalllibrary() { void functioncalllibrary() {
Settings settings1; const Settings settings1;
Tokenizer tokenizer(&settings1,this); Tokenizer tokenizer(&settings1,this);
std::istringstream code("void f() { int a,b,c; x(a,b,c); }"); std::istringstream code("void f() { int a,b,c; x(a,b,c); }");
ASSERT_EQUALS(true, tokenizer.tokenize(code, "test.c")); ASSERT_EQUALS(true, tokenizer.tokenize(code, "test.c"));

View File

@ -25,18 +25,13 @@
class TestPathMatch : public TestFixture { class TestPathMatch : public TestFixture {
public: public:
TestPathMatch() TestPathMatch() : TestFixture("TestPathMatch") {}
: TestFixture("TestPathMatch")
, emptyMatcher(std::vector<std::string>())
, srcMatcher(std::vector<std::string>(1, "src/"))
, fooCppMatcher(std::vector<std::string>(1, "foo.cpp"))
, srcFooCppMatcher(std::vector<std::string>(1, "src/foo.cpp")) {}
private: private:
const PathMatch emptyMatcher; const PathMatch emptyMatcher{std::vector<std::string>()};
const PathMatch srcMatcher; const PathMatch srcMatcher{std::vector<std::string>(1, "src/")};
const PathMatch fooCppMatcher; const PathMatch fooCppMatcher{std::vector<std::string>(1, "foo.cpp")};
const PathMatch srcFooCppMatcher; const PathMatch srcFooCppMatcher{std::vector<std::string>(1, "src/foo.cpp")};
void run() override { void run() override {
TEST_CASE(emptymaskemptyfile); TEST_CASE(emptymaskemptyfile);

View File

@ -30,7 +30,7 @@ public:
TestPostfixOperator() : TestFixture("TestPostfixOperator") {} TestPostfixOperator() : TestFixture("TestPostfixOperator") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().severity(Severity::performance).build();
#define check(code) check_(code, __FILE__, __LINE__) #define check(code) check_(code, __FILE__, __LINE__)
void check_(const char code[], const char* file, int line) { void check_(const char code[], const char* file, int line) {
@ -48,8 +48,6 @@ private:
} }
void run() override { void run() override {
settings.severity.enable(Severity::performance);
TEST_CASE(testsimple); TEST_CASE(testsimple);
TEST_CASE(testfor); TEST_CASE(testfor);
TEST_CASE(testvolatile); TEST_CASE(testvolatile);

View File

@ -43,11 +43,7 @@ class ErrorLogger;
class TestPreprocessor : public TestFixture { class TestPreprocessor : public TestFixture {
public: public:
TestPreprocessor() TestPreprocessor() : TestFixture("TestPreprocessor") {}
: TestFixture("TestPreprocessor")
, preprocessor0(settings0, this) {
settings0.severity.enable(Severity::information);
}
class OurPreprocessor : public Preprocessor { class OurPreprocessor : public Preprocessor {
public: public:
@ -72,8 +68,8 @@ public:
}; };
private: private:
Settings settings0; Settings settings0 = settingsBuilder().severity(Severity::information).build();
Preprocessor preprocessor0; Preprocessor preprocessor0{settings0, this};
void run() override { void run() override {

View File

@ -37,14 +37,10 @@ public:
TestSimplifyTemplate() : TestFixture("TestSimplifyTemplate") {} TestSimplifyTemplate() : TestFixture("TestSimplifyTemplate") {}
private: private:
Settings settings; // If there are unused templates, keep those
const Settings settings = settingsBuilder().severity(Severity::portability).checkUnusedTemplates().build();
void run() override { void run() override {
settings.severity.enable(Severity::portability);
// If there are unused templates, keep those
settings.checkUnusedTemplates = true;
TEST_CASE(template1); TEST_CASE(template1);
TEST_CASE(template2); TEST_CASE(template2);
TEST_CASE(template3); TEST_CASE(template3);
@ -313,9 +309,9 @@ private:
std::string tok_(const char* file, int line, const char code[], bool debugwarnings = false, cppcheck::Platform::Type type = cppcheck::Platform::Type::Native) { std::string tok_(const char* file, int line, const char code[], bool debugwarnings = false, cppcheck::Platform::Type type = cppcheck::Platform::Type::Native) {
errout.str(""); errout.str("");
settings.debugwarnings = debugwarnings; Settings settings1 = settingsBuilder(settings).debugwarnings(debugwarnings).build();
PLATFORM(settings.platform, type); PLATFORM(settings1.platform, type);
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings1, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);

View File

@ -34,24 +34,13 @@ public:
private: private:
Settings settings0; // If there are unused templates, keep those
Settings settings1; const Settings settings0 = settingsBuilder().severity(Severity::portability).checkUnusedTemplates().build();
Settings settings_std; const Settings settings1 = settingsBuilder().severity(Severity::style).checkUnusedTemplates().build();
Settings settings_windows; const Settings settings_std = settingsBuilder().library("std.cfg").checkUnusedTemplates().build();
const Settings settings_windows = settingsBuilder().library("windows.cfg").severity(Severity::portability).checkUnusedTemplates().build();
void run() override { void run() override {
LOAD_LIB_2(settings_std.library, "std.cfg");
LOAD_LIB_2(settings_windows.library, "windows.cfg");
settings0.severity.enable(Severity::portability);
settings1.severity.enable(Severity::style);
settings_windows.severity.enable(Severity::portability);
// If there are unused templates, keep those
settings0.checkUnusedTemplates = true;
settings1.checkUnusedTemplates = true;
settings_std.checkUnusedTemplates = true;
settings_windows.checkUnusedTemplates = true;
TEST_CASE(combine_strings); TEST_CASE(combine_strings);
TEST_CASE(combine_wstrings); TEST_CASE(combine_wstrings);
TEST_CASE(combine_ustrings); TEST_CASE(combine_ustrings);
@ -178,14 +167,13 @@ private:
std::string tok_(const char* file, int line, const char code[], bool simplify = true, cppcheck::Platform::Type type = cppcheck::Platform::Type::Native) { std::string tok_(const char* file, int line, const char code[], bool simplify = true, cppcheck::Platform::Type type = cppcheck::Platform::Type::Native) {
errout.str(""); errout.str("");
PLATFORM(settings0.platform, type); Settings settings = settings0;
Tokenizer tokenizer(&settings0, this); PLATFORM(settings.platform, type);
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
(void)simplify;
return tokenizer.tokens()->stringifyList(nullptr, !simplify); return tokenizer.tokens()->stringifyList(nullptr, !simplify);
} }
@ -206,12 +194,12 @@ private:
std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool simplify = false, bool expand = true, cppcheck::Platform::Type platform = cppcheck::Platform::Type::Native, const char* filename = "test.cpp", bool cpp11 = true) { std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool simplify = false, bool expand = true, cppcheck::Platform::Type platform = cppcheck::Platform::Type::Native, const char* filename = "test.cpp", bool cpp11 = true) {
errout.str(""); errout.str("");
settings1.debugwarnings = true; Settings settings = settingsBuilder(settings1).debugwarnings().build();
PLATFORM(settings1.platform, platform); PLATFORM(settings.platform, platform);
settings1.standards.cpp = cpp11 ? Standards::CPP11 : Standards::CPP03; settings.standards.cpp = cpp11 ? Standards::CPP11 : Standards::CPP03;
// tokenize.. // tokenize..
Tokenizer tokenizer(&settings1, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr);

View File

@ -40,19 +40,12 @@ public:
private: private:
Settings settings0; // If there are unused templates, keep those
Settings settings1; const Settings settings0 = settingsBuilder().severity(Severity::style).checkUnusedTemplates().build();
Settings settings2; const Settings settings1 = settingsBuilder().checkUnusedTemplates().build();
const Settings settings2 = settingsBuilder().severity(Severity::style).checkUnusedTemplates().build();
void run() override { void run() override {
settings0.severity.enable(Severity::style);
settings2.severity.enable(Severity::style);
// If there are unused templates, keep those
settings0.checkUnusedTemplates = true;
settings1.checkUnusedTemplates = true;
settings2.checkUnusedTemplates = true;
TEST_CASE(c1); TEST_CASE(c1);
TEST_CASE(c2); TEST_CASE(c2);
TEST_CASE(canreplace1); TEST_CASE(canreplace1);
@ -234,10 +227,10 @@ private:
std::string tok_(const char* file, int line, const char code[], bool simplify = true, cppcheck::Platform::Type type = cppcheck::Platform::Type::Native, bool debugwarnings = true) { std::string tok_(const char* file, int line, const char code[], bool simplify = true, cppcheck::Platform::Type type = cppcheck::Platform::Type::Native, bool debugwarnings = true) {
errout.str(""); errout.str("");
settings0.certainty.enable(Certainty::inconclusive); // show warnings about unhandled typedef
settings0.debugwarnings = debugwarnings; // show warnings about unhandled typedef Settings settings = settingsBuilder(settings0).certainty(Certainty::inconclusive).debugwarnings(debugwarnings).build();
PLATFORM(settings0.platform, type); PLATFORM(settings.platform, type);
Tokenizer tokenizer(&settings0, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
@ -286,9 +279,9 @@ private:
void checkSimplifyTypedef_(const char code[], const char* file, int line) { void checkSimplifyTypedef_(const char code[], const char* file, int line) {
errout.str(""); errout.str("");
// Tokenize.. // Tokenize..
settings2.certainty.enable(Certainty::inconclusive); // show warnings about unhandled typedef
settings2.debugwarnings = true; // show warnings about unhandled typedef const Settings settings = settingsBuilder(settings2).certainty(Certainty::inconclusive).debugwarnings().build();
Tokenizer tokenizer(&settings2, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
} }

View File

@ -39,19 +39,12 @@ public:
private: private:
Settings settings0; // If there are unused templates, keep those
Settings settings1; const Settings settings0 = settingsBuilder().severity(Severity::style).checkUnusedTemplates().build();
Settings settings2; const Settings settings1 = settingsBuilder().checkUnusedTemplates().build();
const Settings settings2 = settingsBuilder().severity(Severity::style).checkUnusedTemplates().build();
void run() override { void run() override {
settings0.severity.enable(Severity::style);
settings2.severity.enable(Severity::style);
// If there are unused templates, keep those
settings0.checkUnusedTemplates = true;
settings1.checkUnusedTemplates = true;
settings2.checkUnusedTemplates = true;
TEST_CASE(simplifyUsing1); TEST_CASE(simplifyUsing1);
TEST_CASE(simplifyUsing2); TEST_CASE(simplifyUsing2);
TEST_CASE(simplifyUsing3); TEST_CASE(simplifyUsing3);
@ -107,10 +100,9 @@ private:
std::string tok_(const char* file, int line, const char code[], cppcheck::Platform::Type type = cppcheck::Platform::Type::Native, bool debugwarnings = true, bool preprocess = false) { std::string tok_(const char* file, int line, const char code[], cppcheck::Platform::Type type = cppcheck::Platform::Type::Native, bool debugwarnings = true, bool preprocess = false) {
errout.str(""); errout.str("");
settings0.certainty.enable(Certainty::inconclusive); Settings settings = settingsBuilder(settings0).certainty(Certainty::inconclusive).debugwarnings(debugwarnings).build();
settings0.debugwarnings = debugwarnings; PLATFORM(settings.platform, type);
PLATFORM(settings0.platform, type); Tokenizer tokenizer(&settings, this);
Tokenizer tokenizer(&settings0, this);
if (preprocess) { if (preprocess) {
std::vector<std::string> files{ "test.cpp" }; std::vector<std::string> files{ "test.cpp" };

View File

@ -36,13 +36,9 @@ public:
TestSizeof() : TestFixture("TestSizeof") {} TestSizeof() : TestFixture("TestSizeof") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).certainty(Certainty::inconclusive).build();
void run() override { void run() override {
settings.severity.enable(Severity::warning);
settings.severity.enable(Severity::portability);
settings.certainty.enable(Certainty::inconclusive);
TEST_CASE(sizeofsizeof); TEST_CASE(sizeofsizeof);
TEST_CASE(sizeofCalculation); TEST_CASE(sizeofCalculation);
TEST_CASE(sizeofFunction); TEST_CASE(sizeofFunction);

View File

@ -35,14 +35,9 @@ public:
TestStl() : TestFixture("TestStl") {} TestStl() : TestFixture("TestStl") {}
private: private:
Settings settings; Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library("std.cfg").build();
void run() override { void run() override {
settings.severity.enable(Severity::warning);
settings.severity.enable(Severity::style);
settings.severity.enable(Severity::performance);
LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(outOfBounds); TEST_CASE(outOfBounds);
TEST_CASE(outOfBoundsSymbolic); TEST_CASE(outOfBoundsSymbolic);
TEST_CASE(outOfBoundsIndexExpression); TEST_CASE(outOfBoundsIndexExpression);
@ -185,17 +180,15 @@ private:
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive); const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, inconclusive).cpp(cppstandard).build();
settings.standards.cpp = cppstandard;
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings1, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
runChecks<CheckStl>(&tokenizer, &settings, this); runChecks<CheckStl>(&tokenizer, &settings1, this);
} }
void check_(const char* file, int line, const std::string& code, const bool inconclusive = false) { void check_(const char* file, int line, const std::string& code, const bool inconclusive = false) {

View File

@ -32,12 +32,9 @@ public:
TestString() : TestFixture("TestString") {} TestString() : TestFixture("TestString") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).build();
void run() override { void run() override {
settings.severity.enable(Severity::warning);
settings.severity.enable(Severity::style);
TEST_CASE(stringLiteralWrite); TEST_CASE(stringLiteralWrite);
TEST_CASE(alwaysTrueFalseStringCompare); TEST_CASE(alwaysTrueFalseStringCompare);

View File

@ -44,7 +44,7 @@ private:
errout.str(""); errout.str("");
// tokenize.. // tokenize..
Settings settings; const Settings settings;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);

View File

@ -63,16 +63,14 @@ class TestSymbolDatabase;
class TestSymbolDatabase : public TestFixture { class TestSymbolDatabase : public TestFixture {
public: public:
TestSymbolDatabase() TestSymbolDatabase() : TestFixture("TestSymbolDatabase") {}
: TestFixture("TestSymbolDatabase")
,vartok(nullptr)
,typetok(nullptr) {}
private: private:
const Token* vartok; const Token* vartok{nullptr};
const Token* typetok; const Token* typetok{nullptr};
Settings settings1; // If there are unused templates, keep those
Settings settings2; Settings settings1 = settingsBuilder().library("std.cfg").checkUnusedTemplates().build();
Settings settings2 = settingsBuilder().checkUnusedTemplates().build();
void reset() { void reset() {
vartok = nullptr; vartok = nullptr;
@ -117,13 +115,8 @@ private:
} }
void run() override { void run() override {
LOAD_LIB_2(settings1.library, "std.cfg");
PLATFORM(settings2.platform, cppcheck::Platform::Type::Unspecified); PLATFORM(settings2.platform, cppcheck::Platform::Type::Unspecified);
// If there are unused templates, keep those
settings1.checkUnusedTemplates = true;
settings2.checkUnusedTemplates = true;
TEST_CASE(array); TEST_CASE(array);
TEST_CASE(array_ptr); TEST_CASE(array_ptr);
TEST_CASE(stlarray1); TEST_CASE(stlarray1);
@ -2311,17 +2304,15 @@ private:
errout.str(""); errout.str("");
// Check.. // Check..
settings1.debugwarnings = debug; const Settings settings = settingsBuilder(settings1).debugwarnings(debug).build();
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings1, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
// force symbol database creation // force symbol database creation
tokenizer.createSymbolDatabase(); tokenizer.createSymbolDatabase();
settings1.debugwarnings = false;
} }
void functionArgs1() { void functionArgs1() {

View File

@ -39,7 +39,7 @@ public:
TestThreadExecutor() : TestFixture("TestThreadExecutor") {} TestThreadExecutor() : TestFixture("TestThreadExecutor") {}
private: private:
Settings settings; Settings settings = settingsBuilder().library("std.cfg").build();
/** /**
* Execute check using n jobs for y files which are have * Execute check using n jobs for y files which are have
@ -64,12 +64,13 @@ private:
} }
} }
settings.jobs = jobs; Settings settings1 = settings;
settings.showtime = showtime; settings1.jobs = jobs;
settings1.showtime = showtime;
if (plistOutput) if (plistOutput)
settings.plistOutput = plistOutput; settings1.plistOutput = plistOutput;
// TODO: test with settings.project.fileSettings; // TODO: test with settings.project.fileSettings;
ThreadExecutor executor(filemap, settings, *this); ThreadExecutor executor(filemap, settings1, *this);
std::vector<std::unique_ptr<ScopedFile>> scopedfiles; std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
scopedfiles.reserve(filemap.size()); scopedfiles.reserve(filemap.size());
for (std::map<std::string, std::size_t>::const_iterator i = filemap.cbegin(); i != filemap.cend(); ++i) for (std::map<std::string, std::size_t>::const_iterator i = filemap.cbegin(); i != filemap.cend(); ++i)
@ -79,8 +80,6 @@ private:
} }
void run() override { void run() override {
LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(deadlock_with_many_errors); TEST_CASE(deadlock_with_many_errors);
TEST_CASE(many_threads); TEST_CASE(many_threads);
TEST_CASE(many_threads_showtime); TEST_CASE(many_threads_showtime);

View File

@ -135,7 +135,7 @@ private:
#define MatchCheck(...) MatchCheck_(__FILE__, __LINE__, __VA_ARGS__) #define MatchCheck(...) MatchCheck_(__FILE__, __LINE__, __VA_ARGS__)
bool MatchCheck_(const char* file, int line, const std::string& code, const std::string& pattern, unsigned int varid = 0) { bool MatchCheck_(const char* file, int line, const std::string& code, const std::string& pattern, unsigned int varid = 0) {
static const Settings settings; const Settings settings;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(";" + code + ";"); std::istringstream istr(";" + code + ";");
try { try {
@ -395,7 +395,7 @@ private:
void getStrSize() const { void getStrSize() const {
Token tok; Token tok;
Settings settings; const Settings settings;
tok.str("\"\""); tok.str("\"\"");
ASSERT_EQUALS(sizeof(""), Token::getStrSize(&tok, &settings)); ASSERT_EQUALS(sizeof(""), Token::getStrSize(&tok, &settings));

View File

@ -44,28 +44,13 @@ public:
TestTokenizer() : TestFixture("TestTokenizer") {} TestTokenizer() : TestFixture("TestTokenizer") {}
private: private:
Settings settings0; // If there are unused templates, keep those
Settings settings1; Settings settings0 = settingsBuilder().library("qt.cfg").checkUnusedTemplates().build();
Settings settings2; const Settings settings1 = settingsBuilder().library("qt.cfg").checkUnusedTemplates().build();
Settings settings_windows; const Settings settings2 = settingsBuilder().library("qt.cfg").checkUnusedTemplates().build();
const Settings settings_windows = settingsBuilder().library("windows.cfg").checkUnusedTemplates().build();
void run() override { void run() override {
LOAD_LIB_2(settings_windows.library, "windows.cfg");
// If there are unused templates, keep those
settings0.checkUnusedTemplates = true;
settings1.checkUnusedTemplates = true;
settings2.checkUnusedTemplates = true;
settings_windows.checkUnusedTemplates = true;
// library=qt
LOAD_LIB_2(settings0.library, "qt.cfg");
settings0.libraries.emplace_back("qt");
LOAD_LIB_2(settings1.library, "qt.cfg");
settings1.libraries.emplace_back("qt");
LOAD_LIB_2(settings2.library, "qt.cfg");
settings2.libraries.emplace_back("qt");
TEST_CASE(tokenize1); TEST_CASE(tokenize1);
TEST_CASE(tokenize2); TEST_CASE(tokenize2);
TEST_CASE(tokenize4); TEST_CASE(tokenize4);
@ -471,12 +456,11 @@ private:
std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool expand = true, cppcheck::Platform::Type platform = cppcheck::Platform::Type::Native, const char* filename = "test.cpp", Standards::cppstd_t std = Standards::CPP11) { std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool expand = true, cppcheck::Platform::Type platform = cppcheck::Platform::Type::Native, const char* filename = "test.cpp", Standards::cppstd_t std = Standards::CPP11) {
errout.str(""); errout.str("");
settings1.debugwarnings = true; Settings settings = settingsBuilder(settings1).debugwarnings().cpp(std).build();
PLATFORM(settings1.platform, platform); PLATFORM(settings.platform, platform);
settings1.standards.cpp = std;
// tokenize.. // tokenize..
Tokenizer tokenizer(&settings1, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr);
@ -500,12 +484,11 @@ private:
std::string tokenizeAndStringifyWindows_(const char* file, int linenr, const char code[], bool expand = true, cppcheck::Platform::Type platform = cppcheck::Platform::Type::Native, const char* filename = "test.cpp", bool cpp11 = true) { std::string tokenizeAndStringifyWindows_(const char* file, int linenr, const char code[], bool expand = true, cppcheck::Platform::Type platform = cppcheck::Platform::Type::Native, const char* filename = "test.cpp", bool cpp11 = true) {
errout.str(""); errout.str("");
settings_windows.debugwarnings = true; Settings settings = settingsBuilder(settings_windows).debugwarnings().cpp(cpp11 ? Standards::CPP11 : Standards::CPP03).build();
PLATFORM(settings_windows.platform, platform); PLATFORM(settings.platform, platform);
settings_windows.standards.cpp = cpp11 ? Standards::CPP11 : Standards::CPP03;
// tokenize.. // tokenize..
Tokenizer tokenizer(&settings_windows, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr);
@ -541,10 +524,9 @@ private:
std::string tokenizeDebugListing_(const char* file, int line, const char code[], const char filename[] = "test.cpp") { std::string tokenizeDebugListing_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
errout.str(""); errout.str("");
settings2.standards.c = Standards::C89; const Settings settings = settingsBuilder(settings2).c(Standards::C89).cpp(Standards::CPP03).build();
settings2.standards.cpp = Standards::CPP03;
Tokenizer tokenizer(&settings2, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);

View File

@ -30,7 +30,7 @@ public:
TestTokenList() : TestFixture("TestTokenList") {} TestTokenList() : TestFixture("TestTokenList") {}
private: private:
Settings settings; const Settings settings;
void run() override { void run() override {
TEST_CASE(testaddtoken1); TEST_CASE(testaddtoken1);
@ -40,17 +40,18 @@ private:
} }
// inspired by #5895 // inspired by #5895
void testaddtoken1() { void testaddtoken1() const {
const std::string code = "0x89504e470d0a1a0a"; const std::string code = "0x89504e470d0a1a0a";
TokenList tokenlist(&settings); TokenList tokenlist(&settings);
tokenlist.addtoken(code, 1, 1, false); tokenlist.addtoken(code, 1, 1, false);
ASSERT_EQUALS("0x89504e470d0a1a0a", tokenlist.front()->str()); ASSERT_EQUALS("0x89504e470d0a1a0a", tokenlist.front()->str());
} }
void testaddtoken2() { void testaddtoken2() const {
const std::string code = "0xF0000000"; const std::string code = "0xF0000000";
settings.platform.int_bit = 32; Settings settings1;
TokenList tokenlist(&settings); settings1.platform.int_bit = 32;
TokenList tokenlist(&settings1);
tokenlist.addtoken(code, 1, 1, false); tokenlist.addtoken(code, 1, 1, false);
ASSERT_EQUALS("0xF0000000", tokenlist.front()->str()); ASSERT_EQUALS("0xF0000000", tokenlist.front()->str());
} }
@ -68,7 +69,7 @@ private:
ASSERT(Token::simpleMatch(tokenlist.front(), "a + + 1 ; 1 + + b ;")); ASSERT(Token::simpleMatch(tokenlist.front(), "a + + 1 ; 1 + + b ;"));
} }
void isKeyword() { void isKeyword() const {
const char code[] = "for a int delete true"; const char code[] = "for a int delete true";

View File

@ -101,7 +101,7 @@ private:
} }
void scopeExample() const { void scopeExample() const {
Settings settings; const Settings settings;
Tokenizer tokenizer{ &settings, nullptr }; Tokenizer tokenizer{ &settings, nullptr };
std::istringstream sample("void a(){} void main(){ if(true){a();} }"); std::istringstream sample("void a(){} void main(){ if(true){a();} }");
ASSERT(tokenizer.tokenize(sample, "test.cpp")); ASSERT(tokenizer.tokenize(sample, "test.cpp"));

View File

@ -238,9 +238,8 @@ private:
} }
void checkIntegerOverflow() { void checkIntegerOverflow() {
Settings settings; Settings settings = settingsBuilder().severity(Severity::warning).build();
PLATFORM(settings.platform, cppcheck::Platform::Type::Unix32); PLATFORM(settings.platform, cppcheck::Platform::Type::Unix32);
settings.severity.enable(Severity::warning);
check("x = (int)0x10000 * (int)0x10000;", &settings); check("x = (int)0x10000 * (int)0x10000;", &settings);
ASSERT_EQUALS("[test.cpp:1]: (error) Signed integer overflow for expression '(int)0x10000*(int)0x10000'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) Signed integer overflow for expression '(int)0x10000*(int)0x10000'.\n", errout.str());
@ -331,8 +330,7 @@ private:
} }
void longCastAssign() { void longCastAssign() {
Settings settings; Settings settings = settingsBuilder().severity(Severity::style).build();
settings.severity.enable(Severity::style);
PLATFORM(settings.platform, cppcheck::Platform::Type::Unix64); PLATFORM(settings.platform, cppcheck::Platform::Type::Unix64);
check("long f(int x, int y) {\n" check("long f(int x, int y) {\n"
@ -363,8 +361,7 @@ private:
} }
void longCastReturn() { void longCastReturn() {
Settings settings; Settings settings = settingsBuilder().severity(Severity::style).build();
settings.severity.enable(Severity::style);
check("long f(int x, int y) {\n" check("long f(int x, int y) {\n"
" return x * y;\n" " return x * y;\n"

View File

@ -35,11 +35,9 @@ public:
TestUninitVar() : TestFixture("TestUninitVar") {} TestUninitVar() : TestFixture("TestUninitVar") {}
private: private:
Settings settings; Settings settings = settingsBuilder().library("std.cfg").build();
void run() override { void run() override {
LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(uninitvar1); TEST_CASE(uninitvar1);
TEST_CASE(uninitvar_warn_once); // only write 1 warning at a time TEST_CASE(uninitvar_warn_once); // only write 1 warning at a time
TEST_CASE(uninitvar_decl); // handling various types in C and C++ files TEST_CASE(uninitvar_decl); // handling various types in C and C++ files
@ -111,14 +109,15 @@ private:
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
const Settings settings1 = settingsBuilder(settings).debugwarnings(debugwarnings).build();
// Tokenize.. // Tokenize..
settings.debugwarnings = debugwarnings; Tokenizer tokenizer(&settings1, this);
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, fname), file, line); ASSERT_LOC(tokenizer.tokenize(istr, fname), file, line);
// Check for redundant code.. // Check for redundant code..
CheckUninitVar checkuninitvar(&tokenizer, &settings, this); CheckUninitVar checkuninitvar(&tokenizer, &settings1, this);
checkuninitvar.check(); checkuninitvar.check();
settings.debugwarnings = false; settings.debugwarnings = false;

View File

@ -31,11 +31,9 @@ public:
TestUnusedFunctions() : TestFixture("TestUnusedFunctions") {} TestUnusedFunctions() : TestFixture("TestUnusedFunctions") {}
private: private:
Settings settings; Settings settings = settingsBuilder().severity(Severity::style).build();
void run() override { void run() override {
settings.severity.enable(Severity::style);
TEST_CASE(incondition); TEST_CASE(incondition);
TEST_CASE(return1); TEST_CASE(return1);
TEST_CASE(return2); TEST_CASE(return2);

View File

@ -36,11 +36,9 @@ public:
TestUnusedPrivateFunction() : TestFixture("TestUnusedPrivateFunction") {} TestUnusedPrivateFunction() : TestFixture("TestUnusedPrivateFunction") {}
private: private:
Settings settings; Settings settings = settingsBuilder().severity(Severity::style).build();
void run() override { void run() override {
settings.severity.enable(Severity::style);
TEST_CASE(test1); TEST_CASE(test1);
TEST_CASE(test2); TEST_CASE(test2);
TEST_CASE(test3); TEST_CASE(test3);

View File

@ -37,13 +37,9 @@ public:
TestUnusedVar() : TestFixture("TestUnusedVar") {} TestUnusedVar() : TestFixture("TestUnusedVar") {}
private: private:
Settings settings; Settings settings = settingsBuilder().severity(Severity::style).checkLibrary().library("std.cfg").build();
void run() override { void run() override {
settings.severity.enable(Severity::style);
settings.checkLibrary = true;
LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(isRecordTypeWithoutSideEffects); TEST_CASE(isRecordTypeWithoutSideEffects);
TEST_CASE(cleanFunction); TEST_CASE(cleanFunction);

View File

@ -26,8 +26,6 @@
#include <limits> #include <limits>
#include <string> #include <string>
const Settings givenACodeSampleToTokenize::settings;
class TestUtils : public TestFixture { class TestUtils : public TestFixture {
public: public:
TestUtils() : TestFixture("TestUtils") {} TestUtils() : TestFixture("TestUtils") {}

View File

@ -31,7 +31,7 @@ public:
TestVaarg() : TestFixture("TestVaarg") {} TestVaarg() : TestFixture("TestVaarg") {}
private: private:
Settings settings; const Settings settings = settingsBuilder().severity(Severity::warning).build();
#define check(code) check_(code, __FILE__, __LINE__) #define check(code) check_(code, __FILE__, __LINE__)
void check_(const char code[], const char* file, int line) { void check_(const char code[], const char* file, int line) {
@ -48,8 +48,6 @@ private:
} }
void run() override { void run() override {
settings.severity.enable(Severity::warning);
TEST_CASE(wrongParameterTo_va_start); TEST_CASE(wrongParameterTo_va_start);
TEST_CASE(referenceAs_va_start); TEST_CASE(referenceAs_va_start);
TEST_CASE(va_end_missing); TEST_CASE(va_end_missing);

View File

@ -46,7 +46,7 @@ public:
TestValueFlow() : TestFixture("TestValueFlow") {} TestValueFlow() : TestFixture("TestValueFlow") {}
private: private:
Settings settings; Settings settings = settingsBuilder().library("std.cfg").build();
void run() override { void run() override {
// strcpy, abort cfg // strcpy, abort cfg
@ -56,7 +56,6 @@ private:
" <function name=\"abort\"> <noreturn>true</noreturn> </function>\n" // abort is a noreturn function " <function name=\"abort\"> <noreturn>true</noreturn> </function>\n" // abort is a noreturn function
"</def>"; "</def>";
ASSERT_EQUALS(true, settings.library.loadxmldata(cfg, sizeof(cfg))); ASSERT_EQUALS(true, settings.library.loadxmldata(cfg, sizeof(cfg)));
LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(valueFlowNumber); TEST_CASE(valueFlowNumber);
TEST_CASE(valueFlowString); TEST_CASE(valueFlowString);
@ -6572,8 +6571,7 @@ private:
void valueFlowSafeFunctionParameterValues() { void valueFlowSafeFunctionParameterValues() {
const char *code; const char *code;
std::list<ValueFlow::Value> values; std::list<ValueFlow::Value> values;
Settings s; Settings s = settingsBuilder().library("std.cfg").build();
LOAD_LIB_2(s.library, "std.cfg");
s.safeChecks.classes = s.safeChecks.externalFunctions = s.safeChecks.internalFunctions = true; s.safeChecks.classes = s.safeChecks.externalFunctions = s.safeChecks.internalFunctions = true;
code = "short f(short x) {\n" code = "short f(short x) {\n"
@ -6624,8 +6622,7 @@ private:
void valueFlowUnknownFunctionReturn() { void valueFlowUnknownFunctionReturn() {
const char *code; const char *code;
std::list<ValueFlow::Value> values; std::list<ValueFlow::Value> values;
Settings s; Settings s = settingsBuilder().library("std.cfg").build();
LOAD_LIB_2(s.library, "std.cfg");
s.checkUnknownFunctionReturn.insert("rand"); s.checkUnknownFunctionReturn.insert("rand");
code = "x = rand();"; code = "x = rand();";

View File

@ -31,16 +31,13 @@
class TestVarID : public TestFixture { class TestVarID : public TestFixture {
public: public:
TestVarID() : TestFixture("TestVarID") { TestVarID() : TestFixture("TestVarID") {}
PLATFORM(settings.platform, cppcheck::Platform::Type::Unix64);
settings.standards.c = Standards::C89;
settings.standards.cpp = Standards::CPPLatest;
settings.checkUnusedTemplates = true;
}
private: private:
Settings settings; Settings settings = settingsBuilder().c(Standards::C89).cpp(Standards::CPPLatest).checkUnusedTemplates().build();
void run() override { void run() override {
PLATFORM(settings.platform, cppcheck::Platform::Type::Unix64);
TEST_CASE(varid1); TEST_CASE(varid1);
TEST_CASE(varid2); TEST_CASE(varid2);
TEST_CASE(varid3); TEST_CASE(varid3);