1# encoding: utf-8
2"""
3Test lldb data formatter subsystem.
4"""
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase
13
14
15class ObjCDataFormatterExpr(ObjCDataFormatterTestCase):
16
17    def test_expr_with_run_command(self):
18        """Test common cases of expression parser <--> formatters interaction."""
19        self.build()
20        self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
21            self, '// Set break point at this line.',
22            lldb.SBFileSpec('main.m', False))
23
24        # The stop reason of the thread should be breakpoint.
25        self.expect(
26            "thread list",
27            STOPPED_DUE_TO_BREAKPOINT,
28            substrs=['stopped', 'stop reason = breakpoint'])
29
30        # This is the function to remove the custom formats in order to have a
31        # clean slate for the next test case.
32        def cleanup():
33            self.runCmd('type format clear', check=False)
34            self.runCmd('type summary clear', check=False)
35            self.runCmd('type synth clear', check=False)
36
37        # Execute the cleanup function during test case tear down.
38        self.addTearDownHook(cleanup)
39
40        # check that the formatters are able to deal safely and correctly
41        # with ValueObjects that the expression parser returns
42        self.expect(
43            'expression ((id)@"Hello for long enough to avoid short string types")',
44            matching=False,
45            substrs=['Hello for long enough to avoid short string types'])
46
47        self.expect(
48            'expression -d run -- ((id)@"Hello for long enough to avoid short string types")',
49            substrs=['Hello for long enough to avoid short string types'])
50
51        self.expect('expr -d run -- label1', substrs=['Process Name'])
52
53        self.expect(
54            'expr -d run -- @"Hello for long enough to avoid short string types"',
55            substrs=['Hello for long enough to avoid short string types'])
56
57        self.expect(
58            'expr -d run --object-description -- @"Hello for long enough to avoid short string types"',
59            substrs=['Hello for long enough to avoid short string types'])
60        self.expect(
61            'expr -d run --object-description -- @"Hello"',
62            matching=False,
63            substrs=['@"Hello" Hello'])
64