@@ -66,7 +66,7 @@ def test_relative_header_2(record_property, tmpdir, with_pragma_once, inv, sourc
6666 record_property ("stderr" , stderr )
6767 if with_pragma_once :
6868 assert stderr == ''
69- if inv :
69+ if inv or not source_relative :
7070 assert f'#line 8 "{ pathlib .PurePath (tmpdir ).as_posix ()} /test.h"' in stdout
7171 else :
7272 assert '#line 8 "test.h"' in stdout
@@ -93,16 +93,17 @@ def test_relative_header_3(record_property, tmpdir, is_sys, inv, source_relative
9393 assert "missing header: Header not found" in stderr
9494 else :
9595 assert stderr == ''
96- if inv :
97- assert f'#line 8 "{ pathlib .PurePath (test_subdir ).as_posix ()} /test.h"' in stdout
98- else :
96+ if source_relative and not inv :
9997 assert '#line 8 "test_subdir/test.h"' in stdout
98+ else :
99+ assert f'#line 8 "{ pathlib .PurePath (test_subdir ).as_posix ()} /test.h"' in stdout
100100
101101@pytest .mark .parametrize ("use_short_path" , (False , True ))
102102@pytest .mark .parametrize ("relative_include_dir" , (False , True ))
103103@pytest .mark .parametrize ("is_sys" , (False , True ))
104104@pytest .mark .parametrize ("inv" , (False , True ))
105- def test_relative_header_4 (record_property , tmpdir , use_short_path , relative_include_dir , is_sys , inv ):
105+ @pytest .mark .parametrize ("source_relative" , (False , True ))
106+ def test_relative_header_4 (record_property , tmpdir , use_short_path , relative_include_dir , is_sys , inv , source_relative ):
106107 test_subdir = os .path .join (tmpdir , "test_subdir" )
107108 os .mkdir (test_subdir )
108109 header_file , _ = __test_relative_header_create_header (test_subdir )
@@ -111,13 +112,14 @@ def test_relative_header_4(record_property, tmpdir, use_short_path, relative_inc
111112
112113 test_file = __test_relative_header_create_source (tmpdir , header_file , "test.h" , is_include2_sys = is_sys , inv = inv )
113114
114- args = [format_include_path_arg ("test_subdir" if relative_include_dir else test_subdir ), test_file ]
115+ args = [format_include_path_arg ("test_subdir" if relative_include_dir else test_subdir ), "test.c" if source_relative else test_file ]
115116
116117 _ , stdout , stderr = simplecpp (args , cwd = tmpdir )
117118 record_property ("stdout" , stdout )
118119 record_property ("stderr" , stderr )
120+
119121 assert stderr == ''
120- if (use_short_path and not inv ) or (relative_include_dir and inv ):
122+ if (source_relative and use_short_path and not inv ) or (relative_include_dir and inv ):
121123 assert '#line 8 "test_subdir/test.h"' in stdout
122124 else :
123125 assert f'#line 8 "{ pathlib .PurePath (test_subdir ).as_posix ()} /test.h"' in stdout
@@ -126,7 +128,8 @@ def test_relative_header_4(record_property, tmpdir, use_short_path, relative_inc
126128@pytest .mark .parametrize ("relative_include_dir" , (False , True ))
127129@pytest .mark .parametrize ("is_sys" , (False , True ))
128130@pytest .mark .parametrize ("inv" , (False , True ))
129- def test_relative_header_5 (record_property , tmpdir , with_pragma_once , relative_include_dir , is_sys , inv ): # test relative paths with ..
131+ @pytest .mark .parametrize ("source_relative" , (False , True ))
132+ def test_relative_header_5 (record_property , tmpdir , with_pragma_once , relative_include_dir , is_sys , inv , source_relative ): # test relative paths with ..
130133 ## 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
131134 header_file , double_include_error = __test_relative_header_create_header (tmpdir , with_pragma_once = with_pragma_once )
132135 if is_sys :
@@ -138,14 +141,14 @@ def test_relative_header_5(record_property, tmpdir, with_pragma_once, relative_i
138141 os .mkdir (test_subdir )
139142 test_file = __test_relative_header_create_source (test_subdir , header_file , header_file_second_path , is_include2_sys = is_sys , inv = inv )
140143
141- args = ([format_include_path_arg (".." if relative_include_dir else tmpdir )] if is_sys else []) + ["test.c" ]
144+ args = ([format_include_path_arg (".." if relative_include_dir else tmpdir )] if is_sys else []) + ["test.c" if source_relative else test_file ]
142145
143146 _ , stdout , stderr = simplecpp (args , cwd = test_subdir )
144147 record_property ("stdout" , stdout )
145148 record_property ("stderr" , stderr )
146149 if with_pragma_once :
147150 assert stderr == ''
148- if (relative_include_dir or not is_sys ) and inv :
151+ if (relative_include_dir if is_sys else source_relative ) and inv :
149152 assert '#line 8 "../test.h"' in stdout
150153 else :
151154 assert f'#line 8 "{ pathlib .PurePath (tmpdir ).as_posix ()} /test.h"' in stdout
@@ -156,15 +159,16 @@ def test_relative_header_5(record_property, tmpdir, with_pragma_once, relative_i
156159@pytest .mark .parametrize ("relative_include_dir" , (False , True ))
157160@pytest .mark .parametrize ("is_sys" , (False , True ))
158161@pytest .mark .parametrize ("inv" , (False , True ))
159- 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
162+ @pytest .mark .parametrize ("source_relative" , (False , True ))
163+ 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
160164 ## 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
161165 header_file , double_include_error = __test_relative_header_create_header (tmpdir , with_pragma_once = with_pragma_once )
162166
163167 test_subdir = os .path .join (tmpdir , "test_subdir" )
164168 os .mkdir (test_subdir )
165169 test_file = __test_relative_header_create_source (tmpdir , header_file , "../test.h" , is_include2_sys = is_sys , inv = inv )
166170
167- args = [format_include_path_arg ("test_subdir" if relative_include_dir else test_subdir ), "test.c" ]
171+ args = [format_include_path_arg ("test_subdir" if relative_include_dir else test_subdir ), "test.c" if source_relative else test_file ]
168172
169173 _ , stdout , stderr = simplecpp (args , cwd = tmpdir )
170174 record_property ("stdout" , stdout )
0 commit comments