1"""
2Test lldb data formatter subsystem.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12class LibcxxVariantDataFormatterTestCase(TestBase):
13
14    @add_test_categories(["libc++"])
15    ## Clang 7.0 is the oldest Clang that can reliably parse newer libc++ versions
16    ## with -std=c++17.
17    @skipIf(oslist=no_match(["macosx"]), compiler="clang", compiler_version=['<', '7.0'])
18    ## We are skipping gcc version less that 5.1 since this test requires -std=c++17
19    @skipIf(compiler="gcc", compiler_version=['<', '5.1'])
20    ## std::get is unavailable for std::variant before macOS 10.14
21    @skipIf(macos_version=["<", "10.14"])
22
23    def test_with_run_command(self):
24        """Test that that file and class static variables display correctly."""
25        self.build()
26
27        (self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here',
28                lldb.SBFileSpec("main.cpp", False))
29
30        self.runCmd( "frame variable has_variant" )
31
32        output = self.res.GetOutput()
33
34        ## The variable has_variant tells us if the test program
35        ## detected we have a sufficient libc++ version to support variant
36        ## false means we do not and therefore should skip the test
37        if output.find("(bool) has_variant = false") != -1 :
38            self.skipTest( "std::variant not supported" )
39
40        lldbutil.continue_to_breakpoint(self.process, bkpt)
41
42        self.expect("frame variable v1",
43                substrs=['v1 =  Active Type = int  {',
44                               'Value = 12',
45                               '}'])
46
47        self.expect("frame variable v1_ref",
48                substrs=['v1_ref =  Active Type = int : {',
49                               'Value = 12',
50                               '}'])
51
52        self.expect("frame variable v_v1",
53                substrs=['v_v1 =  Active Type = std::variant<int, double, char>  {',
54                                 'Value =  Active Type = int  {',
55                                   'Value = 12',
56                                 '}',
57                               '}'])
58
59        lldbutil.continue_to_breakpoint(self.process, bkpt)
60
61        self.expect("frame variable v1",
62                substrs=['v1 =  Active Type = double  {',
63                               'Value = 2',
64                               '}'])
65
66        lldbutil.continue_to_breakpoint(self.process, bkpt)
67
68        self.expect("frame variable v2",
69                substrs=['v2 =  Active Type = double  {',
70                               'Value = 2',
71                               '}'])
72
73        self.expect("frame variable v3",
74                substrs=['v3 =  Active Type = char  {',
75                               'Value = \'A\'',
76                               '}'])
77
78        self.expect("frame variable v_no_value",
79                    substrs=['v_no_value =  No Value'])
80