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