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