[lldb] Replace unittest2.expectedFailure with expectedFailure (NFC)
authorJonas Devlieghere <jonas@devlieghere.com>
Sat, 15 Aug 2020 00:53:47 +0000 (17:53 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Mon, 17 Aug 2020 17:05:49 +0000 (10:05 -0700)
Rename the existing expectedFailure to expectedFailureIfFn to better
describe its purpose and provide an overload for
unittest2.expectedFailure in decorators.py.

12 files changed:
lldb/packages/Python/lldbsuite/test/decorators.py
lldb/test/API/commands/expression/test/TestExprs.py
lldb/test/API/functionalities/avoids-fd-leak/TestFdLeak.py
lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/TestRequireHWBreakpoints.py
lldb/test/API/functionalities/jitloader_gdb/TestJITLoaderGDB.py
lldb/test/API/functionalities/thread/state/TestThreadStates.py
lldb/test/API/lang/c/shared_lib/TestSharedLib.py
lldb/test/API/lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py
lldb/test/API/lang/cpp/namespace/TestNamespaceLookup.py
lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
lldb/test/API/lang/objc/hidden-ivars/TestHiddenIvars.py
lldb/test/API/tools/lldb-server/TestLldbGdbServer.py

index ee2573f..85f346d 100644 (file)
@@ -85,7 +85,10 @@ def _match_decorator_property(expected, actual):
         return expected == actual
 
 
-def expectedFailure(expected_fn, bugnumber=None):
+def expectedFailure(func, bugnumber=None):
+    return unittest2.expectedFailure(func)
+
+def expectedFailureIfFn(expected_fn, bugnumber=None):
     def expectedFailure_impl(func):
         if isinstance(func, type) and issubclass(func, unittest2.TestCase):
             raise Exception(
@@ -93,11 +96,7 @@ def expectedFailure(expected_fn, bugnumber=None):
 
         @wraps(func)
         def wrapper(*args, **kwargs):
-            self = args[0]
-            if funcutils.requires_self(expected_fn):
-                xfail_reason = expected_fn(self)
-            else:
-                xfail_reason = expected_fn()
+            xfail_reason = expected_fn(*args, **kwargs)
             if xfail_reason is not None:
                 xfail_func = unittest2.expectedFailure(func)
                 xfail_func(*args, **kwargs)
@@ -234,7 +233,7 @@ def _decorateTest(mode,
     if mode == DecorateMode.Skip:
         return skipTestIfFn(fn, bugnumber)
     elif mode == DecorateMode.Xfail:
-        return expectedFailure(fn, bugnumber)
+        return expectedFailureIfFn(fn, bugnumber)
     else:
         return None
 
@@ -427,7 +426,7 @@ def expectedFailureAndroid(bugnumber=None, api_levels=None, archs=None):
         arch - A sequence of architecture names specifying the architectures
             for which a test is expected to fail. None means all architectures.
     """
-    return expectedFailure(
+    return expectedFailureIfFn(
         _skip_for_android(
             "xfailing on android",
             api_levels,
index df454cd..b56ebd8 100644 (file)
@@ -49,7 +49,7 @@ class BasicExprCommandsTestCase(TestBase):
 
         self.runCmd("run", RUN_SUCCEEDED)
 
-    @unittest2.expectedFailure(
+    @expectedFailure(
         "llvm.org/pr17135 <rdar://problem/14874559> APFloat::toString does not identify the correct (i.e. least) precision.")
     def test_floating_point_expr_commands(self):
         self.build_and_run()
index a984254..bb0a9f9 100644 (file)
@@ -24,7 +24,7 @@ class AvoidsFdLeakTestCase(TestBase):
 
     mydir = TestBase.compute_mydir(__file__)
 
-    @expectedFailure(python_leaky_fd_version, "bugs.freebsd.org/197376")
+    @expectedFailureIfFn(python_leaky_fd_version, "bugs.freebsd.org/197376")
     @expectedFailureAll(
         oslist=['freebsd'],
         bugnumber="llvm.org/pr25624 still failing with Python 2.7.10")
@@ -36,7 +36,7 @@ class AvoidsFdLeakTestCase(TestBase):
     def test_fd_leak_basic(self):
         self.do_test([])
 
-    @expectedFailure(python_leaky_fd_version, "bugs.freebsd.org/197376")
+    @expectedFailureIfFn(python_leaky_fd_version, "bugs.freebsd.org/197376")
     @expectedFailureAll(
         oslist=['freebsd'],
         bugnumber="llvm.org/pr25624 still failing with Python 2.7.10")
@@ -68,7 +68,7 @@ class AvoidsFdLeakTestCase(TestBase):
             process.GetExitStatus() == 0,
             "Process returned non-zero status. Were incorrect file descriptors passed?")
 
-    @expectedFailure(python_leaky_fd_version, "bugs.freebsd.org/197376")
+    @expectedFailureIfFn(python_leaky_fd_version, "bugs.freebsd.org/197376")
     @expectedFailureAll(
         oslist=['freebsd'],
         bugnumber="llvm.org/pr25624 still failing with Python 2.7.10")
index dfb9460..f7787bb 100644 (file)
@@ -27,7 +27,7 @@ class BreakpointLocationsTestCase(HardwareBreakpointTestBase):
         breakpoint = target.BreakpointCreateByLocation("main.c", 1)
         self.assertTrue(breakpoint.IsHardware())
 
-    @expectedFailure(supports_hw_breakpoints)
+    @expectedFailureIfFn(supports_hw_breakpoints)
     def test_step_range(self):
         """Test stepping when hardware breakpoints are required."""
         self.build()
@@ -48,7 +48,7 @@ class BreakpointLocationsTestCase(HardwareBreakpointTestBase):
         self.assertTrue("Could not create hardware breakpoint for thread plan"
                         in error.GetCString())
 
-    @expectedFailure(supports_hw_breakpoints)
+    @expectedFailureIfFn(supports_hw_breakpoints)
     def test_step_out(self):
         """Test stepping out when hardware breakpoints are required."""
         self.build()
@@ -68,7 +68,7 @@ class BreakpointLocationsTestCase(HardwareBreakpointTestBase):
         self.assertTrue("Could not create hardware breakpoint for thread plan"
                         in error.GetCString())
 
-    @expectedFailure(supports_hw_breakpoints)
+    @expectedFailureIfFn(supports_hw_breakpoints)
     def test_step_over(self):
         """Test stepping over when hardware breakpoints are required."""
         self.build()
@@ -86,7 +86,7 @@ class BreakpointLocationsTestCase(HardwareBreakpointTestBase):
                 'error: Could not create hardware breakpoint for thread plan.'
             ])
 
-    @expectedFailure(supports_hw_breakpoints)
+    @expectedFailureIfFn(supports_hw_breakpoints)
     def test_step_until(self):
         """Test stepping until when hardware breakpoints are required."""
         self.build()
index 3a89947..4a1118c 100644 (file)
@@ -16,7 +16,7 @@ class JITLoaderGDBTestCase(TestBase):
     @skipTestIfFn(
         lambda: "Skipped because the test crashes the test runner",
         bugnumber="llvm.org/pr24702")
-    @unittest2.expectedFailure("llvm.org/pr24702")
+    @expectedFailure("llvm.org/pr24702")
     def test_bogus_values(self):
         """Test that we handle inferior misusing the GDB JIT interface"""
         self.build()
index 6093808..baae905 100644 (file)
@@ -44,14 +44,14 @@ class ThreadStateTestCase(TestBase):
     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24660")
     @expectedFailureNetBSD
     # thread states not properly maintained
-    @unittest2.expectedFailure("llvm.org/pr16712")
+    @expectedFailure("llvm.org/pr16712")
     def test_state_after_expression(self):
         """Test thread state after expression."""
         self.build(dictionary=self.getBuildFlags(use_cpp11=False))
         self.thread_state_after_expression_test()
 
     # thread states not properly maintained
-    @unittest2.expectedFailure("llvm.org/pr15824 and <rdar://problem/28557237>")
+    @expectedFailure("llvm.org/pr15824 and <rdar://problem/28557237>")
     @expectedFailureAll(
         oslist=["windows"],
         bugnumber="llvm.org/pr24668: Breakpoints not resolved correctly")
index 789939b..208e892 100644 (file)
@@ -44,7 +44,7 @@ class SharedLibTestCase(TestBase):
         """Test that types work when defined in a shared library and forward-declared in the main executable, but with preloading disabled"""
         self.common_test_expr(False)
 
-    @unittest2.expectedFailure("llvm.org/PR36712")
+    @expectedFailure("llvm.org/PR36712")
     def test_frame_variable(self):
         """Test that types work when defined in a shared library and forward-declared in the main executable"""
         self.build()
index 8858f67..5888351 100644 (file)
@@ -33,7 +33,7 @@ class SharedLibStrippedTestCase(TestBase):
                 "other_element = 3"])
 
     @expectedFailureAll(oslist=["windows"])
-    @unittest2.expectedFailure("llvm.org/PR36712")
+    @expectedFailure("llvm.org/PR36712")
     def test_frame_variable(self):
         """Test that types work when defined in a shared library and forward-declared in the main executable"""
         self.build()
index 5526a14..fa8e2dd 100644 (file)
@@ -142,7 +142,7 @@ class NamespaceLookupTestCase(TestBase):
         # Evaluate B::func() - should call B::func()
         self.expect("expr -- B::func()", startstr="(int) $15 = 4")
 
-    @unittest2.expectedFailure("lldb scope lookup of functions bugs")
+    @expectedFailure("lldb scope lookup of functions bugs")
     def test_function_scope_lookup_with_run_command(self):
         """Test scope lookup of functions in lldb."""
         self.build()
@@ -179,7 +179,7 @@ class NamespaceLookupTestCase(TestBase):
         # before functions.
         self.expect("expr -- foo()", startstr="(int) $2 = 42")
 
-    @unittest2.expectedFailure("lldb file scope lookup bugs")
+    @expectedFailure("lldb file scope lookup bugs")
     @skipIfWindows # This is flakey on Windows: llvm.org/pr38373
     def test_file_scope_lookup_with_run_command(self):
         """Test file scope lookup in lldb."""
@@ -246,7 +246,7 @@ class NamespaceLookupTestCase(TestBase):
         # Evaluate func2() - should call A::func2()
         self.expect("expr -- func2()", startstr="(int) $0 = 3")
 
-    @unittest2.expectedFailure(
+    @expectedFailure(
         "lldb scope lookup after using declaration bugs")
     # NOTE: this test may fail on older systems that don't emit import
     # emtries in DWARF - may need to add checks for compiler versions here.
@@ -268,7 +268,7 @@ class NamespaceLookupTestCase(TestBase):
         # Evaluate func() - should call A::func()
         self.expect("expr -- func()", startstr="(int) $0 = 3")
 
-    @unittest2.expectedFailure("lldb scope lookup ambiguity after using bugs")
+    @expectedFailure("lldb scope lookup ambiguity after using bugs")
     def test_scope_ambiguity_after_using_lookup_with_run_command(self):
         """Test scope lookup ambiguity after using in lldb."""
         self.build()
index 4e02ebe..301f3bc 100644 (file)
@@ -15,7 +15,7 @@ class CPPStaticMembersTestCase(TestBase):
 
     mydir = TestBase.compute_mydir(__file__)
 
-    @unittest2.expectedFailure  # llvm.org/pr15401
+    @expectedFailure  # llvm.org/pr15401
     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765")
     def test_with_run_command(self):
         """Test that member variables have the correct layout, scope and qualifiers when stopped inside and outside C++ methods"""
index cc3922c..4a16a80 100644 (file)
@@ -66,7 +66,7 @@ class HiddenIvarsTestCase(TestBase):
             self.build()
             self.frame_var(False)
 
-    @unittest2.expectedFailure("rdar://18683637")
+    @expectedFailure("rdar://18683637")
     @skipUnlessDarwin
     def test_frame_variable_across_modules(self):
         if self.getArchitecture() == 'i386':
index 154f8b6..bd656fb 100644 (file)
@@ -807,7 +807,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod
             post_handle_thread_id = int(post_handle_thread_id, 16)
             self.assertEqual(post_handle_thread_id, print_thread_id)
 
-    @unittest2.expectedFailure()
+    @expectedFailure
     @debugserver_test
     @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
     def test_Hc_then_Csignal_signals_correct_thread_launch_debugserver(self):