Merge branch 'ignore-paths-cli'
This commit is contained in:
commit
ffc4bb481b
14
Makefile
14
Makefile
|
@ -52,6 +52,7 @@ CLIOBJ = cli/cmdlineparser.o \
|
||||||
cli/filelister_unix.o \
|
cli/filelister_unix.o \
|
||||||
cli/filelister_win32.o \
|
cli/filelister_win32.o \
|
||||||
cli/main.o \
|
cli/main.o \
|
||||||
|
cli/pathmatch.o \
|
||||||
cli/threadexecutor.o
|
cli/threadexecutor.o
|
||||||
|
|
||||||
TESTOBJ = test/options.o \
|
TESTOBJ = test/options.o \
|
||||||
|
@ -74,6 +75,7 @@ TESTOBJ = test/options.o \
|
||||||
test/testoptions.o \
|
test/testoptions.o \
|
||||||
test/testother.o \
|
test/testother.o \
|
||||||
test/testpath.o \
|
test/testpath.o \
|
||||||
|
test/testpathmatch.o \
|
||||||
test/testpostfixoperator.o \
|
test/testpostfixoperator.o \
|
||||||
test/testpreprocessor.o \
|
test/testpreprocessor.o \
|
||||||
test/testrunner.o \
|
test/testrunner.o \
|
||||||
|
@ -103,8 +105,8 @@ cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)
|
||||||
|
|
||||||
all: cppcheck testrunner
|
all: cppcheck testrunner
|
||||||
|
|
||||||
testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/filelister_unix.o
|
testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/filelister_unix.o cli/pathmatch.o
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/filelister.o cli/filelister_unix.o $(LDFLAGS)
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/filelister.o cli/filelister_unix.o cli/pathmatch.o $(LDFLAGS)
|
||||||
|
|
||||||
test: all
|
test: all
|
||||||
./testrunner
|
./testrunner
|
||||||
|
@ -206,7 +208,7 @@ lib/tokenize.o: lib/tokenize.cpp lib/tokenize.h lib/token.h lib/mathlib.h lib/se
|
||||||
cli/cmdlineparser.o: cli/cmdlineparser.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/timer.h cli/cmdlineparser.h lib/path.h
|
cli/cmdlineparser.o: cli/cmdlineparser.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/timer.h cli/cmdlineparser.h lib/path.h
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Iexternals -c -o cli/cmdlineparser.o cli/cmdlineparser.cpp
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Iexternals -c -o cli/cmdlineparser.o cli/cmdlineparser.cpp
|
||||||
|
|
||||||
cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h cli/threadexecutor.h cli/cmdlineparser.h cli/filelister.h lib/path.h
|
cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h cli/threadexecutor.h cli/cmdlineparser.h cli/filelister.h lib/path.h cli/pathmatch.h
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Iexternals -c -o cli/cppcheckexecutor.o cli/cppcheckexecutor.cpp
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Iexternals -c -o cli/cppcheckexecutor.o cli/cppcheckexecutor.cpp
|
||||||
|
|
||||||
cli/filelister.o: cli/filelister.cpp cli/filelister.h cli/filelister_win32.h cli/filelister_unix.h
|
cli/filelister.o: cli/filelister.cpp cli/filelister.h cli/filelister_win32.h cli/filelister_unix.h
|
||||||
|
@ -221,6 +223,9 @@ cli/filelister_win32.o: cli/filelister_win32.cpp cli/filelister.h cli/filelister
|
||||||
cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h
|
cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Iexternals -c -o cli/main.o cli/main.cpp
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Iexternals -c -o cli/main.o cli/main.cpp
|
||||||
|
|
||||||
|
cli/pathmatch.o: cli/pathmatch.cpp cli/pathmatch.h
|
||||||
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Iexternals -c -o cli/pathmatch.o cli/pathmatch.cpp
|
||||||
|
|
||||||
cli/threadexecutor.o: cli/threadexecutor.cpp cli/threadexecutor.h lib/settings.h lib/errorlogger.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h
|
cli/threadexecutor.o: cli/threadexecutor.cpp cli/threadexecutor.h lib/settings.h lib/errorlogger.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Iexternals -c -o cli/threadexecutor.o cli/threadexecutor.cpp
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Iexternals -c -o cli/threadexecutor.o cli/threadexecutor.cpp
|
||||||
|
|
||||||
|
@ -284,6 +289,9 @@ test/testother.o: test/testother.cpp lib/tokenize.h lib/checkother.h lib/check.h
|
||||||
test/testpath.o: test/testpath.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/path.h
|
test/testpath.o: test/testpath.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/path.h
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testpath.o test/testpath.cpp
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testpath.o test/testpath.cpp
|
||||||
|
|
||||||
|
test/testpathmatch.o: test/testpathmatch.cpp test/testsuite.h lib/errorlogger.h test/redirect.h
|
||||||
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testpathmatch.o test/testpathmatch.cpp
|
||||||
|
|
||||||
test/testpostfixoperator.o: test/testpostfixoperator.cpp lib/tokenize.h lib/checkpostfixoperator.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
|
test/testpostfixoperator.o: test/testpostfixoperator.cpp lib/tokenize.h lib/checkpostfixoperator.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testpostfixoperator.o test/testpostfixoperator.cpp
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -Ilib -Icli -Iexternals -c -o test/testpostfixoperator.o test/testpostfixoperator.cpp
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,15 @@ SOURCES += main.cpp \
|
||||||
filelister.cpp \
|
filelister.cpp \
|
||||||
filelister_unix.cpp \
|
filelister_unix.cpp \
|
||||||
filelister_win32.cpp \
|
filelister_win32.cpp \
|
||||||
|
pathmatch.cpp \
|
||||||
threadexecutor.cpp
|
threadexecutor.cpp
|
||||||
|
|
||||||
HEADERS += cppcheckexecutor.h \
|
HEADERS += cppcheckexecutor.h \
|
||||||
cmdlineparser.h \
|
cmdlineparser.h \
|
||||||
filelister.h \
|
filelister.h \
|
||||||
filelister_unix.h \
|
filelister_unix.h \
|
||||||
filelister_win32.h \
|
filelister_win32.h \
|
||||||
|
pathmatch.h \
|
||||||
threadexecutor.h
|
threadexecutor.h
|
||||||
|
|
||||||
CONFIG(release, debug|release) {
|
CONFIG(release, debug|release) {
|
||||||
|
|
|
@ -344,6 +344,41 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
AddFilesToList(12 + argv[i], _pathnames);
|
AddFilesToList(12 + argv[i], _pathnames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignored paths
|
||||||
|
else if (strncmp(argv[i], "-i", 2) == 0)
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
|
||||||
|
// "-i path/"
|
||||||
|
if (strcmp(argv[i], "-i") == 0)
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
if (i >= argc)
|
||||||
|
{
|
||||||
|
PrintMessage("cppcheck: argument to '-i' is missing");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
path = argv[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// "-Ipath/"
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path = 2 + argv[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!path.empty())
|
||||||
|
{
|
||||||
|
path = Path::fromNativeSeparators(path);
|
||||||
|
|
||||||
|
// If path doesn't end with / or \, add it
|
||||||
|
if (path[path.length()-1] != '/')
|
||||||
|
path += '/';
|
||||||
|
|
||||||
|
_ignoredPaths.push_back(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Report progress
|
// Report progress
|
||||||
else if (strcmp(argv[i], "--report-progress") == 0)
|
else if (strcmp(argv[i], "--report-progress") == 0)
|
||||||
{
|
{
|
||||||
|
@ -606,6 +641,9 @@ void CmdLineParser::PrintHelp()
|
||||||
" -I [dir] Give include path. Give several -I parameters to give\n"
|
" -I [dir] Give include path. Give several -I parameters to give\n"
|
||||||
" several paths. First given path is checked first. If\n"
|
" several paths. First given path is checked first. If\n"
|
||||||
" paths are relative to source files, this is not needed\n"
|
" paths are relative to source files, this is not needed\n"
|
||||||
|
" -i [dir] Give path to ignore. Give several -i parameters to ignore\n"
|
||||||
|
" several paths. If any part of the checked path matches the\n"
|
||||||
|
" given dir the path is ignored and not checked.\n"
|
||||||
" --inline-suppr Enable inline suppressions. Use them by placing one or\n"
|
" --inline-suppr Enable inline suppressions. Use them by placing one or\n"
|
||||||
" more comments, like: // cppcheck-suppress warningId\n"
|
" more comments, like: // cppcheck-suppress warningId\n"
|
||||||
" on the lines before the warning to suppress.\n"
|
" on the lines before the warning to suppress.\n"
|
||||||
|
|
|
@ -92,6 +92,14 @@ public:
|
||||||
return _exitAfterPrint;
|
return _exitAfterPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a list of paths user wants to ignore.
|
||||||
|
*/
|
||||||
|
std::vector<std::string> GetIgnoredPaths() const
|
||||||
|
{
|
||||||
|
return _ignoredPaths;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,6 +119,7 @@ private:
|
||||||
bool _showErrorMessages;
|
bool _showErrorMessages;
|
||||||
bool _exitAfterPrint;
|
bool _exitAfterPrint;
|
||||||
std::vector<std::string> _pathnames;
|
std::vector<std::string> _pathnames;
|
||||||
|
std::vector<std::string> _ignoredPaths;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
ProjectType="Visual C++"
|
ProjectType="Visual C++"
|
||||||
Version="9,00"
|
Version="9,00"
|
||||||
Name="cppcheck"
|
Name="cppcheck"
|
||||||
ProjectGUID="{7E69D6C6-32B2-32E1-BF56-A5BFBAF5E61F}"
|
ProjectGUID="{56B0F403-02CE-3F89-9A1B-E03F21240A63}"
|
||||||
Keyword="Qt4VSv1.0">
|
Keyword="Qt4VSv1.0">
|
||||||
<Platforms>
|
<Platforms>
|
||||||
<Platform
|
<Platform
|
||||||
|
@ -169,6 +169,8 @@
|
||||||
RelativePath="..\lib\mathlib.cpp" />
|
RelativePath="..\lib\mathlib.cpp" />
|
||||||
<File
|
<File
|
||||||
RelativePath="..\lib\path.cpp" />
|
RelativePath="..\lib\path.cpp" />
|
||||||
|
<File
|
||||||
|
RelativePath="pathmatch.cpp" />
|
||||||
<File
|
<File
|
||||||
RelativePath="..\lib\preprocessor.cpp" />
|
RelativePath="..\lib\preprocessor.cpp" />
|
||||||
<File
|
<File
|
||||||
|
@ -242,6 +244,8 @@
|
||||||
RelativePath="..\lib\mathlib.h" />
|
RelativePath="..\lib\mathlib.h" />
|
||||||
<File
|
<File
|
||||||
RelativePath="..\lib\path.h" />
|
RelativePath="..\lib\path.h" />
|
||||||
|
<File
|
||||||
|
RelativePath="pathmatch.h" />
|
||||||
<File
|
<File
|
||||||
RelativePath="..\lib\preprocessor.h" />
|
RelativePath="..\lib\preprocessor.h" />
|
||||||
<File
|
<File
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
</ProjectConfiguration>
|
</ProjectConfiguration>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{42BC0E8E-9175-3B2D-B8B3-9EC5C36EF49A}</ProjectGuid>
|
<ProjectGuid>{A6DACC3F-847F-3498-9415-164FBC746D6B}</ProjectGuid>
|
||||||
<RootNamespace>cppcheck</RootNamespace>
|
<RootNamespace>cppcheck</RootNamespace>
|
||||||
<Keyword>Qt4VSv1.0</Keyword>
|
<Keyword>Qt4VSv1.0</Keyword>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -140,6 +140,7 @@
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
<ClCompile Include="..\lib\mathlib.cpp" />
|
<ClCompile Include="..\lib\mathlib.cpp" />
|
||||||
<ClCompile Include="..\lib\path.cpp" />
|
<ClCompile Include="..\lib\path.cpp" />
|
||||||
|
<ClCompile Include="pathmatch.cpp" />
|
||||||
<ClCompile Include="..\lib\preprocessor.cpp" />
|
<ClCompile Include="..\lib\preprocessor.cpp" />
|
||||||
<ClCompile Include="..\lib\settings.cpp" />
|
<ClCompile Include="..\lib\settings.cpp" />
|
||||||
<ClCompile Include="..\lib\symboldatabase.cpp" />
|
<ClCompile Include="..\lib\symboldatabase.cpp" />
|
||||||
|
@ -176,6 +177,7 @@
|
||||||
<ClInclude Include="filelister_win32.h" />
|
<ClInclude Include="filelister_win32.h" />
|
||||||
<ClInclude Include="..\lib\mathlib.h" />
|
<ClInclude Include="..\lib\mathlib.h" />
|
||||||
<ClInclude Include="..\lib\path.h" />
|
<ClInclude Include="..\lib\path.h" />
|
||||||
|
<ClInclude Include="pathmatch.h" />
|
||||||
<ClInclude Include="..\lib\preprocessor.h" />
|
<ClInclude Include="..\lib\preprocessor.h" />
|
||||||
<ClInclude Include="resource.h" />
|
<ClInclude Include="resource.h" />
|
||||||
<ClInclude Include="..\lib\settings.h" />
|
<ClInclude Include="..\lib\settings.h" />
|
||||||
|
|
|
@ -84,6 +84,9 @@
|
||||||
<ClCompile Include="..\lib\path.cpp">
|
<ClCompile Include="..\lib\path.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="pathmatch.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\lib\preprocessor.cpp">
|
<ClCompile Include="..\lib\preprocessor.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -188,6 +191,9 @@
|
||||||
<ClInclude Include="..\lib\path.h">
|
<ClInclude Include="..\lib\path.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="pathmatch.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="..\lib\preprocessor.h">
|
<ClInclude Include="..\lib\preprocessor.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "cmdlineparser.h"
|
#include "cmdlineparser.h"
|
||||||
#include "filelister.h"
|
#include "filelister.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
#include "pathmatch.h"
|
||||||
|
|
||||||
CppCheckExecutor::CppCheckExecutor()
|
CppCheckExecutor::CppCheckExecutor()
|
||||||
{
|
{
|
||||||
|
@ -87,19 +88,36 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
|
||||||
std::vector<std::string>::const_iterator iter;
|
std::vector<std::string>::const_iterator iter;
|
||||||
for (iter = pathnames.begin(); iter != pathnames.end(); ++iter)
|
for (iter = pathnames.begin(); iter != pathnames.end(); ++iter)
|
||||||
getFileLister()->recursiveAddFiles(filenames, Path::toNativeSeparators(iter->c_str()));
|
getFileLister()->recursiveAddFiles(filenames, Path::toNativeSeparators(iter->c_str()));
|
||||||
|
|
||||||
for (iter = filenames.begin(); iter != filenames.end(); ++iter)
|
|
||||||
cppcheck->addFile(*iter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filenames.empty())
|
if (!filenames.empty())
|
||||||
|
{
|
||||||
|
PathMatch matcher(parser.GetIgnoredPaths());
|
||||||
|
std::vector<std::string>::iterator iterBegin = filenames.begin();
|
||||||
|
for (int i = (int)filenames.size() - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (matcher.Match(filenames[i]))
|
||||||
|
filenames.erase(iterBegin + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
std::cout << "cppcheck: error: could not find or open any of the paths given." << std::endl;
|
std::cout << "cppcheck: error: could not find or open any of the paths given." << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!filenames.empty())
|
||||||
|
{
|
||||||
|
std::vector<std::string>::iterator iter;
|
||||||
|
for (iter = filenames.begin(); iter != filenames.end(); ++iter)
|
||||||
|
cppcheck->addFile(*iter);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return true;
|
std::cout << "cppcheck: error: no files to check - all paths ignored." << std::endl;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Cppcheck - A tool for static C/C++ code analysis
|
||||||
|
* Copyright (C) 2007-2011 Daniel Marjamäki and Cppcheck team.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pathmatch.h"
|
||||||
|
|
||||||
|
PathMatch::PathMatch(const std::vector<std::string> &masks)
|
||||||
|
: _masks(masks)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PathMatch::Match(const std::string &path)
|
||||||
|
{
|
||||||
|
if (path.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::vector<std::string>::const_iterator iterMask;
|
||||||
|
for (iterMask = _masks.begin(); iterMask != _masks.end(); ++iterMask)
|
||||||
|
{
|
||||||
|
std::string findpath(path);
|
||||||
|
if (findpath[findpath.length() - 1] != '/')
|
||||||
|
findpath = RemoveFilename(findpath);
|
||||||
|
|
||||||
|
if (findpath.find(*iterMask) != std::string::npos)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PathMatch::RemoveFilename(const std::string &path)
|
||||||
|
{
|
||||||
|
const size_t ind = path.find_last_of('/');
|
||||||
|
return path.substr(0, ind + 1);
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Cppcheck - A tool for static C/C++ code analysis
|
||||||
|
* Copyright (C) 2007-2011 Daniel Marjamäki and Cppcheck team.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PATHMATCH_H
|
||||||
|
#define PATHMATCH_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
/// @addtogroup CLI
|
||||||
|
/// @{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Simple path matching for ignoring paths in CLI.
|
||||||
|
*/
|
||||||
|
class PathMatch
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constructor.
|
||||||
|
* @param masks List of masks.
|
||||||
|
*/
|
||||||
|
PathMatch(const std::vector<std::string> &masks);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Match path against list of masks.
|
||||||
|
* @param path Path to match.
|
||||||
|
* @return true if any of the masks match the path, false otherwise.
|
||||||
|
*/
|
||||||
|
bool Match(const std::string &path);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Remove filename part from the path.
|
||||||
|
* @param path Path to edit.
|
||||||
|
* @return path without filename part.
|
||||||
|
*/
|
||||||
|
std::string RemoveFilename(const std::string &path);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::string> _masks;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
#endif // PATHMATCH_H
|
150
test/test.pro
150
test/test.pro
|
@ -1,73 +1,77 @@
|
||||||
|
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
TARGET = test
|
TARGET = test
|
||||||
DEPENDPATH += .
|
DEPENDPATH += .
|
||||||
INCLUDEPATH += . ../cli ../lib
|
INCLUDEPATH += . ../cli ../lib
|
||||||
OBJECTS_DIR = temp
|
OBJECTS_DIR = temp
|
||||||
CONFIG += warn_on console
|
CONFIG += warn_on console
|
||||||
CONFIG -= qt app_bundle
|
CONFIG -= qt app_bundle
|
||||||
win32 {
|
win32 {
|
||||||
LIBS += -lshlwapi
|
LIBS += -lshlwapi
|
||||||
}
|
}
|
||||||
|
|
||||||
BASEPATH = ../externals/tinyxml/
|
BASEPATH = ../externals/tinyxml/
|
||||||
include(../externals/tinyxml/tinyxml.pri)
|
include(../externals/tinyxml/tinyxml.pri)
|
||||||
BASEPATH = ../lib/
|
BASEPATH = ../lib/
|
||||||
include(../lib/lib.pri)
|
include(../lib/lib.pri)
|
||||||
|
|
||||||
# cli/*
|
# cli/*
|
||||||
SOURCES += ../cli/cmdlineparser.cpp \
|
SOURCES += ../cli/cmdlineparser.cpp \
|
||||||
../cli/cppcheckexecutor.cpp \
|
../cli/cppcheckexecutor.cpp \
|
||||||
../cli/filelister.cpp \
|
../cli/filelister.cpp \
|
||||||
../cli/filelister_unix.cpp \
|
../cli/filelister_unix.cpp \
|
||||||
../cli/filelister_win32.cpp \
|
../cli/filelister_win32.cpp \
|
||||||
../cli/threadexecutor.cpp
|
../cli/pathmatch.cpp \
|
||||||
HEADERS += ../cli/cmdlineparser.h \
|
../cli/threadexecutor.cpp \
|
||||||
../cli/cppcheckexecutor.h \
|
testpathmatch.cpp
|
||||||
../cli/filelister.h \
|
HEADERS += ../cli/cmdlineparser.h \
|
||||||
../cli/filelister_unix.h \
|
../cli/cppcheckexecutor.h \
|
||||||
../cli/filelister_win32.h \
|
../cli/filelister.h \
|
||||||
../cli/threadexecutor.h
|
../cli/filelister_unix.h \
|
||||||
|
../cli/filelister_win32.h \
|
||||||
# test/*
|
../cli/pathmatch.h \
|
||||||
HEADERS += options.h redirect.h testsuite.h
|
../cli/threadexecutor.h
|
||||||
SOURCES += options.cpp \
|
|
||||||
testautovariables.cpp \
|
# test/*
|
||||||
testbufferoverrun.cpp \
|
HEADERS += options.h redirect.h testsuite.h
|
||||||
testcharvar.cpp \
|
SOURCES += options.cpp \
|
||||||
testclass.cpp \
|
testautovariables.cpp \
|
||||||
testcmdlineparser.cpp \
|
testbufferoverrun.cpp \
|
||||||
testconstructors.cpp \
|
testcharvar.cpp \
|
||||||
testcppcheck.cpp \
|
testclass.cpp \
|
||||||
testdivision.cpp \
|
testcmdlineparser.cpp \
|
||||||
testerrorlogger.cpp \
|
testconstructors.cpp \
|
||||||
testexceptionsafety.cpp \
|
testcppcheck.cpp \
|
||||||
testincompletestatement.cpp \
|
testdivision.cpp \
|
||||||
testmathlib.cpp \
|
testerrorlogger.cpp \
|
||||||
testmemleak.cpp \
|
testexceptionsafety.cpp \
|
||||||
testnullpointer.cpp \
|
testincompletestatement.cpp \
|
||||||
testobsoletefunctions.cpp \
|
testmathlib.cpp \
|
||||||
testoptions.cpp \
|
testmemleak.cpp \
|
||||||
testother.cpp \
|
testnullpointer.cpp \
|
||||||
testpath.cpp \
|
testobsoletefunctions.cpp \
|
||||||
testpostfixoperator.cpp \
|
testoptions.cpp \
|
||||||
testpreprocessor.cpp \
|
testother.cpp \
|
||||||
testrunner.cpp \
|
testpath.cpp \
|
||||||
testsettings.cpp \
|
testpathmatch.cpp \
|
||||||
testsimplifytokens.cpp \
|
testpostfixoperator.cpp \
|
||||||
teststl.cpp \
|
testpreprocessor.cpp \
|
||||||
testsuite.cpp \
|
testrunner.cpp \
|
||||||
testthreadexecutor.cpp \
|
testsettings.cpp \
|
||||||
testtoken.cpp \
|
testsimplifytokens.cpp \
|
||||||
testtokenize.cpp \
|
teststl.cpp \
|
||||||
testuninitvar.cpp \
|
testsuite.cpp \
|
||||||
testunusedfunctions.cpp \
|
testthreadexecutor.cpp \
|
||||||
testunusedprivfunc.cpp \
|
testtoken.cpp \
|
||||||
testunusedvar.cpp
|
testtokenize.cpp \
|
||||||
|
testuninitvar.cpp \
|
||||||
# Change Visual Studio compiler (CL) warning level to W4
|
testunusedfunctions.cpp \
|
||||||
contains(QMAKE_CXX, cl) {
|
testunusedprivfunc.cpp \
|
||||||
QMAKE_CXXFLAGS_WARN_ON -= -W3
|
testunusedvar.cpp
|
||||||
QMAKE_CXXFLAGS_WARN_ON += -W4
|
|
||||||
DEFINES += _CRT_SECURE_NO_WARNINGS
|
# Change Visual Studio compiler (CL) warning level to W4
|
||||||
}
|
contains(QMAKE_CXX, cl) {
|
||||||
|
QMAKE_CXXFLAGS_WARN_ON -= -W3
|
||||||
|
QMAKE_CXXFLAGS_WARN_ON += -W4
|
||||||
|
DEFINES += _CRT_SECURE_NO_WARNINGS
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
ProjectType="Visual C++"
|
ProjectType="Visual C++"
|
||||||
Version="9,00"
|
Version="9,00"
|
||||||
Name="test"
|
Name="test"
|
||||||
ProjectGUID="{48110A35-C2BB-3F1C-A741-C15295041A2D}"
|
ProjectGUID="{5B7869EA-A1CB-3E73-8569-5B385608779E}"
|
||||||
Keyword="Qt4VSv1.0">
|
Keyword="Qt4VSv1.0">
|
||||||
<Platforms>
|
<Platforms>
|
||||||
<Platform
|
<Platform
|
||||||
|
@ -72,7 +72,7 @@
|
||||||
UseOfMfc="0">
|
UseOfMfc="0">
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
AdditionalIncludeDirectories="".","..\cli","..\lib","..\externals",c:\Qt\VS4.7.0\mkspecs\win32-msvc2008"
|
AdditionalIncludeDirectories="".","..\cli","..\lib","..\externals",..\..\..\..\Qt\qt-everywhere-opensource-src-4.7.1-vs2008-x86\mkspecs\win32-msvc2008"
|
||||||
AdditionalOptions="-Zm200 -w34100 -w34189"
|
AdditionalOptions="-Zm200 -w34100 -w34189"
|
||||||
AssemblerListingLocation="temp\"
|
AssemblerListingLocation="temp\"
|
||||||
BufferSecurityCheck="false"
|
BufferSecurityCheck="false"
|
||||||
|
@ -169,6 +169,8 @@
|
||||||
RelativePath="options.cpp" />
|
RelativePath="options.cpp" />
|
||||||
<File
|
<File
|
||||||
RelativePath="..\lib\path.cpp" />
|
RelativePath="..\lib\path.cpp" />
|
||||||
|
<File
|
||||||
|
RelativePath="..\cli\pathmatch.cpp" />
|
||||||
<File
|
<File
|
||||||
RelativePath="..\lib\preprocessor.cpp" />
|
RelativePath="..\lib\preprocessor.cpp" />
|
||||||
<File
|
<File
|
||||||
|
@ -211,6 +213,8 @@
|
||||||
RelativePath="testother.cpp" />
|
RelativePath="testother.cpp" />
|
||||||
<File
|
<File
|
||||||
RelativePath="testpath.cpp" />
|
RelativePath="testpath.cpp" />
|
||||||
|
<File
|
||||||
|
RelativePath="testpathmatch.cpp" />
|
||||||
<File
|
<File
|
||||||
RelativePath="testpostfixoperator.cpp" />
|
RelativePath="testpostfixoperator.cpp" />
|
||||||
<File
|
<File
|
||||||
|
@ -308,6 +312,8 @@
|
||||||
RelativePath="options.h" />
|
RelativePath="options.h" />
|
||||||
<File
|
<File
|
||||||
RelativePath="..\lib\path.h" />
|
RelativePath="..\lib\path.h" />
|
||||||
|
<File
|
||||||
|
RelativePath="..\cli\pathmatch.h" />
|
||||||
<File
|
<File
|
||||||
RelativePath="..\lib\preprocessor.h" />
|
RelativePath="..\lib\preprocessor.h" />
|
||||||
<File
|
<File
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
</ProjectConfiguration>
|
</ProjectConfiguration>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{081168BA-E630-3D82-8EDB-A19028999479}</ProjectGuid>
|
<ProjectGuid>{D0001948-3B19-3314-8BEE-3B92350BC5B5}</ProjectGuid>
|
||||||
<RootNamespace>test</RootNamespace>
|
<RootNamespace>test</RootNamespace>
|
||||||
<Keyword>Qt4VSv1.0</Keyword>
|
<Keyword>Qt4VSv1.0</Keyword>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -140,6 +140,7 @@
|
||||||
<ClCompile Include="..\lib\mathlib.cpp" />
|
<ClCompile Include="..\lib\mathlib.cpp" />
|
||||||
<ClCompile Include="options.cpp" />
|
<ClCompile Include="options.cpp" />
|
||||||
<ClCompile Include="..\lib\path.cpp" />
|
<ClCompile Include="..\lib\path.cpp" />
|
||||||
|
<ClCompile Include="..\cli\pathmatch.cpp" />
|
||||||
<ClCompile Include="..\lib\preprocessor.cpp" />
|
<ClCompile Include="..\lib\preprocessor.cpp" />
|
||||||
<ClCompile Include="..\lib\settings.cpp" />
|
<ClCompile Include="..\lib\settings.cpp" />
|
||||||
<ClCompile Include="..\lib\symboldatabase.cpp" />
|
<ClCompile Include="..\lib\symboldatabase.cpp" />
|
||||||
|
@ -161,6 +162,7 @@
|
||||||
<ClCompile Include="testoptions.cpp" />
|
<ClCompile Include="testoptions.cpp" />
|
||||||
<ClCompile Include="testother.cpp" />
|
<ClCompile Include="testother.cpp" />
|
||||||
<ClCompile Include="testpath.cpp" />
|
<ClCompile Include="testpath.cpp" />
|
||||||
|
<ClCompile Include="testpathmatch.cpp" />
|
||||||
<ClCompile Include="testpostfixoperator.cpp" />
|
<ClCompile Include="testpostfixoperator.cpp" />
|
||||||
<ClCompile Include="testpreprocessor.cpp" />
|
<ClCompile Include="testpreprocessor.cpp" />
|
||||||
<ClCompile Include="testrunner.cpp" />
|
<ClCompile Include="testrunner.cpp" />
|
||||||
|
@ -209,6 +211,7 @@
|
||||||
<ClInclude Include="..\lib\mathlib.h" />
|
<ClInclude Include="..\lib\mathlib.h" />
|
||||||
<ClInclude Include="options.h" />
|
<ClInclude Include="options.h" />
|
||||||
<ClInclude Include="..\lib\path.h" />
|
<ClInclude Include="..\lib\path.h" />
|
||||||
|
<ClInclude Include="..\cli\pathmatch.h" />
|
||||||
<ClInclude Include="..\lib\preprocessor.h" />
|
<ClInclude Include="..\lib\preprocessor.h" />
|
||||||
<ClInclude Include="redirect.h" />
|
<ClInclude Include="redirect.h" />
|
||||||
<ClInclude Include="..\lib\settings.h" />
|
<ClInclude Include="..\lib\settings.h" />
|
||||||
|
|
|
@ -80,6 +80,9 @@
|
||||||
<ClCompile Include="..\lib\path.cpp">
|
<ClCompile Include="..\lib\path.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\cli\pathmatch.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\lib\preprocessor.cpp">
|
<ClCompile Include="..\lib\preprocessor.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -143,6 +146,9 @@
|
||||||
<ClCompile Include="testpath.cpp">
|
<ClCompile Include="testpath.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="testpathmatch.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="testpostfixoperator.cpp">
|
<ClCompile Include="testpostfixoperator.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -283,6 +289,9 @@
|
||||||
<ClInclude Include="..\lib\path.h">
|
<ClInclude Include="..\lib\path.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\cli\pathmatch.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="..\lib\preprocessor.h">
|
<ClInclude Include="..\lib\preprocessor.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
@ -90,6 +90,11 @@ private:
|
||||||
TEST_CASE(errorlist1);
|
TEST_CASE(errorlist1);
|
||||||
TEST_CASE(errorlistverbose1)
|
TEST_CASE(errorlistverbose1)
|
||||||
TEST_CASE(errorlistverbose2)
|
TEST_CASE(errorlistverbose2)
|
||||||
|
TEST_CASE(ignorepathsnopath)
|
||||||
|
TEST_CASE(ignorepaths1)
|
||||||
|
TEST_CASE(ignorepaths2)
|
||||||
|
TEST_CASE(ignorepaths3)
|
||||||
|
TEST_CASE(ignorepaths4)
|
||||||
TEST_CASE(unknownParam);
|
TEST_CASE(unknownParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -679,6 +684,62 @@ private:
|
||||||
ASSERT(settings._verbose);
|
ASSERT(settings._verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ignorepathsnopath()
|
||||||
|
{
|
||||||
|
REDIRECT;
|
||||||
|
const char *argv[] = {"cppcheck", "-i"};
|
||||||
|
Settings settings;
|
||||||
|
CmdLineParser parser(&settings);
|
||||||
|
ASSERT(!parser.ParseFromArgs(2, argv));
|
||||||
|
ASSERT_EQUALS(0, parser.GetIgnoredPaths().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ignorepaths1()
|
||||||
|
{
|
||||||
|
REDIRECT;
|
||||||
|
const char *argv[] = {"cppcheck", "-isrc", "file.cpp"};
|
||||||
|
Settings settings;
|
||||||
|
CmdLineParser parser(&settings);
|
||||||
|
ASSERT(parser.ParseFromArgs(3, argv));
|
||||||
|
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size());
|
||||||
|
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ignorepaths2()
|
||||||
|
{
|
||||||
|
REDIRECT;
|
||||||
|
const char *argv[] = {"cppcheck", "-i", "src", "file.cpp"};
|
||||||
|
Settings settings;
|
||||||
|
CmdLineParser parser(&settings);
|
||||||
|
ASSERT(parser.ParseFromArgs(4, argv));
|
||||||
|
ASSERT_EQUALS(1, parser.GetIgnoredPaths().size());
|
||||||
|
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ignorepaths3()
|
||||||
|
{
|
||||||
|
REDIRECT;
|
||||||
|
const char *argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"};
|
||||||
|
Settings settings;
|
||||||
|
CmdLineParser parser(&settings);
|
||||||
|
ASSERT(parser.ParseFromArgs(4, argv));
|
||||||
|
ASSERT_EQUALS(2, parser.GetIgnoredPaths().size());
|
||||||
|
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]);
|
||||||
|
ASSERT_EQUALS("module/", parser.GetIgnoredPaths()[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ignorepaths4()
|
||||||
|
{
|
||||||
|
REDIRECT;
|
||||||
|
const char *argv[] = {"cppcheck", "-i", "src", "-i", "module", "file.cpp"};
|
||||||
|
Settings settings;
|
||||||
|
CmdLineParser parser(&settings);
|
||||||
|
ASSERT(parser.ParseFromArgs(6, argv));
|
||||||
|
ASSERT_EQUALS(2, parser.GetIgnoredPaths().size());
|
||||||
|
ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]);
|
||||||
|
ASSERT_EQUALS("module/", parser.GetIgnoredPaths()[1]);
|
||||||
|
}
|
||||||
|
|
||||||
void unknownParam()
|
void unknownParam()
|
||||||
{
|
{
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
|
|
|
@ -0,0 +1,160 @@
|
||||||
|
/*
|
||||||
|
* Cppcheck - A tool for static C/C++ code analysis
|
||||||
|
* Copyright (C) 2007-2011 Daniel Marjamäki and Cppcheck team.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include "testsuite.h"
|
||||||
|
#include "pathmatch.h"
|
||||||
|
|
||||||
|
class TestPathMatch : public TestFixture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestPathMatch() : TestFixture("TestPathMatch")
|
||||||
|
{ }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void run()
|
||||||
|
{
|
||||||
|
TEST_CASE(emptymaskemptyfile);
|
||||||
|
TEST_CASE(emptymaskpath1);
|
||||||
|
TEST_CASE(emptymaskpath2);
|
||||||
|
TEST_CASE(emptymaskpath3);
|
||||||
|
TEST_CASE(onemaskemptypath);
|
||||||
|
TEST_CASE(onemasksamepath);
|
||||||
|
TEST_CASE(onemasksamepathwithfile);
|
||||||
|
TEST_CASE(onemasklongerpath1);
|
||||||
|
TEST_CASE(onemasklongerpath2);
|
||||||
|
TEST_CASE(onemasklongerpath3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void emptymaskemptyfile()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(!match.Match(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
void emptymaskpath1()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(!match.Match("src/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void emptymaskpath2()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(!match.Match("../src/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void emptymaskpath3()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(!match.Match("/home/user/code/src/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void onemaskemptypath()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(!match.Match(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
void onemasksamepath()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(match.Match("src/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void onemasksamepathwithfile()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(match.Match("src/file.txt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void onemasklongerpath1()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(match.Match("/tmp/src/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void onemasklongerpath2()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(match.Match("src/module/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void onemasklongerpath3()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(match.Match("project/src/module/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void twomasklongerpath1()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
masks.push_back("module/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(!match.Match("project/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void twomasklongerpath2()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
masks.push_back("module/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(match.Match("project/src/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void twomasklongerpath3()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
masks.push_back("module/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(match.Match("project/module/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void twomasklongerpath4()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
masks.push_back("module/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(match.Match("project/src/module/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
REGISTER_TEST(TestPathMatch)
|
|
@ -230,8 +230,8 @@ int main(int argc, char **argv)
|
||||||
fout << "cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)\n";
|
fout << "cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)\n";
|
||||||
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o cppcheck $(CLIOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre $(LDFLAGS)\n\n";
|
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o cppcheck $(CLIOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre $(LDFLAGS)\n\n";
|
||||||
fout << "all:\tcppcheck testrunner\n\n";
|
fout << "all:\tcppcheck testrunner\n\n";
|
||||||
fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/filelister_unix.o\n";
|
fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/filelister_unix.o cli/pathmatch.o\n";
|
||||||
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/filelister.o cli/filelister_unix.o $(LDFLAGS)\n\n";
|
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/filelister.o cli/filelister_unix.o cli/pathmatch.o $(LDFLAGS)\n\n";
|
||||||
fout << "test:\tall\n";
|
fout << "test:\tall\n";
|
||||||
fout << "\t./testrunner\n\n";
|
fout << "\t./testrunner\n\n";
|
||||||
fout << "check:\tall\n";
|
fout << "check:\tall\n";
|
||||||
|
|
Loading…
Reference in New Issue