1"""
2Test some features of "session history" and history recall.
3"""
4
5
6
7import lldb
8import lldbsuite.test.lldbutil as lldbutil
9from lldbsuite.test.lldbtest import *
10
11
12class TestHistoryRecall(TestBase):
13
14    # If your test case doesn't stress debug info, then
15    # set this to true.  That way it won't be run once for
16    # each debug info format.
17    NO_DEBUG_INFO_TESTCASE = True
18
19    def test_history_recall(self):
20        """Test the !N and !-N functionality of the command interpreter."""
21        self.do_bang_N_test()
22
23    def test_regex_history(self):
24        """Test the regex commands don't add two elements to the history"""
25        self.do_regex_history_test()
26
27    def do_regex_history_test(self):
28        interp = self.dbg.GetCommandInterpreter()
29        result = lldb.SBCommandReturnObject()
30        command = "_regexp-break foo.c:12"
31        self.runCmd(command, msg="Run the regex break command", inHistory = True)
32        interp.HandleCommand("session history", result, True)
33        self.assertTrue(result.Succeeded(), "session history ran successfully")
34        results = result.GetOutput()
35        self.assertIn(command, results, "Recorded the actual command")
36        self.assertNotIn("breakpoint set --file 'foo.c' --line 12", results,
37                         "Didn't record the resolved command")
38
39    def do_bang_N_test(self):
40        interp = self.dbg.GetCommandInterpreter()
41        result = lldb.SBCommandReturnObject()
42        interp.HandleCommand("session history", result, True)
43        interp.HandleCommand("platform list", result, True)
44
45        interp.HandleCommand("!0", result, False)
46        self.assertTrue(result.Succeeded(), "!0 command did not work: %s"%(result.GetError()))
47        self.assertIn("session history", result.GetOutput(), "!0 didn't rerun session history")
48
49        interp.HandleCommand("!-1", result, False)
50        self.assertTrue(result.Succeeded(), "!-1 command did not work: %s"%(result.GetError()))
51        self.assertIn("host:", result.GetOutput(), "!-1 didn't rerun platform list.")
52