Skip to content

Commit ecf86da

Browse files
committed
Move tests to integration_test.py
1 parent 9935591 commit ecf86da

7 files changed

Lines changed: 113 additions & 47 deletions

File tree

integration_test.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import pathlib
5+
import platform
56
import pytest
67
from testutils import simplecpp, format_include_path_arg, format_include
78

@@ -177,3 +178,113 @@ def test_relative_header_6(record_property, tmpdir, with_pragma_once, relative_i
177178
assert f'#line 8 "{pathlib.PurePath(tmpdir).as_posix()}/test.h"' in stdout
178179
else:
179180
assert double_include_error in stderr
181+
182+
def test_same_name_header(record_property, tmpdir):
183+
include_a = os.path.join(tmpdir, "include_a")
184+
include_b = os.path.join(tmpdir, "include_b")
185+
186+
test_file = os.path.join(tmpdir, "test.c")
187+
header_a = os.path.join(include_a, "header_a.h")
188+
header_b = os.path.join(include_b, "header_b.h")
189+
same_name_a = os.path.join(include_a, "same_name.h")
190+
same_name_b = os.path.join(include_b, "same_name.h")
191+
192+
os.mkdir(include_a)
193+
os.mkdir(include_b)
194+
195+
with open(test_file, "wt") as f:
196+
f.write("""
197+
#include <header_a.h>
198+
#include <header_b.h>
199+
TEST
200+
""")
201+
202+
with open(header_a, "wt") as f:
203+
f.write("""
204+
#include "same_name.h"
205+
""")
206+
207+
with open(header_b, "wt") as f:
208+
f.write("""
209+
#include "same_name.h"
210+
""")
211+
212+
with open(same_name_a, "wt") as f:
213+
f.write("""
214+
#define TEST E
215+
""")
216+
217+
with open(same_name_b, "wt") as f:
218+
f.write("""
219+
#define TEST OK
220+
""")
221+
222+
args = [
223+
format_include_path_arg(include_a),
224+
format_include_path_arg(include_b),
225+
test_file
226+
]
227+
228+
_, stdout, stderr = simplecpp(args, cwd=tmpdir)
229+
record_property("stdout", stdout)
230+
record_property("stderr", stderr)
231+
232+
assert "OK" in stdout
233+
assert stderr == ""
234+
235+
def test_pragma_once_matching(record_property, tmpdir):
236+
if platform.system() == "win32":
237+
names_to_test = [
238+
'"once.h"',
239+
'"Once.h"',
240+
'<once.h>',
241+
'<Once.h>',
242+
'"../test_dir/once.h"',
243+
'"../test_dir/Once.h"',
244+
'"../Test_Dir/once.h"',
245+
'"../Test_Dir/Once.h"',
246+
'"test_subdir/../once.h"',
247+
'"test_subdir/../Once.h"',
248+
'"Test_Subdir/../once.h"',
249+
'"Test_Subdir/../Once.h"',
250+
]
251+
else:
252+
names_to_test = [
253+
'"once.h"',
254+
'<once.h>',
255+
'"../test_dir/once.h"',
256+
'"test_subdir/../once.h"',
257+
]
258+
259+
test_dir = os.path.join(tmpdir, "test_dir")
260+
test_subdir = os.path.join(test_dir, "test_subdir")
261+
262+
test_file = os.path.join(test_dir, "test.c")
263+
once_header = os.path.join(test_dir, "once.h")
264+
265+
os.mkdir(test_dir)
266+
os.mkdir(test_subdir)
267+
268+
with open(test_file, "wt") as f:
269+
for n in names_to_test:
270+
f.write(f"""
271+
#include {n}
272+
""");
273+
274+
with open(once_header, "wt") as f:
275+
f.write(f"""
276+
#pragma once
277+
ONCE
278+
""");
279+
280+
args = [
281+
format_include_path_arg(test_dir),
282+
test_file
283+
]
284+
285+
_, stdout, stderr = simplecpp(args, cwd=tmpdir)
286+
record_property("stdout", stdout)
287+
record_property("stderr", stderr)
288+
289+
assert stdout.count("ONCE") == 1
290+
assert stderr == ""

test.cpp

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ static std::string preprocess(const char code[], const simplecpp::DUI &dui, simp
105105
tokens.removeComments();
106106
simplecpp::TokenList tokens2(files);
107107
simplecpp::preprocess(tokens2, tokens, files, filedata, dui, outputList);
108+
for (auto &i : filedata)
109+
delete i.second;
108110
return tokens2.stringify();
109111
}
110112

@@ -2990,43 +2992,6 @@ static void fuzz_crash()
29902992
}
29912993
}
29922994

2993-
static void same_name()
2994-
{
2995-
const char code[] = "#include <header_a.h>\n"
2996-
"#include <header_b.h>\n"
2997-
"TEST\n";
2998-
2999-
simplecpp::DUI dui;
3000-
dui.includePaths.push_back("./testsuite/path-tests/include_a");
3001-
dui.includePaths.push_back("./testsuite/path-tests/include_b");
3002-
3003-
ASSERT_EQUALS("\n\nOK", preprocess(code, dui));
3004-
}
3005-
3006-
static void file_id()
3007-
{
3008-
const char code[] = "#include \"once.h\"\n"
3009-
"#include \"Once.h\"\n"
3010-
3011-
"#include <once.h>\n"
3012-
"#include <Once.h>\n"
3013-
3014-
"#include \"../path-tests/once.h\"\n"
3015-
"#include \"../path-tests/Once.h\"\n"
3016-
"#include \"../Path-Tests/once.h\"\n"
3017-
"#include \"../Path-Tests/Once.h\"\n"
3018-
3019-
"#include \"include_a/../once.h\"\n"
3020-
"#include \"include_a/../Once.h\"\n"
3021-
"#include \"include_A/../once.h\"\n"
3022-
"#include \"include_A/../Once.h\"\n";
3023-
3024-
simplecpp::DUI dui;
3025-
dui.includePaths.push_back("./testsuite/path-tests");
3026-
3027-
ASSERT_EQUALS("\n#line 2 \"testsuite/path-tests/once.h\"\nONCE", preprocess(code, dui));
3028-
}
3029-
30302995
int main(int argc, char **argv)
30312996
{
30322997
TEST_CASE(backslash);
@@ -3249,10 +3214,6 @@ int main(int argc, char **argv)
32493214

32503215
TEST_CASE(warning);
32513216

3252-
// path resolution
3253-
TEST_CASE(same_name);
3254-
TEST_CASE(file_id);
3255-
32563217
// utility functions.
32573218
TEST_CASE(simplifyPath);
32583219
TEST_CASE(simplifyPath_cppcheck);

testsuite/path-tests/include_a/header_a.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

testsuite/path-tests/include_a/same_name.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

testsuite/path-tests/include_b/header_b.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

testsuite/path-tests/include_b/same_name.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

testsuite/path-tests/once.h

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)