Skip to content

Commit 9cd0027

Browse files
committed
Add some testing on errors raised with proper lines from #line directives
1 parent d139973 commit 9cd0027

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

tests/test_c_parser.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,36 @@ def test_initial_semi(self):
167167
["Decl", "foo", ["TypeDecl", ["IdentifierType", ["int"]]]],
168168
)
169169

170-
def test_coords(self):
171-
"""Tests the "coordinates" of parsed elements - file
172-
name, line and column numbers, with modification
173-
inserted by #line directives.
170+
def test_line_directive_update_in_errors(self):
171+
s1 = """
172+
\t # \t line \t 8 \t "baz.c" \t
173+
174+
some syntax error here
174175
"""
176+
self.assertRaisesRegex(ParseError, "baz.c:9", self.parse, s1)
177+
178+
s2 = """
179+
\t # \t 8 \t "baz.c" \t
180+
181+
182+
some syntax error here
183+
"""
184+
self.assertRaisesRegex(ParseError, "baz.c:10", self.parse, s2)
185+
186+
s3 = """ #line 5 "foo.c"
187+
extern int xx;
188+
#line 6 "bar.c"
189+
extern int yy;
190+
#line 7 "baz.c"
191+
some syntax error here
192+
#line 8 "yadda.c"
193+
extern int zz;
194+
"""
195+
self.assertRaisesRegex(ParseError, "baz.c:7", self.parse, s3)
196+
197+
def test_coords(self):
198+
# Tests the "coordinates" of parsed elements - file name, line and
199+
# column numbers, with modification inserted by #line directives.
175200
self.assert_coord(self.parse("int a;").ext[0], 1, 5)
176201

177202
t1 = """

0 commit comments

Comments
 (0)