1""" 2Test calling an expression with errors that a FixIt can fix. 3""" 4 5import lldb 6from lldbsuite.test.decorators import * 7from lldbsuite.test.lldbtest import * 8from lldbsuite.test import lldbutil 9 10 11class ExprCommandWithFixits(TestBase): 12 13 mydir = TestBase.compute_mydir(__file__) 14 15 def test_with_dummy_target(self): 16 """Test calling expressions in the dummy target with errors that can be fixed by the FixIts.""" 17 18 # Enable fix-its as they were intentionally disabled by TestBase.setUp. 19 self.runCmd("settings set target.auto-apply-fixits true") 20 21 ret_val = lldb.SBCommandReturnObject() 22 result = self.dbg.GetCommandInterpreter().HandleCommand("expression ((1 << 16) - 1))", ret_val) 23 self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "The expression was successful.") 24 self.assertTrue("Fix-it applied" in ret_val.GetError(), "Found the applied FixIt.") 25 26 @skipUnlessDarwin 27 def test_with_target(self): 28 """Test calling expressions with errors that can be fixed by the FixIts.""" 29 self.build() 30 (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self, 31 'Stop here to evaluate expressions', 32 lldb.SBFileSpec("main.cpp")) 33 34 options = lldb.SBExpressionOptions() 35 options.SetAutoApplyFixIts(True) 36 37 frame = self.thread.GetFrameAtIndex(0) 38 39 # Try with one error: 40 value = frame.EvaluateExpression("my_pointer.first", options) 41 self.assertTrue(value.IsValid()) 42 self.assertTrue(value.GetError().Success()) 43 self.assertEquals(value.GetValueAsUnsigned(), 10) 44 45 # Try with two errors: 46 two_error_expression = "my_pointer.second->a" 47 value = frame.EvaluateExpression(two_error_expression, options) 48 self.assertTrue(value.IsValid()) 49 self.assertTrue(value.GetError().Success()) 50 self.assertEquals(value.GetValueAsUnsigned(), 20) 51 52 # Now turn off the fixits, and the expression should fail: 53 options.SetAutoApplyFixIts(False) 54 value = frame.EvaluateExpression(two_error_expression, options) 55 self.assertTrue(value.IsValid()) 56 self.assertTrue(value.GetError().Fail()) 57 error_string = value.GetError().GetCString() 58 self.assertTrue( 59 error_string.find("fixed expression suggested:") != -1, 60 "Fix was suggested") 61 self.assertTrue( 62 error_string.find("my_pointer->second.a") != -1, 63 "Fix was right") 64