199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest that lldb command "command source" works correctly. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprecht 699451b44SJordan Rupprecht 799451b44SJordan Rupprechtimport lldb 899451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 999451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 1099451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 1199451b44SJordan Rupprecht 1299451b44SJordan Rupprecht 1399451b44SJordan Rupprechtclass CommandSourceTestCase(TestBase): 1499451b44SJordan Rupprecht 1599451b44SJordan Rupprecht @no_debug_info_test 1699451b44SJordan Rupprecht def test_command_source(self): 1799451b44SJordan Rupprecht """Test that lldb command "command source" works correctly.""" 1899451b44SJordan Rupprecht 1999451b44SJordan Rupprecht # Sourcing .lldb in the current working directory, which in turn imports 2099451b44SJordan Rupprecht # the "my" package that defines the date() function. 2199451b44SJordan Rupprecht self.runCmd("command source .lldb") 22*3bf3b966SJim Ingham self.check_results() 2399451b44SJordan Rupprecht 24*3bf3b966SJim Ingham @no_debug_info_test 25*3bf3b966SJim Ingham def test_command_source_relative(self): 26*3bf3b966SJim Ingham """Test that lldb command "command source" works correctly with relative paths.""" 27*3bf3b966SJim Ingham 28*3bf3b966SJim Ingham # Sourcing .lldb in the current working directory, which in turn imports 29*3bf3b966SJim Ingham # the "my" package that defines the date() function. 30*3bf3b966SJim Ingham self.runCmd("command source commands2.txt") 31*3bf3b966SJim Ingham self.check_results() 32*3bf3b966SJim Ingham 33*3bf3b966SJim Ingham def check_results(self, failure=False): 3499451b44SJordan Rupprecht # Python should evaluate "my.date()" successfully. 3599451b44SJordan Rupprecht command_interpreter = self.dbg.GetCommandInterpreter() 3699451b44SJordan Rupprecht self.assertTrue(command_interpreter, VALID_COMMAND_INTERPRETER) 3799451b44SJordan Rupprecht result = lldb.SBCommandReturnObject() 3899451b44SJordan Rupprecht command_interpreter.HandleCommand("script my.date()", result) 3999451b44SJordan Rupprecht 4099451b44SJordan Rupprecht import datetime 41*3bf3b966SJim Ingham if failure: 42*3bf3b966SJim Ingham self.expect(result.GetOutput(), "script my.date() runs successfully", 43*3bf3b966SJim Ingham exe=False, error=True) 44*3bf3b966SJim Ingham else: 4599451b44SJordan Rupprecht self.expect(result.GetOutput(), "script my.date() runs successfully", 4699451b44SJordan Rupprecht exe=False, 4799451b44SJordan Rupprecht substrs=[str(datetime.date.today())]) 48*3bf3b966SJim Ingham 49*3bf3b966SJim Ingham @no_debug_info_test 50*3bf3b966SJim Ingham def test_command_source_relative_error(self): 51*3bf3b966SJim Ingham """Test that 'command source -C' gives an error for a relative path""" 52*3bf3b966SJim Ingham source_dir = self.getSourceDir() 53*3bf3b966SJim Ingham result = lldb.SBCommandReturnObject() 54*3bf3b966SJim Ingham self.runCmd("command source --stop-on-error 1 not-relative.txt") 55*3bf3b966SJim Ingham self.check_results(failure=True) 56