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