Skip to content

Commit

Permalink
Nits
Browse files Browse the repository at this point in the history
  • Loading branch information
olabetskyi committed Aug 30, 2024
1 parent 0ef5641 commit c131239
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 146 deletions.
11 changes: 2 additions & 9 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,6 @@ unsigned int CppCheck::check(const FileSettings &fs)
// TODO: move to constructor when CppCheck no longer owns the settings
if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck)
mUnusedFunctionsCheck.reset(new CheckUnusedFunctions());
if (!Path::isFile(fs.filename)) {
std::string fixedpath = Path::simplifyPath(fs.filename);
fixedpath = Path::toNativeSeparators(fixedpath);
const std::string errorMsg("File " + fixedpath + " does not exists. Skipping file.");
fileNotFoundError(fs.filename, errorMsg);
return 0;
}
CppCheck temp(mErrorLogger, mUseGlobalSuppressions, mExecuteCommand);
temp.mSettings = mSettings;
if (!temp.mSettings.userDefines.empty())
Expand Down Expand Up @@ -708,7 +701,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
if (mSettings.relativePaths)
locfile = Path::getRelativePath(locfile, mSettings.basePaths);
if(output.type == simplecpp::Output::Type::FILE_NOT_FOUND){
const std::string fixedpath = Path::toNativeSeparators(file);
const std::string fixedpath = Path::toNativeSeparators(file.path());
const std::string errorMsg("File " + fixedpath + " does not exists. Skipping file.");

reportErr(ErrorMessage(std::list<ErrorMessage::FileLocation> (),
Expand All @@ -719,7 +712,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
Certainty::normal));
}
else{
reportErr(makeError(file, output.location.line, output.location.col, output.msg, "syntaxError"));
reportErr(makeError(file.path(), output.location.line, output.location.col, output.msg, "syntaxError"));
}
return mExitCode;
}
Expand Down
3 changes: 0 additions & 3 deletions lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
/** @brief There has been an internal error => Report information message */
void internalError(const std::string &filename, const std::string &msg);

/** @brief File is missing => Report information message */
void fileNotFoundError(const std::string &filename, const std::string &msg);

/**
* @brief Check a file using stream
* @param file the file
Expand Down
123 changes: 0 additions & 123 deletions test/cli/invalid-project/invalid-project.vcxproj

This file was deleted.

133 changes: 130 additions & 3 deletions test/cli/more-projects_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,9 +865,136 @@ def test_shared_items_project(tmpdir = ""):
assert any('2/2 files checked 100% done' in x for x in lines)
assert stderr == ''

import shutil

def test_project_missing_files():
filename = os.path.join('invalid-project', 'main.c')
ret, _, stderr = cppcheck(['--template=cppcheck1', '--project=' + os.path.join('invalid-project', 'invalid-project.vcxproj')])
def test_project_missing_files(tmpdir):
filename = os.path.join(tmpdir, 'main.c')
project_file = os.path.join(tmpdir, 'helloworld.vcxproj')
with open(project_file, 'wt') as f:
f.write(
"""<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{7319858B-261C-4F0D-B022-92BB896242DD}</ProjectGuid>
<RootNamespace>invalidProjet</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>""")
ret, _, stderr = cppcheck(['--template=cppcheck1', '--project=' + os.path.join(tmpdir, 'helloworld.vcxproj')])
assert ret == 0
assert stderr == ': (error) File {} does not exists. Skipping file.\n'.format(filename)
2 changes: 1 addition & 1 deletion test/testcppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class TestCppcheck : public TestFixture {
{
ErrorLogger2 errorLogger;
CppCheck cppcheck(errorLogger, false, {});
ASSERT_EQUALS(1, cppcheck.check("NotAFile"));
ASSERT_EQUALS(1, cppcheck.check(FileWithDetails("NotAFile")));

ASSERT_EQUALS(1, errorLogger.ids.size());
ASSERT_EQUALS("fileNotFound", *errorLogger.ids.cbegin());
Expand Down
16 changes: 9 additions & 7 deletions test/testsuppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,9 +1190,10 @@ class TestSuppressions : public TestFixture {
ASSERT_EQUALS("", settings.supprs.nomsg.addSuppressionLine("uninitvar"));
settings.exitCode = 1;

const char code[] = "int f() { int a; return a; }";
ASSERT_EQUALS(0, cppCheck.check("test.c", code)); // <- no unsuppressed error is seen
ASSERT_EQUALS("[test.c:1]: (error) Uninitialized variable: a\n", errout.str()); // <- report error so ThreadExecutor can suppress it and make sure the global suppression is matched.
ScopedFile file("test.c", "int f() { int a; return a; }");
FileSettings fs{file.path()};
ASSERT_EQUALS(0, cppCheck.check(fs)); // <- no unsuppressed error is seen
ASSERT_EQUALS("[test.c:1]: (error) Uninitialized variable: a\n", errout_str()); // <- report error so ThreadExecutor can suppress it and make sure the global suppression is matched.
}

void inlinesuppress_unusedFunction() const { // #4210, #4946 - wrong report of "unmatchedSuppression" for "unusedFunction"
Expand Down Expand Up @@ -1223,16 +1224,17 @@ class TestSuppressions : public TestFixture {
settings.inlineSuppressions = true;
settings.relativePaths = true;
settings.basePaths.emplace_back("/somewhere");
const char code[] =
ScopedFile file("test.cpp",
"struct Point\n"
"{\n"
" // cppcheck-suppress unusedStructMember\n"
" int x;\n"
" // cppcheck-suppress unusedStructMember\n"
" int y;\n"
"};";
ASSERT_EQUALS(0, cppCheck.check("/somewhere/test.cpp", code));
ASSERT_EQUALS("",errout.str());
"};");
FileSettings fs{file.path()};
ASSERT_EQUALS(0, cppCheck.check(fs));
ASSERT_EQUALS("", errout_str());
}

void suppressingSyntaxErrorsInternal(unsigned int (TestSuppressions::*check)(const char[], const std::string &)) { // syntaxErrors should be suppressible (#7076)
Expand Down

0 comments on commit c131239

Please sign in to comment.