xref: /llvm-project/lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py (revision 5ee910fef52448c141d0cd2507cee29432541cda)
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    @add_test_categories(["libc++"])
12    @skipIf(compiler=no_match("clang"))
13    @skipIfLinux # Declaration in some Linux headers causes LLDB to crash.
14    @skipIf(bugnumber="rdar://97622854")
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        stack_type = "std::stack<C>"
25        size_type = stack_type + "::size_type"
26
27        self.expect_expr("s_deque", result_type=stack_type)
28        self.expect("expr s_deque.pop()")
29        self.expect("expr s_deque.push({4})")
30        self.expect_expr("s_deque.size()",
31                         result_type=size_type,
32                         result_value="3")
33        self.expect_expr("s_deque.top().i",
34                         result_type="int",
35                         result_value="4")
36        self.expect("expr s_deque.emplace(5)")
37        self.expect_expr("s_deque.top().i",
38                         result_type="int",
39                         result_value="5")
40
41        # Test std::stack functionality with a std::vector.
42        stack_type = "std::stack<C, std::vector<C> >"
43        size_type = stack_type + "::size_type"
44
45        self.expect_expr("s_vector", result_type=stack_type)
46        self.expect("expr s_vector.pop()")
47        self.expect("expr s_vector.push({4})")
48        self.expect_expr("s_vector.size()",
49                         result_type=size_type,
50                         result_value="3")
51        self.expect_expr("s_vector.top().i",
52                         result_type="int",
53                         result_value="4")
54        self.expect("expr s_vector.emplace(5)")
55        self.expect_expr("s_vector.top().i",
56                         result_type="int",
57                         result_value="5")
58
59        # Test std::stack functionality with a std::list.
60        stack_type = "std::stack<C, std::list<C> >"
61        size_type = stack_type + "::size_type"
62        self.expect_expr("s_list", result_type=stack_type)
63        self.expect("expr s_list.pop()")
64        self.expect("expr s_list.push({4})")
65        self.expect_expr("s_list.size()",
66                         result_type=size_type,
67                         result_value="3")
68        self.expect_expr("s_list.top().i", result_type="int", result_value="4")
69        self.expect("expr s_list.emplace(5)")
70        self.expect_expr("s_list.top().i", result_type="int", result_value="5")
71