Skip to content

Commit 473ef7c

Browse files
authored
Merge pull request #341 from kjnh10/bugfix/#340
Bugfix/#340
2 parents 8e8185e + 2c60bcb commit 473ef7c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

onlinejudge_verify/languages/cplusplus_bundle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def _get_uncommented_code(path: pathlib.Path, *, iquotes_options: Tuple[str, ...
184184
if compiler == 'g++':
185185
raise BundleError(f'A fake g++ is detected. Please install the GNU C++ compiler.: {compiler}')
186186
raise BundleError(f"It's not g++. Please specify g++ with $CXX envvar.: {compiler}")
187-
command = [compiler, *iquotes_options, '-fpreprocessed', '-dD', '-E', str(path)]
187+
command = [compiler, '-x', 'c++', *iquotes_options, '-fpreprocessed', '-dD', '-E', str(path)]
188188
return subprocess.check_output(command)
189189

190190

tests/test_bundle.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ def test_uncommenting(self) -> None:
6565
self.assertIn(b'void foo() {}', bundled)
6666
self.assertNotIn(b'void bar() {}', bundled)
6767

68+
def test_without_extension(self) -> None:
69+
# .hppといった拡張子がないheader fileがinclude中に現れても正しく展開される事を確認
70+
71+
files = {
72+
'example.test.cpp': b'#include "bar"\n#include "foo.hpp"',
73+
'bar': b'#include "./bar.hpp"',
74+
'bar.hpp': b'hello bar\n',
75+
'foo.hpp': b'hello foo\n',
76+
}
77+
path = pathlib.Path('example.test.cpp')
78+
with tests.utils.load_files(files) as tempdir:
79+
with tests.utils.chdir(tempdir):
80+
bundler = cplusplus_bundle.Bundler(iquotes=[tempdir])
81+
bundler.update(path)
82+
res = bundler.get()
83+
self.assertIn(b'hello bar\n', res)
84+
self.assertIn(b'hello foo\n', res)
85+
6886
@unittest.skipIf(shutil.which('clang++') is None, 'clang++ is required for this test')
6987
def test_reject_clang(self) -> None:
7088
files = {

0 commit comments

Comments
 (0)