Skip to content

Commit 4714c5e

Browse files
committed
run tests on actual project
1 parent 1d324a2 commit 4714c5e

8 files changed

Lines changed: 322 additions & 0 deletions

File tree

test/cli/slnx-folders/app/app.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "../lib/lib.h"
2+
3+
int main(int argc, char *argv[])
4+
{
5+
int x = 3 / 0; (void)x; // ERROR
6+
return foo();
7+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|x64">
5+
<Configuration>Debug</Configuration>
6+
<Platform>x64</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|x64">
9+
<Configuration>Release</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<VCProjectVersion>18.0</VCProjectVersion>
15+
<Keyword>Win32Proj</Keyword>
16+
<ProjectGuid>{0de77c38-881a-4f9f-bdfa-2c429968985e}</ProjectGuid>
17+
<RootNamespace>unused</RootNamespace>
18+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
21+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
22+
<ConfigurationType>Application</ConfigurationType>
23+
<UseDebugLibraries>true</UseDebugLibraries>
24+
<PlatformToolset>v145</PlatformToolset>
25+
<CharacterSet>Unicode</CharacterSet>
26+
</PropertyGroup>
27+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
28+
<ConfigurationType>Application</ConfigurationType>
29+
<UseDebugLibraries>false</UseDebugLibraries>
30+
<PlatformToolset>v145</PlatformToolset>
31+
<WholeProgramOptimization>true</WholeProgramOptimization>
32+
<CharacterSet>Unicode</CharacterSet>
33+
</PropertyGroup>
34+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
35+
<ImportGroup Label="ExtensionSettings">
36+
</ImportGroup>
37+
<ImportGroup Label="Shared">
38+
</ImportGroup>
39+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
40+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
41+
</ImportGroup>
42+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
43+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
44+
</ImportGroup>
45+
<PropertyGroup Label="UserMacros" />
46+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
47+
<OutDir>..\x64\Debug\</OutDir>
48+
<IntDir>x64\Debug\</IntDir>
49+
</PropertyGroup>
50+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
51+
<OutDir>..\x64\Release\</OutDir>
52+
<IntDir>x64\Release\</IntDir>
53+
</PropertyGroup>
54+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
55+
<ClCompile>
56+
<WarningLevel>Level3</WarningLevel>
57+
<SDLCheck>true</SDLCheck>
58+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
59+
<ConformanceMode>true</ConformanceMode>
60+
<LanguageStandard>stdcpp20</LanguageStandard>
61+
<AdditionalIncludeDirectories>
62+
</AdditionalIncludeDirectories>
63+
</ClCompile>
64+
<Link>
65+
<SubSystem>Console</SubSystem>
66+
<GenerateDebugInformation>true</GenerateDebugInformation>
67+
<AdditionalLibraryDirectories>../lib</AdditionalLibraryDirectories>
68+
</Link>
69+
<Manifest>
70+
<EnableSegmentHeap>true</EnableSegmentHeap>
71+
</Manifest>
72+
</ItemDefinitionGroup>
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
74+
<ClCompile>
75+
<WarningLevel>Level3</WarningLevel>
76+
<FunctionLevelLinking>true</FunctionLevelLinking>
77+
<IntrinsicFunctions>true</IntrinsicFunctions>
78+
<SDLCheck>true</SDLCheck>
79+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
80+
<ConformanceMode>true</ConformanceMode>
81+
<LanguageStandard>stdcpp20</LanguageStandard>
82+
</ClCompile>
83+
<Link>
84+
<SubSystem>Console</SubSystem>
85+
<GenerateDebugInformation>true</GenerateDebugInformation>
86+
</Link>
87+
<Manifest>
88+
<EnableSegmentHeap>true</EnableSegmentHeap>
89+
</Manifest>
90+
</ItemDefinitionGroup>
91+
<ItemGroup>
92+
<ClCompile Include="app.cpp" />
93+
</ItemGroup>
94+
<ItemGroup>
95+
<ProjectReference Include="..\lib\lib.vcxproj">
96+
<Project>{93BE1430-BE74-35DF-1882-AF70E49C9898}</Project>
97+
</ProjectReference>
98+
</ItemGroup>
99+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
100+
<ImportGroup Label="ExtensionTargets">
101+
</ImportGroup>
102+
</Project>

test/cli/slnx-folders/lib/lib.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <iostream>
2+
#include "lib.h"
3+
4+
int foo()
5+
{
6+
std::cout << "hello world\n";
7+
int x = 3 / 0; (void)x; // ERROR
8+
return 0;
9+
}

test/cli/slnx-folders/lib/lib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extern int foo();
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|x64">
5+
<Configuration>Debug</Configuration>
6+
<Platform>x64</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|x64">
9+
<Configuration>Release</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<VCProjectVersion>18.0</VCProjectVersion>
15+
<Keyword>Win32Proj</Keyword>
16+
<ProjectGuid>{93BE1430-BE74-35DF-1882-AF70E49C9898}</ProjectGuid>
17+
<RootNamespace>unused</RootNamespace>
18+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
21+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
22+
<ConfigurationType>StaticLibrary</ConfigurationType>
23+
<UseDebugLibraries>true</UseDebugLibraries>
24+
<PlatformToolset>v145</PlatformToolset>
25+
<CharacterSet>Unicode</CharacterSet>
26+
</PropertyGroup>
27+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
28+
<ConfigurationType>StaticLibrary</ConfigurationType>
29+
<UseDebugLibraries>false</UseDebugLibraries>
30+
<PlatformToolset>v145</PlatformToolset>
31+
<WholeProgramOptimization>true</WholeProgramOptimization>
32+
<CharacterSet>Unicode</CharacterSet>
33+
</PropertyGroup>
34+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
35+
<ImportGroup Label="ExtensionSettings">
36+
</ImportGroup>
37+
<ImportGroup Label="Shared">
38+
</ImportGroup>
39+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
40+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
41+
</ImportGroup>
42+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
43+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
44+
</ImportGroup>
45+
<PropertyGroup Label="UserMacros" />
46+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
47+
<OutDir>..\x64\Debug\</OutDir>
48+
<IntDir>x64\Debug\</IntDir>
49+
</PropertyGroup>
50+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
51+
<OutDir>..\x64\Release\</OutDir>
52+
<IntDir>x64\Release\</IntDir>
53+
</PropertyGroup>
54+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
55+
<ClCompile>
56+
<WarningLevel>Level3</WarningLevel>
57+
<SDLCheck>true</SDLCheck>
58+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
59+
<ConformanceMode>true</ConformanceMode>
60+
<LanguageStandard>stdcpp20</LanguageStandard>
61+
<AdditionalIncludeDirectories>
62+
</AdditionalIncludeDirectories>
63+
</ClCompile>
64+
<Link>
65+
<SubSystem>Console</SubSystem>
66+
<GenerateDebugInformation>true</GenerateDebugInformation>
67+
<AdditionalLibraryDirectories>../lib</AdditionalLibraryDirectories>
68+
</Link>
69+
<Manifest>
70+
<EnableSegmentHeap>true</EnableSegmentHeap>
71+
</Manifest>
72+
</ItemDefinitionGroup>
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
74+
<ClCompile>
75+
<WarningLevel>Level3</WarningLevel>
76+
<FunctionLevelLinking>true</FunctionLevelLinking>
77+
<IntrinsicFunctions>true</IntrinsicFunctions>
78+
<SDLCheck>true</SDLCheck>
79+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
80+
<ConformanceMode>true</ConformanceMode>
81+
<LanguageStandard>stdcpp20</LanguageStandard>
82+
</ClCompile>
83+
<Link>
84+
<SubSystem>Console</SubSystem>
85+
<GenerateDebugInformation>true</GenerateDebugInformation>
86+
</Link>
87+
<Manifest>
88+
<EnableSegmentHeap>true</EnableSegmentHeap>
89+
</Manifest>
90+
</ItemDefinitionGroup>
91+
<ItemGroup>
92+
<ClCompile Include="lib.cpp" />
93+
</ItemGroup>
94+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
95+
<ImportGroup Label="ExtensionTargets">
96+
</ImportGroup>
97+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project version="1">
3+
<builddir>slnx-folders-cppcheck-build-dir</builddir>
4+
<importproject>slnx-folders.slnx</importproject>
5+
<analyze-all-vs-configs>false</analyze-all-vs-configs>
6+
<check-headers>true</check-headers>
7+
<check-unused-templates>true</check-unused-templates>
8+
<inline-suppression>true</inline-suppression>
9+
<max-ctu-depth>2</max-ctu-depth>
10+
<max-template-recursion>100</max-template-recursion>
11+
<vs-configurations>
12+
<config>Debug</config>
13+
<config>Release</config>
14+
</vs-configurations>
15+
<check-level-normal/>
16+
<project-name>slnx-folders</project-name>
17+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Solution>
2+
<Configurations>
3+
<Platform Name="x64" />
4+
</Configurations>
5+
<Folder Name="/Lib/">
6+
<File Path="lib/lib.h" />
7+
<Project Path="lib\lib.vcxproj" />
8+
</Folder>
9+
<Folder Name="/App/">
10+
<Project Path="app\app.vcxproj" Id="0de77c38-881a-4f9f-bdfa-2c429968985e" />
11+
</Folder>
12+
</Solution>

test/cli/slnx-folders_test.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
# python -m pytest slnx-folders_test.py
3+
4+
import os
5+
import re
6+
import glob
7+
import json
8+
import shutil
9+
import xml.etree.ElementTree as ET
10+
11+
import pytest
12+
13+
from testutils import create_gui_project_file, cppcheck
14+
15+
__script_dir = os.path.dirname(os.path.abspath(__file__))
16+
__proj_dir = os.path.join(__script_dir, 'slnx-folders')
17+
18+
19+
# Get Visual Studio configurations checking a file
20+
# Checking {file} {config}...
21+
def __getVsConfigs(stdout, filename):
22+
ret = []
23+
for line in stdout.split('\n'):
24+
if not line.startswith('Checking %s ' % filename):
25+
continue
26+
if not line.endswith('...'):
27+
continue
28+
res = re.match(r'.* ([A-Za-z0-9|]+)...', line)
29+
if res:
30+
ret.append(res.group(1))
31+
ret.sort()
32+
return ' '.join(ret)
33+
34+
def test_relative_path():
35+
args = [
36+
'--template=cppcheck1',
37+
'slnx-folders'
38+
]
39+
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
40+
filename1 = os.path.join('slnx-folders', 'app', 'app.cpp')
41+
filename2 = os.path.join('slnx-folders', 'lib', 'lib.cpp')
42+
assert ret == 0, stdout
43+
expected = (
44+
'[%s:5]: (error) Division by zero.\n'
45+
'[%s:7]: (error) Division by zero.\n' % (filename1, filename2)
46+
)
47+
assert stderr == expected
48+
49+
def test_local_path():
50+
args = [
51+
'--template=cppcheck1',
52+
'.'
53+
]
54+
ret, stdout, stderr = cppcheck(args, cwd=__proj_dir)
55+
filename1 = os.path.join('app', 'app.cpp')
56+
filename2 = os.path.join('lib', 'lib.cpp')
57+
assert ret == 0, stdout
58+
expected = (
59+
'[%s:5]: (error) Division by zero.\n'
60+
'[%s:7]: (error) Division by zero.\n' % (filename1, filename2)
61+
)
62+
assert stderr == expected
63+
64+
def test_absolute_path():
65+
args = [
66+
'--template=cppcheck1',
67+
__proj_dir
68+
]
69+
ret, stdout, stderr = cppcheck(args)
70+
filename1 = os.path.join(__proj_dir, 'app', 'app.cpp')
71+
filename2 = os.path.join(__proj_dir, 'lib', 'lib.cpp')
72+
assert ret == 0, stdout
73+
expected = (
74+
'[%s:5]: (error) Division by zero.\n'
75+
'[%s:7]: (error) Division by zero.\n' % (filename1, filename2)
76+
)
77+
assert stderr == expected

0 commit comments

Comments
 (0)