1"""
2Test the command history mechanism
3"""
4
5import os
6import unittest2
7import lldb
8import pexpect
9from lldbtest import *
10
11class CommandHistoryTestCase(TestBase):
12
13    mydir = os.path.join("functionalities", "command_history")
14
15    def test_history(self):
16        self.runCmd('command history --clear', inHistory=False)
17        self.runCmd('breakpoint list', check=False, inHistory=True) #0
18        self.runCmd('register read', check=False, inHistory=True) #1
19        self.runCmd('apropos hello', check=False, inHistory=True) #2
20        self.runCmd('memory write', check=False, inHistory=True) #3
21        self.runCmd('log list', check=False, inHistory=True) #4
22        self.runCmd('disassemble', check=False, inHistory=True) #5
23        self.runCmd('expression 1', check=False, inHistory=True) #6
24        self.runCmd('type summary list -w default', check=False, inHistory=True) #7
25        self.runCmd('version', check=False, inHistory=True) #8
26        self.runCmd('frame select 1', check=False, inHistory=True) #9
27
28        self.expect ("command history -s 3 -c 3", inHistory=True,
29                     substrs = ['3: memory write','4: log list','5: disassemble'])
30
31        self.expect ("command history -s 3 -e 3", inHistory=True,
32                     substrs = ['3: memory write'])
33
34        self.expect ("command history -s 6 -e 7", inHistory=True,
35                     substrs = ['6: expression 1','7: type summary list -w default'])
36
37        self.expect ("command history -c 2", inHistory=True,
38                     substrs = ['0: breakpoint list','1: register read'])
39
40        self.expect ("command history -e 3 -c 1", inHistory=True,
41                     substrs = ['3: memory write'])
42
43        self.expect ("command history -e 2", inHistory=True,
44                     substrs = ['0: breakpoint list','1: register read','2: apropos hello'])
45
46        self.expect ("command history -s 12", inHistory=True,
47                     substrs = ['12: command history -s 6 -e 7','13: command history -c 2','14: command history -e 3 -c 1','15: command history -e 2','16: command history -s 12'])
48
49        self.expect ("command history -s end -c 3", inHistory=True,
50                     substrs = ['15: command history -e 2','16: command history -s 12','17: command history -s end -c 3'])
51
52        self.expect ("command history -s end -e 15", inHistory=True,
53                     substrs = ['15: command history -e 2','16: command history -s 12','17: command history -s end -c 3','command history -s end -e 15'])
54
55        self.expect ("command history -s 5 -c 1", inHistory=True,
56                     substrs = ['5: disassemble'])
57
58        self.expect ("command history -c 1 -s 5", inHistory=True,
59                     substrs = ['5: disassemble'])
60
61        self.expect ("command history -c 1 -e 3", inHistory=True,
62                     substrs = ['3: memory write'])
63
64        self.expect ("command history -c 1 -e 3 -s 5",error=True, inHistory=True,
65                     substrs = ['error: --count, --start-index and --end-index cannot be all specified in the same invocation'])
66
67
68if __name__ == '__main__':
69    import atexit
70    lldb.SBDebugger.Initialize()
71    atexit.register(lambda: lldb.SBDebugger.Terminate())
72    unittest2.main()
73