Johnny Chen | b9e7c0a | 2010-07-29 21:42:28 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test that lldb command "command source" works correctly. |
Johnny Chen | 8402832 | 2010-08-02 21:19:08 +0000 | [diff] [blame] | 3 | |
| 4 | See also http://llvm.org/viewvc/llvm-project?view=rev&revision=109673. |
Johnny Chen | b9e7c0a | 2010-07-29 21:42:28 +0000 | [diff] [blame] | 5 | """ |
| 6 | |
Johnny Chen | 6bcb81a | 2011-01-28 20:59:39 +0000 | [diff] [blame] | 7 | import os, sys |
Johnny Chen | 7325883 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 8 | import unittest2 |
Johnny Chen | b9e7c0a | 2010-07-29 21:42:28 +0000 | [diff] [blame] | 9 | import lldb |
Johnny Chen | 1794184 | 2010-08-09 23:44:24 +0000 | [diff] [blame] | 10 | from lldbtest import * |
Johnny Chen | b9e7c0a | 2010-07-29 21:42:28 +0000 | [diff] [blame] | 11 | |
Johnny Chen | cbb4be0 | 2010-09-01 19:59:58 +0000 | [diff] [blame] | 12 | class CommandSourceTestCase(TestBase): |
Johnny Chen | b9e7c0a | 2010-07-29 21:42:28 +0000 | [diff] [blame] | 13 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame^] | 14 | mydir = TestBase.compute_mydir(__file__) |
Johnny Chen | b9e7c0a | 2010-07-29 21:42:28 +0000 | [diff] [blame] | 15 | |
| 16 | def test_command_source(self): |
| 17 | """Test that lldb command "command source" works correctly.""" |
Johnny Chen | b9e7c0a | 2010-07-29 21:42:28 +0000 | [diff] [blame] | 18 | |
| 19 | # Sourcing .lldb in the current working directory, which in turn imports |
| 20 | # the "my" package that defines the date() function. |
Johnny Chen | 617cca9 | 2010-08-20 17:04:20 +0000 | [diff] [blame] | 21 | self.runCmd("command source .lldb") |
Johnny Chen | b9e7c0a | 2010-07-29 21:42:28 +0000 | [diff] [blame] | 22 | |
Johnny Chen | c03a362 | 2011-01-28 19:30:12 +0000 | [diff] [blame] | 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 | |
Johnny Chen | 8402832 | 2010-08-02 21:19:08 +0000 | [diff] [blame] | 29 | # Python should evaluate "my.date()" successfully. |
Johnny Chen | 9ee96e7 | 2011-04-21 22:50:23 +0000 | [diff] [blame] | 30 | # Pass 'check=False' so that sys.stdout gets restored unconditionally. |
| 31 | self.runCmd("script my.date()", check=False) |
Johnny Chen | b9e7c0a | 2010-07-29 21:42:28 +0000 | [diff] [blame] | 32 | |
Johnny Chen | 49c2245 | 2011-01-28 19:39:06 +0000 | [diff] [blame] | 33 | # Now restore stdout to the way we were. :-) |
| 34 | sys.stdout = old_stdout |
| 35 | |
Johnny Chen | c03a362 | 2011-01-28 19:30:12 +0000 | [diff] [blame] | 36 | import datetime |
| 37 | self.expect(session.getvalue(), "script my.date() runs successfully", |
| 38 | exe=False, |
| 39 | substrs = [str(datetime.date.today())]) |
| 40 | |
Johnny Chen | b9e7c0a | 2010-07-29 21:42:28 +0000 | [diff] [blame] | 41 | |
| 42 | if __name__ == '__main__': |
Johnny Chen | a212495 | 2010-08-05 21:23:45 +0000 | [diff] [blame] | 43 | import atexit |
Johnny Chen | b9e7c0a | 2010-07-29 21:42:28 +0000 | [diff] [blame] | 44 | lldb.SBDebugger.Initialize() |
Johnny Chen | a212495 | 2010-08-05 21:23:45 +0000 | [diff] [blame] | 45 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
Johnny Chen | 7325883 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 46 | unittest2.main() |