File tree 2 files changed +44
-0
lines changed
2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Copyright (C) 2019 Intel Corporation
2
+ # SPDX-License-Identifier: BSD-3-Clause
Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments