xref: /llvm-project/lldb/test/API/functionalities/history/TestHistoryRecall.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprecht"""
28cc8b36fSJim InghamTest some features of "session history" and history recall.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprecht
699451b44SJordan Rupprechtimport lldb
799451b44SJordan Rupprechtimport lldbsuite.test.lldbutil as lldbutil
899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
999451b44SJordan Rupprecht
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprechtclass TestHistoryRecall(TestBase):
12c6ad6901SVenkata Ramanaiah Nalamothu    # If your test case doesn't stress debug info, then
1399451b44SJordan Rupprecht    # set this to true.  That way it won't be run once for
1499451b44SJordan Rupprecht    # each debug info format.
1599451b44SJordan Rupprecht    NO_DEBUG_INFO_TESTCASE = True
1699451b44SJordan Rupprecht
1799451b44SJordan Rupprecht    def test_history_recall(self):
1899451b44SJordan Rupprecht        """Test the !N and !-N functionality of the command interpreter."""
198cc8b36fSJim Ingham        self.do_bang_N_test()
2099451b44SJordan Rupprecht
218cc8b36fSJim Ingham    def test_regex_history(self):
228cc8b36fSJim Ingham        """Test the regex commands don't add two elements to the history"""
238cc8b36fSJim Ingham        self.do_regex_history_test()
248cc8b36fSJim Ingham
258cc8b36fSJim Ingham    def do_regex_history_test(self):
268cc8b36fSJim Ingham        interp = self.dbg.GetCommandInterpreter()
278cc8b36fSJim Ingham        result = lldb.SBCommandReturnObject()
288cc8b36fSJim Ingham        command = "_regexp-break foo.c:12"
298cc8b36fSJim Ingham        self.runCmd(command, msg="Run the regex break command", inHistory=True)
308cc8b36fSJim Ingham        interp.HandleCommand("session history", result, True)
318cc8b36fSJim Ingham        self.assertTrue(result.Succeeded(), "session history ran successfully")
328cc8b36fSJim Ingham        results = result.GetOutput()
338cc8b36fSJim Ingham        self.assertIn(command, results, "Recorded the actual command")
34*2238dcc3SJonas Devlieghere        self.assertNotIn(
35*2238dcc3SJonas Devlieghere            "breakpoint set --file 'foo.c' --line 12",
36*2238dcc3SJonas Devlieghere            results,
37*2238dcc3SJonas Devlieghere            "Didn't record the resolved command",
38*2238dcc3SJonas Devlieghere        )
398cc8b36fSJim Ingham
408cc8b36fSJim Ingham    def do_bang_N_test(self):
4199451b44SJordan Rupprecht        interp = self.dbg.GetCommandInterpreter()
4299451b44SJordan Rupprecht        result = lldb.SBCommandReturnObject()
43e605994bSMed Ismail Bennani        interp.HandleCommand("session history", result, True)
4499451b44SJordan Rupprecht        interp.HandleCommand("platform list", result, True)
4599451b44SJordan Rupprecht
4699451b44SJordan Rupprecht        interp.HandleCommand("!0", result, False)
47*2238dcc3SJonas Devlieghere        self.assertTrue(
48*2238dcc3SJonas Devlieghere            result.Succeeded(), "!0 command did not work: %s" % (result.GetError())
49*2238dcc3SJonas Devlieghere        )
50*2238dcc3SJonas Devlieghere        self.assertIn(
51*2238dcc3SJonas Devlieghere            "session history", result.GetOutput(), "!0 didn't rerun session history"
52*2238dcc3SJonas Devlieghere        )
5399451b44SJordan Rupprecht
5499451b44SJordan Rupprecht        interp.HandleCommand("!-1", result, False)
55*2238dcc3SJonas Devlieghere        self.assertTrue(
56*2238dcc3SJonas Devlieghere            result.Succeeded(), "!-1 command did not work: %s" % (result.GetError())
57*2238dcc3SJonas Devlieghere        )
583cc37622SDave Lee        self.assertIn("host:", result.GetOutput(), "!-1 didn't rerun platform list.")
59