xref: /llvm-project/lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Tests std::stack functionality.
3"""
4
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9
10class TestStack(TestBase):
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(
19            self, "// Set break point at this line.", lldb.SBFileSpec("main.cpp")
20        )
21
22        self.runCmd("settings set target.import-std-module true")
23
24        # Test std::stack functionality with a std::deque.
25        stack_type = "std::stack<C>"
26        size_type = stack_type + "::size_type"
27
28        self.expect_expr("s_deque", result_type=stack_type)
29        self.expect("expr s_deque.pop()")
30        self.expect("expr s_deque.push({4})")
31        self.expect_expr("s_deque.size()", result_type=size_type, result_value="3")
32        self.expect_expr("s_deque.top().i", result_type="int", result_value="4")
33        self.expect("expr s_deque.emplace(5)")
34        self.expect_expr("s_deque.top().i", result_type="int", result_value="5")
35
36        # Test std::stack functionality with a std::vector.
37        stack_type = "std::stack<C, std::vector<C> >"
38        size_type = stack_type + "::size_type"
39
40        self.expect_expr("s_vector", result_type=stack_type)
41        self.expect("expr s_vector.pop()")
42        self.expect("expr s_vector.push({4})")
43        self.expect_expr("s_vector.size()", result_type=size_type, result_value="3")
44        self.expect_expr("s_vector.top().i", result_type="int", result_value="4")
45        self.expect("expr s_vector.emplace(5)")
46        self.expect_expr("s_vector.top().i", result_type="int", result_value="5")
47
48        # Test std::stack functionality with a std::list.
49        stack_type = "std::stack<C, std::list<C> >"
50        size_type = stack_type + "::size_type"
51        self.expect_expr("s_list", result_type=stack_type)
52        self.expect("expr s_list.pop()")
53        self.expect("expr s_list.push({4})")
54        self.expect_expr("s_list.size()", result_type=size_type, result_value="3")
55        self.expect_expr("s_list.top().i", result_type="int", result_value="4")
56        self.expect("expr s_list.emplace(5)")
57        self.expect_expr("s_list.top().i", result_type="int", result_value="5")
58