xref: /llvm-project/lldb/test/API/test_utils/TestDecorators.py (revision a4c18137d84bc48df49ee0101bef465a955e62ac)
1import re
2
3from lldbsuite.test.lldbtest import TestBase
4from lldbsuite.test.decorators import *
5
6
7def expectedFailureDwarf(bugnumber=None):
8    return expectedFailureAll(bugnumber, debug_info="dwarf")
9
10
11class TestDecoratorsNoDebugInfoClass(TestBase):
12    NO_DEBUG_INFO_TESTCASE = True
13
14    @expectedFailureAll(debug_info="dwarf")
15    def test_decorator_xfail(self):
16        """Test that specifying a debug info category works for a NO_DEBUG_INFO_TESTCASE"""
17
18    @expectedFailureDwarf
19    def test_decorator_xfail_bare_decorator(self):
20        """Same as test_decorator_xfail, but with a custom decorator w/ a bare syntax"""
21
22    @expectedFailureDwarf()
23    def test_decorator_xfail_decorator_empty_args(self):
24        """Same as test_decorator_xfail, but with a custom decorator w/ no args"""
25
26    @add_test_categories(["dwarf"])
27    def test_add_test_categories(self):
28        # Note: the "dwarf" test category is ignored, because we don't generate any debug info test variants
29        self.assertIsNone(self.getDebugInfo())
30
31    @expectedFailureAll
32    def test_xfail_empty(self):
33        """Test that expectedFailureAll can be empty (but please just use expectedFailure)"""
34        self.fail()
35
36    @expectedFailureAll(compiler=re.compile(".*"))
37    def test_xfail_regexp(self):
38        """Test that xfail can take a regex as a matcher"""
39        self.fail()
40
41    @expectedFailureAll(compiler=no_match(re.compile(".*")))
42    def test_xfail_no_match(self):
43        """Test that xfail can take a no_match matcher"""
44        pass
45
46    @expectedFailureIf(condition=True)
47    def test_xfail_condition_true(self):
48        self.fail()
49
50    @expectedFailureIf(condition=False)
51    def test_xfail_condition_false(self):
52        pass
53
54
55class TestDecorators(TestBase):
56    @expectedFailureAll(debug_info="dwarf")
57    def test_decorator_xfail(self):
58        """Test that expectedFailureAll fails for the debug_info variant"""
59        if self.getDebugInfo() == "dwarf":
60            self.fail()
61
62    @skipIf(debug_info="dwarf")
63    def test_decorator_skip(self):
64        """Test that skipIf skips the debug_info variant"""
65        self.assertNotEqual(self.getDebugInfo(), "dwarf")
66
67    @expectedFailureDwarf
68    def test_decorator_xfail2(self):
69        """Same as test_decorator_xfail, but with a custom decorator w/ a bare syntax"""
70        if self.getDebugInfo() == "dwarf":
71            self.fail()
72
73    @expectedFailureDwarf()
74    def test_decorator_xfail3(self):
75        """Same as test_decorator_xfail, but with a custom decorator w/ no args"""
76        if self.getDebugInfo() == "dwarf":
77            self.fail()
78
79    @add_test_categories(["dwarf"])
80    def test_add_test_categories(self):
81        """Test that add_test_categories limits the kinds of debug info test variants"""
82        self.assertEqual(self.getDebugInfo(), "dwarf")
83
84    @expectedFailureAll(compiler="fake", debug_info="dwarf")
85    def test_decorator_xfail_all(self):
86        """Test that expectedFailureAll requires all conditions to match to be xfail"""
87
88    @skipIf(compiler="fake", debug_info="dwarf")
89    def test_decorator_skip2(self):
90        """Test that expectedFailureAll fails for the debug_info variant"""
91        # Note: the following assertion would fail, if this were not skipped:
92        # self.assertNotEqual(self.getDebugInfo(), "dwarf")
93
94    @expectedFailureAll
95    def test_xfail_empty(self):
96        """Test that xfail can be empty"""
97        self.fail()
98
99    @expectedFailureAll(compiler=re.compile(".*"))
100    def test_xfail_regexp(self):
101        """Test that xfail can take a regex as a matcher"""
102        self.fail()
103
104    @expectedFailureAll(compiler=no_match(re.compile(".*")))
105    def test_xfail_no_match(self):
106        """Test that xfail can take a no_match matcher"""
107        pass
108
109    @expectedFailureIf(condition=True)
110    def test_xfail_condition_true(self):
111        self.fail()
112
113    @expectedFailureIf(condition=False)
114    def test_xfail_condition_false(self):
115        pass
116