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 mydir = TestBase.compute_mydir(__file__) 16 17 @no_debug_info_test 18 def test_command_source(self): 19 """Test that lldb command "command source" works correctly.""" 20 21 # Sourcing .lldb in the current working directory, which in turn imports 22 # the "my" package that defines the date() function. 23 self.runCmd("command source .lldb") 24 self.check_results() 25 26 @no_debug_info_test 27 def test_command_source_relative(self): 28 """Test that lldb command "command source" works correctly with relative paths.""" 29 30 # Sourcing .lldb in the current working directory, which in turn imports 31 # the "my" package that defines the date() function. 32 self.runCmd("command source commands2.txt") 33 self.check_results() 34 35 def check_results(self, failure=False): 36 # Python should evaluate "my.date()" successfully. 37 command_interpreter = self.dbg.GetCommandInterpreter() 38 self.assertTrue(command_interpreter, VALID_COMMAND_INTERPRETER) 39 result = lldb.SBCommandReturnObject() 40 command_interpreter.HandleCommand("script my.date()", result) 41 42 import datetime 43 if failure: 44 self.expect(result.GetOutput(), "script my.date() runs successfully", 45 exe=False, error=True) 46 else: 47 self.expect(result.GetOutput(), "script my.date() runs successfully", 48 exe=False, 49 substrs=[str(datetime.date.today())]) 50 51 @no_debug_info_test 52 def test_command_source_relative_error(self): 53 """Test that 'command source -C' gives an error for a relative path""" 54 source_dir = self.getSourceDir() 55 result = lldb.SBCommandReturnObject() 56 self.runCmd("command source --stop-on-error 1 not-relative.txt") 57 self.check_results(failure=True) 58