xref: /llvm-project/lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py (revision 99451b4453688a94c6014cac233d371ab4cc342d)
1"""
2Tests std::stack functionality.
3"""
4
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9class TestStack(TestBase):
10
11    mydir = TestBase.compute_mydir(__file__)
12
13    @add_test_categories(["libc++"])
14    @skipIf(compiler=no_match("clang"))
15    def test(self):
16        self.build()
17
18        lldbutil.run_to_source_breakpoint(self,
19            "// Set break point at this line.", lldb.SBFileSpec("main.cpp"))
20
21        self.runCmd("settings set target.import-std-module true")
22
23        # Test std::stack functionality with a std::deque.
24        self.expect("expr s_deque.pop()")
25        self.expect("expr s_deque.push({4})")
26        self.expect("expr (size_t)s_deque.size()", substrs=['(size_t) $0 = 3'])
27        self.expect("expr (int)s_deque.top().i", substrs=['(int) $1 = 4'])
28        self.expect("expr s_deque.emplace(5)")
29        self.expect("expr (int)s_deque.top().i", substrs=['(int) $2 = 5'])
30
31        # Test std::stack functionality with a std::vector.
32        self.expect("expr s_vector.pop()")
33        self.expect("expr s_vector.push({4})")
34        self.expect("expr (size_t)s_vector.size()", substrs=['(size_t) $3 = 3'])
35        self.expect("expr (int)s_vector.top().i", substrs=['(int) $4 = 4'])
36        self.expect("expr s_vector.emplace(5)")
37        self.expect("expr (int)s_vector.top().i", substrs=['(int) $5 = 5'])
38
39        # Test std::stack functionality with a std::list.
40        self.expect("expr s_list.pop()")
41        self.expect("expr s_list.push({4})")
42        self.expect("expr (size_t)s_list.size()", substrs=['(size_t) $6 = 3'])
43        self.expect("expr (int)s_list.top().i", substrs=['(int) $7 = 4'])
44        self.expect("expr s_list.emplace(5)")
45        self.expect("expr (int)s_list.top().i", substrs=['(int) $8 = 5'])
46