xref: /llvm-project/lldb/test/API/lang/cpp/union-static-data-members/TestCppUnionStaticMembers.py (revision f74aaca63202cabb512c78fe19196ff348d436a8)
1"""
2Tests that frame variable and expr work for
3C++ unions and their static data members.
4"""
5import lldb
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test.decorators import *
8import lldbsuite.test.lldbutil as lldbutil
9
10class CppUnionStaticMembersTestCase(TestBase):
11    def test(self):
12        """Tests that frame variable and expr work
13           for union static data members"""
14        self.build()
15
16        (target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(
17            self, "return 0", lldb.SBFileSpec("main.cpp")
18        )
19
20        self.expect("frame variable foo", substrs=["val = 42"])
21        self.expect("frame variable bar", substrs=["val = 137"])
22
23        self.expect_expr("foo", result_type="Foo", result_children=[ValueCheck(
24                name="val", value="42"
25            )])
26        self.expect_expr("bar", result_type="Bar", result_children=[ValueCheck(
27                name="val", value="137"
28            )])
29
30        self.expect_expr("Foo::sVal1", result_type="const int", result_value="-42")
31        self.expect_expr("Foo::sVal2", result_type="Foo", result_children=[ValueCheck(
32                name="val", value="42"
33            )])
34
35    @expectedFailureAll
36    def test_union_in_anon_namespace(self):
37        """Tests that frame variable and expr work
38           for union static data members in anonymous
39           namespaces"""
40        self.expect_expr("Bar::sVal1", result_type="const int", result_value="-137")
41        self.expect_expr("Bar::sVal2", result_type="Bar", result_children=[ValueCheck(
42                name="val", value="137"
43            )])
44