-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathprops_dirs_test.py
More file actions
78 lines (62 loc) · 3.3 KB
/
Copy pathprops_dirs_test.py
File metadata and controls
78 lines (62 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# python -m pytest props_dirs_test.py
#
# Regression coverage for MSBuild property-sheet (.props) loading across multiple
# directories:
# - $(MSBuildThisFileDirectory) must resolve to each .props file's own directory,
# not the importing project's directory, even through a chain of nested imports
# (ProjA/ -> shared/shared.props -> common/common.props).
# - AdditionalIncludeDirectories set via that chain must actually make a header in a
# different directory (common/common.h) resolvable from the project's source file.
# - A project that imports common/common.props directly (ProjB) must pick up exactly
# what that file sets and nothing that a *different* project in the same solution
# (ProjA) added on top - no cross-project variable leakage.
import os
from testutils import cppcheck
__script_dir = os.path.dirname(os.path.abspath(__file__))
__ERR_A = ('%s:10:14: error: Division by zero. [zerodiv]\n'
' return x / 0;\n'
' ^\n') % os.path.join('props-dirs', 'ProjA', 'a.cpp')
__ERR_B = ('%s:10:14: error: Division by zero. [zerodiv]\n'
' return y / 0;\n'
' ^\n') % os.path.join('props-dirs', 'ProjB', 'b.cpp')
def __get_lines(s):
# file order is not guaranteed when multiple jobs are used (TEST_CPPCHECK_INJECT_J) so
# compare output order-independently
return sorted(s.split('\n'))
def test_props_dirs_solution():
args = [
'--project=props-dirs/props-dirs.slnx',
'--no-cppcheck-build-dir'
]
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
assert ret == 0, stdout
# both files were actually analyzed (division by zero fires) which also proves
# "common.h" was found via AdditionalIncludeDirectories - if it hadn't resolved, the
# #error guard in each .cpp would have fired instead and there would be no zerodiv
assert __get_lines(stderr) == __get_lines(__ERR_A + __ERR_B)
def test_props_dirs_defines_and_standard():
args = [
'--project=props-dirs/props-dirs.slnx',
'--no-cppcheck-build-dir',
'--dump'
]
ret, stdout, _ = cppcheck(args, cwd=__script_dir)
assert ret == 0, stdout
dump_a = os.path.join(__script_dir, 'props-dirs', 'ProjA', 'a.cpp.dump')
dump_b = os.path.join(__script_dir, 'props-dirs', 'ProjB', 'b.cpp.dump')
assert os.path.exists(dump_a), f"Dump file not found at {dump_a}"
assert os.path.exists(dump_b), f"Dump file not found at {dump_b}"
with open(dump_a, 'rt') as f:
dump_a_content = f.read()
with open(dump_b, 'rt') as f:
dump_b_content = f.read()
# ProjA imports shared/shared.props (which itself imports common/common.props), and
# also sets its own PROJA_DEFINE - all three must be present, most specific first
assert 'cfg="_WIN32=1;_WIN64=1;PROJA_DEFINE=1;SHARED_DEFINE=1;COMMON_DEFINE=1;_MSC_VER=1900"' in dump_a_content
assert '<cpp version="c++17"/>' in dump_a_content
# ProjB imports common/common.props directly - it must see COMMON_DEFINE, but neither
# PROJA_DEFINE nor SHARED_DEFINE, which only ever applied to ProjA
assert 'cfg="_WIN32=1;_WIN64=1;COMMON_DEFINE=1;_MSC_VER=1900"' in dump_b_content
assert '<cpp version="c++17"/>' in dump_b_content
assert 'PROJA_DEFINE' not in dump_b_content
assert 'SHARED_DEFINE' not in dump_b_content