1""" 2Test that lldb command "command source" works correctly. 3""" 4 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class CommandSourceTestCase(TestBase): 14 15 @no_debug_info_test 16 def test_command_source(self): 17 """Test that lldb command "command source" works correctly.""" 18 19 # Sourcing .lldb in the current working directory, which in turn imports 20 # the "my" package that defines the date() function. 21 self.runCmd("command source .lldb") 22 self.check_results() 23 24 @no_debug_info_test 25 def test_command_source_relative(self): 26 """Test that lldb command "command source" works correctly with relative paths.""" 27 28 # Sourcing .lldb in the current working directory, which in turn imports 29 # the "my" package that defines the date() function. 30 self.runCmd("command source commands2.txt") 31 self.check_results() 32 33 def check_results(self, failure=False): 34 # Python should evaluate "my.date()" successfully. 35 command_interpreter = self.dbg.GetCommandInterpreter() 36 self.assertTrue(command_interpreter, VALID_COMMAND_INTERPRETER) 37 result = lldb.SBCommandReturnObject() 38 command_interpreter.HandleCommand("script my.date()", result) 39 40 import datetime 41 if failure: 42 self.expect(result.GetOutput(), "script my.date() runs successfully", 43 exe=False, error=True) 44 else: 45 self.expect(result.GetOutput(), "script my.date() runs successfully", 46 exe=False, 47 substrs=[str(datetime.date.today())]) 48 49 @no_debug_info_test 50 def test_command_source_relative_error(self): 51 """Test that 'command source -C' gives an error for a relative path""" 52 source_dir = self.getSourceDir() 53 result = lldb.SBCommandReturnObject() 54 self.runCmd("command source --stop-on-error 1 not-relative.txt") 55 self.check_results(failure=True) 56