blob: c3eeee6fc56cbf5a9e2e90f40a4c68125ba7fdd7 [file] [log] [blame]
Johnny Chenb9e7c0a2010-07-29 21:42:28 +00001"""
2Test that lldb command "command source" works correctly.
Johnny Chen84028322010-08-02 21:19:08 +00003
4See also http://llvm.org/viewvc/llvm-project?view=rev&revision=109673.
Johnny Chenb9e7c0a2010-07-29 21:42:28 +00005"""
6
Johnny Chen6bcb81a2011-01-28 20:59:39 +00007import os, sys
Johnny Chen73258832010-08-05 23:42:46 +00008import unittest2
Johnny Chenb9e7c0a2010-07-29 21:42:28 +00009import lldb
Johnny Chen17941842010-08-09 23:44:24 +000010from lldbtest import *
Johnny Chenb9e7c0a2010-07-29 21:42:28 +000011
Johnny Chencbb4be02010-09-01 19:59:58 +000012class CommandSourceTestCase(TestBase):
Johnny Chenb9e7c0a2010-07-29 21:42:28 +000013
Greg Clayton4570d3e2013-12-10 23:19:29 +000014 mydir = TestBase.compute_mydir(__file__)
Johnny Chenb9e7c0a2010-07-29 21:42:28 +000015
16 def test_command_source(self):
17 """Test that lldb command "command source" works correctly."""
Johnny Chenb9e7c0a2010-07-29 21:42:28 +000018
19 # Sourcing .lldb in the current working directory, which in turn imports
20 # the "my" package that defines the date() function.
Johnny Chen617cca92010-08-20 17:04:20 +000021 self.runCmd("command source .lldb")
Johnny Chenb9e7c0a2010-07-29 21:42:28 +000022
Johnny Chenc03a3622011-01-28 19:30:12 +000023 # 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
Johnny Chen84028322010-08-02 21:19:08 +000029 # Python should evaluate "my.date()" successfully.
Johnny Chen9ee96e72011-04-21 22:50:23 +000030 # Pass 'check=False' so that sys.stdout gets restored unconditionally.
31 self.runCmd("script my.date()", check=False)
Johnny Chenb9e7c0a2010-07-29 21:42:28 +000032
Johnny Chen49c22452011-01-28 19:39:06 +000033 # Now restore stdout to the way we were. :-)
34 sys.stdout = old_stdout
35
Johnny Chenc03a3622011-01-28 19:30:12 +000036 import datetime
37 self.expect(session.getvalue(), "script my.date() runs successfully",
38 exe=False,
39 substrs = [str(datetime.date.today())])
40
Johnny Chenb9e7c0a2010-07-29 21:42:28 +000041
42if __name__ == '__main__':
Johnny Chena2124952010-08-05 21:23:45 +000043 import atexit
Johnny Chenb9e7c0a2010-07-29 21:42:28 +000044 lldb.SBDebugger.Initialize()
Johnny Chena2124952010-08-05 21:23:45 +000045 atexit.register(lambda: lldb.SBDebugger.Terminate())
Johnny Chen73258832010-08-05 23:42:46 +000046 unittest2.main()