1"""
2Tests target.expr-error-limit.
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class TestCase(TestBase):
12
13    @no_debug_info_test
14    def test(self):
15        # FIXME: The only reason this test needs to create a real target is because
16        # the settings of the dummy target can't be changed with `settings set`.
17        self.build()
18        target = self.createTestTarget()
19
20        # Our test expression that is just several lines of malformed
21        # integer literals (with a 'yerror' integer suffix). Every error
22        # has its own unique string (1, 2, 3, 4) and is on its own line
23        # that we can later find it when Clang prints the respective source
24        # code for each error to the error output.
25        # For example, in the error output below we would look for the
26        # unique `1yerror` string:
27        #     error: <expr>:1:2: invalid suffix 'yerror' on integer constant
28        #     1yerror
29        #     ^
30        expr = "1yerror;\n2yerror;\n3yerror;\n4yerror;"
31
32        options = lldb.SBExpressionOptions()
33        options.SetAutoApplyFixIts(False)
34
35        # Evaluate the expression and check that only the first 2 errors are
36        # emitted.
37        self.runCmd("settings set target.expr-error-limit 2")
38        eval_result = target.EvaluateExpression(expr, options)
39        self.assertIn("1yerror", str(eval_result.GetError()))
40        self.assertIn("2yerror", str(eval_result.GetError()))
41        self.assertNotIn("3yerror", str(eval_result.GetError()))
42        self.assertNotIn("4yerror", str(eval_result.GetError()))
43
44        # Change to a 3 errors and check again which errors are emitted.
45        self.runCmd("settings set target.expr-error-limit 3")
46        eval_result = target.EvaluateExpression(expr, options)
47        self.assertIn("1yerror", str(eval_result.GetError()))
48        self.assertIn("2yerror", str(eval_result.GetError()))
49        self.assertIn("3yerror", str(eval_result.GetError()))
50        self.assertNotIn("4yerror", str(eval_result.GetError()))
51
52        # Disable the error limit and make sure all errors are emitted.
53        self.runCmd("settings set target.expr-error-limit 0")
54        eval_result = target.EvaluateExpression(expr, options)
55        self.assertIn("1yerror", str(eval_result.GetError()))
56        self.assertIn("2yerror", str(eval_result.GetError()))
57        self.assertIn("3yerror", str(eval_result.GetError()))
58        self.assertIn("4yerror", str(eval_result.GetError()))
59