@@ -207,37 +207,56 @@ def test_command_expr_sbdata(self):
207207 (target , process , thread , bkpt ) = lldbutil .run_to_source_breakpoint (
208208 self , "// Break here" , self .main_source_spec
209209 )
210+
211+ def check_error (diags ):
212+ # Version.
213+ version = diags .GetValueForKey ("version" )
214+ self .assertEqual (version .GetIntegerValue (), 1 )
215+
216+ details = diags .GetValueForKey ("details" )
217+
218+ # Detail 1/2: undeclared 'a'
219+ diag = details .GetItemAtIndex (0 )
220+
221+ severity = diag .GetValueForKey ("severity" )
222+ message = diag .GetValueForKey ("message" )
223+ rendered = diag .GetValueForKey ("rendered" )
224+ sloc = diag .GetValueForKey ("source_location" )
225+ filename = sloc .GetValueForKey ("file" )
226+ hidden = sloc .GetValueForKey ("hidden" )
227+ in_user_input = sloc .GetValueForKey ("in_user_input" )
228+
229+ self .assertEqual (str (severity ), "error" )
230+ self .assertIn ("undeclared identifier 'a'" , str (message ))
231+ # The rendered string should contain the source file.
232+ self .assertIn ("user expression" , str (rendered ))
233+ self .assertIn ("user expression" , str (filename ))
234+ self .assertFalse (hidden .GetBooleanValue ())
235+ self .assertTrue (in_user_input .GetBooleanValue ())
236+
237+ # Detail 1/2: undeclared 'b'
238+ diag = details .GetItemAtIndex (1 )
239+ message = diag .GetValueForKey ("message" )
240+ self .assertIn ("undeclared identifier 'b'" , str (message ))
241+
242+ # Test diagnostics in CommandReturnObject
210243 interp = self .dbg .GetCommandInterpreter ()
211244 cro = lldb .SBCommandReturnObject ()
212245 interp .HandleCommand ("expression -- a+b" , cro )
213246
214247 diags = cro .GetErrorData ()
215- # Version.
216- version = diags .GetValueForKey ("version" )
217- self .assertEqual (version .GetIntegerValue (), 1 )
248+ check_error (diags )
218249
219- details = diags .GetValueForKey ("details" )
220-
221- # Detail 1/2: undeclared 'a'
222- diag = details .GetItemAtIndex (0 )
223-
224- severity = diag .GetValueForKey ("severity" )
225- message = diag .GetValueForKey ("message" )
226- rendered = diag .GetValueForKey ("rendered" )
227- sloc = diag .GetValueForKey ("source_location" )
228- filename = sloc .GetValueForKey ("file" )
229- hidden = sloc .GetValueForKey ("hidden" )
230- in_user_input = sloc .GetValueForKey ("in_user_input" )
231-
232- self .assertEqual (str (severity ), "error" )
233- self .assertIn ("undeclared identifier 'a'" , str (message ))
234- # The rendered string should contain the source file.
235- self .assertIn ("user expression" , str (rendered ))
236- self .assertIn ("user expression" , str (filename ))
237- self .assertFalse (hidden .GetBooleanValue ())
238- self .assertTrue (in_user_input .GetBooleanValue ())
239-
240- # Detail 1/2: undeclared 'b'
241- diag = details .GetItemAtIndex (1 )
242- message = diag .GetValueForKey ("message" )
243- self .assertIn ("undeclared identifier 'b'" , str (message ))
250+ # Test diagnostics in SBError
251+ frame = thread .GetSelectedFrame ()
252+ value = frame .EvaluateExpression ("a+b" )
253+ error = value .GetError ()
254+ self .assertTrue (error .Fail ())
255+ self .assertEquals (error .GetType (), lldb .eErrorTypeExpression )
256+ data = error .GetErrorData ()
257+ version = data .GetValueForKey ("version" )
258+ self .assertEqual (version .GetIntegerValue (), 1 )
259+ err_ty = data .GetValueForKey ("type" )
260+ self .assertEqual (err_ty .GetIntegerValue (), lldb .eErrorTypeExpression )
261+ diags = data .GetValueForKey ("errors" ).GetItemAtIndex (0 )
262+ check_error (diags )
0 commit comments