Home | History | Annotate | Download | only in command_source
      1 """
      2 Test that lldb command "command source" works correctly.
      3 
      4 See also http://llvm.org/viewvc/llvm-project?view=rev&revision=109673.
      5 """
      6 
      7 import os, sys
      8 import unittest2
      9 import lldb
     10 from lldbtest import *
     11 
     12 class CommandSourceTestCase(TestBase):
     13 
     14     mydir = os.path.join("functionalities", "command_source")
     15 
     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 
     23         # Let's temporarily redirect the stdout to our StringIO session object
     24         # in order to capture the script evaluation output.
     25         old_stdout = sys.stdout
     26         session = StringIO.StringIO()
     27         sys.stdout = session
     28 
     29         # Python should evaluate "my.date()" successfully.
     30         # Pass 'check=False' so that sys.stdout gets restored unconditionally.
     31         self.runCmd("script my.date()", check=False)
     32 
     33         # Now restore stdout to the way we were. :-)
     34         sys.stdout = old_stdout
     35 
     36         import datetime
     37         self.expect(session.getvalue(), "script my.date() runs successfully",
     38                     exe=False,
     39             substrs = [str(datetime.date.today())])
     40 
     41 
     42 if __name__ == '__main__':
     43     import atexit
     44     lldb.SBDebugger.Initialize()
     45     atexit.register(lambda: lldb.SBDebugger.Terminate())
     46     unittest2.main()
     47