diff options
author | Armin Rigo <arigo@tunes.org> | 2020-05-26 15:51:56 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2020-05-26 15:51:56 +0200 |
commit | 6c6b4102077dec4eb249d3ca42a1bd0b343aece2 (patch) | |
tree | e32441f4b49a6a2e548e5169881097947cfa344a /testing | |
parent | bb48fdcc86c5bd2c211fba2ac4cffe8b6efb49e2 (diff) | |
download | cffi-6c6b4102077dec4eb249d3ca42a1bd0b343aece2.tar.gz |
Issue #454
Try harder to avoid #line directives confuse the rest of pre-parsing
Diffstat (limited to 'testing')
-rw-r--r-- | testing/cffi0/test_parsing.py | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py index 3fc3783..5f2d7ec 100644 --- a/testing/cffi0/test_parsing.py +++ b/testing/cffi0/test_parsing.py @@ -174,7 +174,7 @@ def test_remove_line_continuation_comments(): double // blah \\ more comments x(void); - double // blah\\\\ + double // blah // blah\\\\ y(void); double // blah\\ \ etc @@ -185,6 +185,52 @@ def test_remove_line_continuation_comments(): m.y m.z +def test_dont_remove_comment_in_line_directives(): + ffi = FFI(backend=FakeBackend()) + e = py.test.raises(CDefError, ffi.cdef, """ + \t # \t line \t 8 \t "baz.c" \t + + some syntax error here + """) + assert str(e.value) == "parse error\nbaz.c:9:14: before: syntax" + # + e = py.test.raises(CDefError, ffi.cdef, """ + #line 7 "foo//bar.c" + + some syntax error here + """) + assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax" + +def test_multiple_line_directives(): + ffi = FFI(backend=FakeBackend()) + e = py.test.raises(CDefError, ffi.cdef, + """ #line 5 "foo.c" + extern int xx; + #line 6 "bar.c" + extern int yy; + #line 7 "baz.c" + some syntax error here + #line 8 "yadda.c" + extern int zz; + """) + assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax" + +def test_commented_line_directive(): + ffi = FFI(backend=FakeBackend()) + e = py.test.raises(CDefError, ffi.cdef, """ + /* + #line 5 "foo.c" + */ + void xx(void); + + #line 6 "bar.c" + /* + #line 35 "foo.c" + */ + some syntax error + """) + assert str(e.value) == "parse error\nbar.c:9:14: before: syntax" + def test_line_continuation_in_defines(): ffi = FFI(backend=FakeBackend()) ffi.cdef(""" |