@@ -67,7 +67,7 @@ def test_relative_header_2(record_property, tmpdir, with_pragma_once, inv, sourc
67
67
record_property ("stderr" , stderr )
68
68
if with_pragma_once :
69
69
assert stderr == ''
70
- if inv :
70
+ if inv or not source_relative :
71
71
assert f'#line 8 "{ pathlib .PurePath (tmpdir ).as_posix ()} /test.h"' in stdout
72
72
else :
73
73
assert '#line 8 "test.h"' in stdout
@@ -94,16 +94,17 @@ def test_relative_header_3(record_property, tmpdir, is_sys, inv, source_relative
94
94
assert "missing header: Header not found" in stderr
95
95
else :
96
96
assert stderr == ''
97
- if inv :
98
- assert f'#line 8 "{ pathlib .PurePath (test_subdir ).as_posix ()} /test.h"' in stdout
99
- else :
97
+ if source_relative and not inv :
100
98
assert '#line 8 "test_subdir/test.h"' in stdout
99
+ else :
100
+ assert f'#line 8 "{ pathlib .PurePath (test_subdir ).as_posix ()} /test.h"' in stdout
101
101
102
102
@pytest .mark .parametrize ("use_short_path" , (False , True ))
103
103
@pytest .mark .parametrize ("relative_include_dir" , (False , True ))
104
104
@pytest .mark .parametrize ("is_sys" , (False , True ))
105
105
@pytest .mark .parametrize ("inv" , (False , True ))
106
- def test_relative_header_4 (record_property , tmpdir , use_short_path , relative_include_dir , is_sys , inv ):
106
+ @pytest .mark .parametrize ("source_relative" , (False , True ))
107
+ def test_relative_header_4 (record_property , tmpdir , use_short_path , relative_include_dir , is_sys , inv , source_relative ):
107
108
test_subdir = os .path .join (tmpdir , "test_subdir" )
108
109
os .mkdir (test_subdir )
109
110
header_file , _ = __test_relative_header_create_header (test_subdir )
@@ -112,13 +113,14 @@ def test_relative_header_4(record_property, tmpdir, use_short_path, relative_inc
112
113
113
114
test_file = __test_relative_header_create_source (tmpdir , header_file , "test.h" , is_include2_sys = is_sys , inv = inv )
114
115
115
- args = [format_include_path_arg ("test_subdir" if relative_include_dir else test_subdir ), test_file ]
116
+ args = [format_include_path_arg ("test_subdir" if relative_include_dir else test_subdir ), "test.c" if source_relative else test_file ]
116
117
117
118
_ , stdout , stderr = simplecpp (args , cwd = tmpdir )
118
119
record_property ("stdout" , stdout )
119
120
record_property ("stderr" , stderr )
121
+
120
122
assert stderr == ''
121
- if (use_short_path and not inv ) or (relative_include_dir and inv ):
123
+ if (source_relative and use_short_path and not inv ) or (relative_include_dir and inv ):
122
124
assert '#line 8 "test_subdir/test.h"' in stdout
123
125
else :
124
126
assert f'#line 8 "{ pathlib .PurePath (test_subdir ).as_posix ()} /test.h"' in stdout
@@ -127,7 +129,8 @@ def test_relative_header_4(record_property, tmpdir, use_short_path, relative_inc
127
129
@pytest .mark .parametrize ("relative_include_dir" , (False , True ))
128
130
@pytest .mark .parametrize ("is_sys" , (False , True ))
129
131
@pytest .mark .parametrize ("inv" , (False , True ))
130
- def test_relative_header_5 (record_property , tmpdir , with_pragma_once , relative_include_dir , is_sys , inv ): # test relative paths with ..
132
+ @pytest .mark .parametrize ("source_relative" , (False , True ))
133
+ def test_relative_header_5 (record_property , tmpdir , with_pragma_once , relative_include_dir , is_sys , inv , source_relative ): # test relative paths with ..
131
134
## in this test, the subdir role is the opposite then the previous - it contains the test.c file, while the parent tmpdir contains the header file
132
135
header_file , double_include_error = __test_relative_header_create_header (tmpdir , with_pragma_once = with_pragma_once )
133
136
if is_sys :
@@ -139,14 +142,14 @@ def test_relative_header_5(record_property, tmpdir, with_pragma_once, relative_i
139
142
os .mkdir (test_subdir )
140
143
test_file = __test_relative_header_create_source (test_subdir , header_file , header_file_second_path , is_include2_sys = is_sys , inv = inv )
141
144
142
- args = ([format_include_path_arg (".." if relative_include_dir else tmpdir )] if is_sys else []) + ["test.c" ]
145
+ args = ([format_include_path_arg (".." if relative_include_dir else tmpdir )] if is_sys else []) + ["test.c" if source_relative else test_file ]
143
146
144
147
_ , stdout , stderr = simplecpp (args , cwd = test_subdir )
145
148
record_property ("stdout" , stdout )
146
149
record_property ("stderr" , stderr )
147
150
if with_pragma_once :
148
151
assert stderr == ''
149
- if (relative_include_dir or not is_sys ) and inv :
152
+ if (relative_include_dir if is_sys else source_relative ) and inv :
150
153
assert '#line 8 "../test.h"' in stdout
151
154
else :
152
155
assert f'#line 8 "{ pathlib .PurePath (tmpdir ).as_posix ()} /test.h"' in stdout
@@ -157,15 +160,16 @@ def test_relative_header_5(record_property, tmpdir, with_pragma_once, relative_i
157
160
@pytest .mark .parametrize ("relative_include_dir" , (False , True ))
158
161
@pytest .mark .parametrize ("is_sys" , (False , True ))
159
162
@pytest .mark .parametrize ("inv" , (False , True ))
160
- def test_relative_header_6 (record_property , tmpdir , with_pragma_once , relative_include_dir , is_sys , inv ): # test relative paths with .. that is resolved only by an include dir
163
+ @pytest .mark .parametrize ("source_relative" , (False , True ))
164
+ def test_relative_header_6 (record_property , tmpdir , with_pragma_once , relative_include_dir , is_sys , inv , source_relative ): # test relative paths with .. that is resolved only by an include dir
161
165
## in this test, both the header and the source file are at the same dir, but there is a dummy inclusion dir as a subdir
162
166
header_file , double_include_error = __test_relative_header_create_header (tmpdir , with_pragma_once = with_pragma_once )
163
167
164
168
test_subdir = os .path .join (tmpdir , "test_subdir" )
165
169
os .mkdir (test_subdir )
166
170
test_file = __test_relative_header_create_source (tmpdir , header_file , "../test.h" , is_include2_sys = is_sys , inv = inv )
167
171
168
- args = [format_include_path_arg ("test_subdir" if relative_include_dir else test_subdir ), "test.c" ]
172
+ args = [format_include_path_arg ("test_subdir" if relative_include_dir else test_subdir ), "test.c" if source_relative else test_file ]
169
173
170
174
_ , stdout , stderr = simplecpp (args , cwd = tmpdir )
171
175
record_property ("stdout" , stdout )
0 commit comments