@@ -74,6 +74,41 @@ def test_evaluate_string_on_reported_value(self):
7474 value = '"\u26a0 \ufe0f problem %s: %s"'
7575 self .assertEqual (evaluate_string (value ), "\u26a0 \ufe0f problem %s: %s" )
7676
77+ def test_syntax_error_node_raises (self ):
78+ output = json .dumps (
79+ [
80+ {
81+ "id" : 0 ,
82+ "edges" : [],
83+ "attrs" : {
84+ "_kind" : {"type" : "string" , "string" : "SyntaxErrorNode" },
85+ "_location" : {
86+ "type" : "list" ,
87+ "values" : [
88+ {"type" : "int" , "int" : 4 },
89+ {"type" : "int" , "int" : 5 },
90+ {"type" : "int" , "int" : 4 },
91+ {"type" : "int" , "int" : 6 },
92+ ],
93+ },
94+ "source" : {"type" : "string" , "string" : "!" },
95+ },
96+ }
97+ ]
98+ ).encode ("utf-8" )
99+
100+ process = unittest .mock .Mock ()
101+ process .communicate .return_value = (output , None )
102+ process .returncode = 0
103+ with unittest .mock .patch (
104+ "semmle.python.parser.tsg_parser.subprocess.Popen" , return_value = process
105+ ):
106+ with self .assertRaises (SyntaxError ) as raised :
107+ read_tsg_python_output ("test.py" , unittest .mock .Mock ())
108+
109+ self .assertEqual (raised .exception .lineno , 5 )
110+ self .assertEqual (raised .exception .offset , 5 )
111+
77112
78113class FormatMessageTest (unittest .TestCase ):
79114 """A pre-formatted log message may contain `%` directives coming from the analysed source, and
0 commit comments