Skip to content

Commit fb13460

Browse files
committed
Add regression test for backslash-newline at EOF
gcc accepts this with a warning and clang accepts it silently, but CBI exits with a RuntimeError. Signed-off-by: John Pennycook <[email protected]>
1 parent adba0e7 commit fb13460

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/preprocessor/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Copyright (C) 2019 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause

tests/preprocessor/test_warnings.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (C) 2019-2024 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
import logging
5+
import os
6+
import tempfile
7+
import unittest
8+
from pathlib import Path
9+
10+
from codebasin import file_parser
11+
12+
13+
class TestPreprocessorWarnings(unittest.TestCase):
14+
"""
15+
Test that preprocessor generates warnings for weird corner cases.
16+
"""
17+
18+
def setUp(self):
19+
self.cwd = os.getcwd()
20+
21+
def tearDown(self):
22+
os.chdir(self.cwd)
23+
24+
def test_backslash_eof(self):
25+
"""Check backslash-newline at EOF is only a warning"""
26+
tmp = tempfile.TemporaryDirectory()
27+
path = Path(tmp.name)
28+
os.chdir(tmp.name)
29+
30+
with open(path / "test.hpp", mode="w") as f:
31+
f.write("#define BAD_MACRO \\\n")
32+
33+
parser = file_parser.FileParser(path / "test.hpp")
34+
35+
logging.disable(logging.NOTSET)
36+
logger = logging.getLogger("codebasin")
37+
with self.assertLogs(logger, level="WARNING") as cm:
38+
_ = parser.parse_file()
39+
logging.disable()
40+
self.assertRegex(cm.output[0], "backslash-newline at end of file")
41+
42+
tmp.cleanup()

0 commit comments

Comments
 (0)