[Lldb-commits] [lldb] 3567497 - [lldb/Test] Introduce "assertSuccess"

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue Jun 30 06:41:18 PDT 2020


Author: Pavel Labath
Date: 2020-06-30T15:41:03+02:00
New Revision: 35674976f09ec99e74d0d28b4a64b6bce360c128

URL: https://github.com/llvm/llvm-project/commit/35674976f09ec99e74d0d28b4a64b6bce360c128
DIFF: https://github.com/llvm/llvm-project/commit/35674976f09ec99e74d0d28b4a64b6bce360c128.diff

LOG: [lldb/Test] Introduce "assertSuccess"

Summary:
A lot of our tests do 'self.assertTrue(error.Success()'. The problem
with that is that when this fails, it produces a completely useless
error message (False is not True) and the most important piece of
information -- the actual error message -- is completely hidden.

Sometimes we mitigate that by including the error message in the "msg"
argument, but this has two additional problems:
- as the msg argument is evaluated unconditionally, one needs to be
  careful to not trigger an exception when the operation was actually
  successful.
- it requires more typing, which means we often don't do it

assertSuccess solves these problems by taking the entire SBError object
as an argument. If the operation was unsuccessful, it can format a
reasonable error message itself. The function still accepts a "msg"
argument, which can include any additional context, but this context now
does not need to include the error message.

To demonstrate usage, I replace a number of existing assertTrue
assertions with the new function. As this process is not easily
automatable, I have just manually updated a representative sample. In
some cases, I did not update the code to use assertSuccess, but I went
for even higher-level assertion apis (runCmd, expect_expr), as these are
even shorter, and can produce even better failure messages.

Reviewers: teemperor, JDevlieghere

Subscribers: arphaman, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D82759

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/lldbtest.py
    lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
    lldb/test/API/commands/expression/call-throws/TestCallThatThrows.py
    lldb/test/API/commands/expression/context-object-objc/TestContextObjectObjc.py
    lldb/test/API/commands/expression/context-object/TestContextObject.py
    lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py
    lldb/test/API/commands/expression/fixits/TestFixIts.py
    lldb/test/API/commands/expression/options/TestExprOptions.py
    lldb/test/API/commands/expression/pr35310/TestExprsBug35310.py
    lldb/test/API/commands/expression/result_numbering/TestResultNumbering.py
    lldb/test/API/commands/expression/scoped_enums/TestScopedEnumType.py
    lldb/test/API/commands/expression/timeout/TestCallWithTimeout.py
    lldb/test/API/commands/expression/unwind_expression/TestUnwindExpression.py
    lldb/test/API/commands/expression/weak_symbols/TestWeakSymbols.py
    lldb/test/API/commands/register/register/register_command/TestRegisters.py
    lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
    lldb/test/API/python_api/hello_world/TestHelloWorld.py

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 481c23671228..35865d9e0d5c 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -2481,9 +2481,7 @@ def expect_expr(
         else:
           eval_result = self.target().EvaluateExpression(expr, options)
 
-        if not eval_result.GetError().Success():
-            self.assertTrue(eval_result.GetError().Success(),
-                "Unexpected failure with msg: " + eval_result.GetError().GetCString())
+        self.assertSuccess(eval_result.GetError())
 
         if result_type:
             self.assertEqual(result_type, eval_result.GetDisplayTypeName())
@@ -2535,6 +2533,13 @@ def run_platform_command(self, cmd):
         err = platform.Run(shell_command)
         return (err, shell_command.GetStatus(), shell_command.GetOutput())
 
+    """Assert that an lldb.SBError is in the "success" state."""
+    def assertSuccess(self, obj, msg=None):
+        if not obj.Success():
+            error = obj.GetCString()
+            self.fail(self._formatMessage(msg,
+                "'{}' is not success".format(error)))
+
     # =================================================
     # Misc. helper methods for debugging test execution
     # =================================================

diff  --git a/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py b/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
index f48cc5e6332b..a7e1a8c800cc 100644
--- a/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
+++ b/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
@@ -52,10 +52,7 @@ def call_function(self):
                                       'Stop here in main.', self.main_source_spec)
 
         # Make sure the SIGCHLD behavior is pass/no-stop/no-notify:
-        return_obj = lldb.SBCommandReturnObject()
-        self.dbg.GetCommandInterpreter().HandleCommand(
-            "process handle SIGCHLD -s 0 -p 1 -n 0", return_obj)
-        self.assertTrue(return_obj.Succeeded(), "Set SIGCHLD to pass, no-stop")
+        self.runCmd("process handle SIGCHLD -s 0 -p 1 -n 0")
 
         # The sigchld_no variable should be 0 at this point.
         self.sigchld_no = target.FindFirstGlobalVariable("sigchld_no")
@@ -84,7 +81,7 @@ def call_function(self):
             "call_me (%d)" %
             (num_sigchld), options)
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEquals(value.GetValueAsSigned(-1), num_sigchld)
 
         self.check_after_call(num_sigchld)
@@ -101,23 +98,21 @@ def call_function(self):
             "call_me (%d)" %
             (num_sigchld), options)
 
-        self.assertTrue(value.IsValid() and value.GetError().Success())
+        self.assertTrue(value.IsValid())
+        self.assertSuccess(value.GetError())
         self.assertEquals(value.GetValueAsSigned(-1), num_sigchld)
         self.check_after_call(num_sigchld)
 
         # Now set the signal to print but not stop and make sure that calling
         # still works:
-        self.dbg.GetCommandInterpreter().HandleCommand(
-            "process handle SIGCHLD -s 0 -p 1 -n 1", return_obj)
-        self.assertTrue(
-            return_obj.Succeeded(),
-            "Set SIGCHLD to pass, no-stop, notify")
+        self.runCmd("process handle SIGCHLD -s 0 -p 1 -n 1")
 
         value = frame.EvaluateExpression(
             "call_me (%d)" %
             (num_sigchld), options)
 
-        self.assertTrue(value.IsValid() and value.GetError().Success())
+        self.assertTrue(value.IsValid())
+        self.assertSuccess(value.GetError())
         self.assertEquals(value.GetValueAsSigned(-1), num_sigchld)
         self.check_after_call(num_sigchld)
 
@@ -128,36 +123,28 @@ def call_function(self):
             "call_me (%d)" %
             (num_sigchld), options)
 
-        self.assertTrue(value.IsValid() and value.GetError().Success())
+        self.assertTrue(value.IsValid())
+        self.assertSuccess(value.GetError())
         self.assertEquals(value.GetValueAsSigned(-1), num_sigchld)
         self.check_after_call(num_sigchld)
 
         # Okay, now set UnwindOnError to true, and then make the signal behavior to stop
         # and see that now we do stop at the signal point:
 
-        self.dbg.GetCommandInterpreter().HandleCommand(
-            "process handle SIGCHLD -s 1 -p 1 -n 1", return_obj)
-        self.assertTrue(
-            return_obj.Succeeded(),
-            "Set SIGCHLD to pass, stop, notify")
+        self.runCmd("process handle SIGCHLD -s 1 -p 1 -n 1")
 
         value = frame.EvaluateExpression(
             "call_me (%d)" %
             (num_sigchld), options)
-        self.assertTrue(
-            value.IsValid() and value.GetError().Success() == False)
+        self.assertTrue(value.IsValid())
+        self.assertFalse(value.GetError().Success())
 
         # Set signal handling back to no-stop, and continue and we should end
         # up back in out starting frame:
-        self.dbg.GetCommandInterpreter().HandleCommand(
-            "process handle SIGCHLD -s 0 -p 1 -n 1", return_obj)
-        self.assertTrue(
-            return_obj.Succeeded(),
-            "Set SIGCHLD to pass, no-stop, notify")
+        self.runCmd("process handle SIGCHLD -s 0 -p 1 -n 1")
 
         error = process.Continue()
-        self.assertTrue(
-            error.Success(),
+        self.assertSuccess(error,
             "Continuing after stopping for signal succeeds.")
 
         frame = self.thread.GetFrameAtIndex(0)

diff  --git a/lldb/test/API/commands/expression/call-throws/TestCallThatThrows.py b/lldb/test/API/commands/expression/call-throws/TestCallThatThrows.py
index 9fe1405c3d72..eb84b7b54eb6 100644
--- a/lldb/test/API/commands/expression/call-throws/TestCallThatThrows.py
+++ b/lldb/test/API/commands/expression/call-throws/TestCallThatThrows.py
@@ -88,7 +88,7 @@ def call_function(self):
         options.SetTrapExceptions(False)
         value = frame.EvaluateExpression("[my_class iCatchMyself]", options)
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEquals(value.GetValueAsUnsigned(), 57)
         self.check_after_call()
         options.SetTrapExceptions(True)

diff  --git a/lldb/test/API/commands/expression/context-object-objc/TestContextObjectObjc.py b/lldb/test/API/commands/expression/context-object-objc/TestContextObjectObjc.py
index 4ae4fd8680d8..36384b752751 100644
--- a/lldb/test/API/commands/expression/context-object-objc/TestContextObjectObjc.py
+++ b/lldb/test/API/commands/expression/context-object-objc/TestContextObjectObjc.py
@@ -44,13 +44,13 @@ def test_context_object_objc(self):
         # Test retrieving of an objcClass's property through the self pointer
         value = obj_val.EvaluateExpression("self.property")
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEqual(value.GetValueAsSigned(), 2222)
 
         # Test objcClass's methods evaluation through the self pointer
         value = obj_val.EvaluateExpression("[self method]")
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEqual(value.GetValueAsSigned(), 3333)
 
         # Test if we can use a computation result reference object correctly
@@ -63,12 +63,12 @@ def test_context_object_objc(self):
         # Test an expression evaluation on it
         value = obj_val.EvaluateExpression("1")
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
 
         # Test retrieving of a field on it
         value = obj_val.EvaluateExpression("field")
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEqual(value.GetValueAsSigned(), 1111)
 
     def setUp(self):

diff  --git a/lldb/test/API/commands/expression/context-object/TestContextObject.py b/lldb/test/API/commands/expression/context-object/TestContextObject.py
index 02b8162aad65..b7dc6d53dc47 100644
--- a/lldb/test/API/commands/expression/context-object/TestContextObject.py
+++ b/lldb/test/API/commands/expression/context-object/TestContextObject.py
@@ -32,19 +32,19 @@ def test_context_object(self):
         # Test retrieveing of a field (not a local with the same name)
         value = obj_val.EvaluateExpression("field")
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEqual(value.GetValueAsSigned(), 1111)
 
         # Test functions evaluation
         value = obj_val.EvaluateExpression("function()")
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEqual(value.GetValueAsSigned(), 2222)
 
         # Test that we retrieve the right global
         value = obj_val.EvaluateExpression("global.field")
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEqual(value.GetValueAsSigned(), 1111)
 
         #
@@ -57,7 +57,7 @@ def test_context_object(self):
         # Test retrieveing of a field
         value = obj_val.EvaluateExpression("field_int")
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEqual(value.GetValueAsSigned(), 5555)
 
         #
@@ -87,7 +87,7 @@ def test_context_object(self):
         # Test retrieveing of an element's field
         value = obj_val.GetValueForExpressionPath("[7]").EvaluateExpression("field")
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEqual(value.GetValueAsSigned(), 1111)
 
         #
@@ -105,7 +105,7 @@ def test_context_object(self):
         # Test retrieveing of a dereferenced object's field
         value = obj_val.Dereference().EvaluateExpression("field")
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEqual(value.GetValueAsSigned(), 1111)
 
         #
@@ -135,7 +135,7 @@ def test_context_object(self):
         # Test retrieveing of a dereferenced object's field
         value = obj_val.Dereference().EvaluateExpression("field")
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEqual(value.GetValueAsSigned(), 1111)
 
     def setUp(self):

diff  --git a/lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py b/lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py
index c70e90e7a26f..083d97adf1b2 100644
--- a/lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py
+++ b/lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py
@@ -58,7 +58,7 @@ def expr_options_test(self):
 
         # Now use the options:
         result = frame.EvaluateExpression("call_me(10)", options)
-        self.assertTrue(result.GetError().Success(), "expression succeeded")
+        self.assertSuccess(result.GetError())
         self.assertEqual(result.GetValueAsSigned(), 18, "got the right value.")
 
         # Now disallow JIT and make sure it fails:
@@ -77,6 +77,6 @@ def expr_options_test(self):
 
         # And again, make sure this works:
         result = frame.EvaluateExpression("call_me(10)", options)
-        self.assertTrue(result.GetError().Success(), "expression succeeded")
+        self.assertSuccess(result.GetError())
         self.assertEqual(result.GetValueAsSigned(), 18, "got the right value.")
 

diff  --git a/lldb/test/API/commands/expression/fixits/TestFixIts.py b/lldb/test/API/commands/expression/fixits/TestFixIts.py
index 9907c2557788..59a1eb2d2abf 100644
--- a/lldb/test/API/commands/expression/fixits/TestFixIts.py
+++ b/lldb/test/API/commands/expression/fixits/TestFixIts.py
@@ -42,7 +42,7 @@ def test_with_target(self):
         # Try with one error:
         value = frame.EvaluateExpression("my_pointer.first", options)
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEquals(value.GetValueAsUnsigned(), 10)
 
         # Try with one error in a top-level expression.
@@ -58,7 +58,7 @@ def test_with_target(self):
         two_error_expression = "my_pointer.second->a"
         value = frame.EvaluateExpression(two_error_expression, options)
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
         self.assertEquals(value.GetValueAsUnsigned(), 20)
 
         # Try a Fix-It that is stored in the 'note:' diagnostic of an error.
@@ -66,7 +66,7 @@ def test_with_target(self):
         fixit_in_note_expr ="#define ToStr(x) #x\nToStr(0 {, })"
         value = frame.EvaluateExpression(fixit_in_note_expr, options)
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success(), value.GetError())
+        self.assertSuccess(value.GetError())
         self.assertEquals(value.GetSummary(), '"(0 {, })"')
 
         # Now turn off the fixits, and the expression should fail:

diff  --git a/lldb/test/API/commands/expression/options/TestExprOptions.py b/lldb/test/API/commands/expression/options/TestExprOptions.py
index 833833a866f8..1f56e5fb0971 100644
--- a/lldb/test/API/commands/expression/options/TestExprOptions.py
+++ b/lldb/test/API/commands/expression/options/TestExprOptions.py
@@ -46,14 +46,14 @@ def test_expr_options(self):
         # Make sure we can evaluate a C++11 expression.
         val = frame.EvaluateExpression('foo != nullptr')
         self.assertTrue(val.IsValid())
-        self.assertTrue(val.GetError().Success())
+        self.assertSuccess(val.GetError())
         self.DebugSBValue(val)
 
         # Make sure it still works if language is set to C++11:
         options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11)
         val = frame.EvaluateExpression('foo != nullptr', options)
         self.assertTrue(val.IsValid())
-        self.assertTrue(val.GetError().Success())
+        self.assertSuccess(val.GetError())
         self.DebugSBValue(val)
 
         # Make sure it fails if language is set to C:
@@ -80,7 +80,7 @@ def test_expr_options_lang(self):
         options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11)
         val = frame.EvaluateExpression('id == 0', options)
         self.assertTrue(val.IsValid())
-        self.assertTrue(val.GetError().Success())
+        self.assertSuccess(val.GetError())
         self.DebugSBValue(val)
 
         # Make sure we can't retrieve `id` variable if language is set to ObjC:

diff  --git a/lldb/test/API/commands/expression/pr35310/TestExprsBug35310.py b/lldb/test/API/commands/expression/pr35310/TestExprsBug35310.py
index 23dbce9227e7..a9987ce3ed52 100644
--- a/lldb/test/API/commands/expression/pr35310/TestExprsBug35310.py
+++ b/lldb/test/API/commands/expression/pr35310/TestExprsBug35310.py
@@ -23,16 +23,8 @@ def test_issue35310(self):
         """
         self.build()
 
-        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
+        lldbutil.run_to_source_breakpoint(self,
                                           '// Break here', self.main_source_spec)
-        frame = thread.GetFrameAtIndex(0)
 
-        value = frame.EvaluateExpression("a.test_abi_tag()")
-        self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
-        self.assertEqual(value.GetValueAsSigned(0), 1)
-
-        value = frame.EvaluateExpression("a.test_asm_name()")
-        self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
-        self.assertEqual(value.GetValueAsSigned(0), 2)
+        self.expect_expr("a.test_abi_tag()", result_value='1')
+        self.expect_expr("a.test_asm_name()", result_value='2')

diff  --git a/lldb/test/API/commands/expression/result_numbering/TestResultNumbering.py b/lldb/test/API/commands/expression/result_numbering/TestResultNumbering.py
index cd6b9c43775c..11429516d1f1 100644
--- a/lldb/test/API/commands/expression/result_numbering/TestResultNumbering.py
+++ b/lldb/test/API/commands/expression/result_numbering/TestResultNumbering.py
@@ -33,7 +33,7 @@ def do_numbering_test(self):
 
         # Get the number of the last expression:
         result = thread.frames[0].EvaluateExpression("call_me(200)")
-        self.assertTrue(result.GetError().Success(), "Our expression succeeded")
+        self.assertSuccess(result.GetError(), "Our expression succeeded")
         name = result.GetName()
         ordinal = int(name[1:])
         
@@ -42,7 +42,7 @@ def do_numbering_test(self):
         # The condition evaluation had to run a 4 expressions, but we haven't
         # run any user expressions.
         result = thread.frames[0].EvaluateExpression("call_me(200)")
-        self.assertTrue(result.GetError().Success(), "Our expression succeeded the second time")
+        self.assertSuccess(result.GetError(), "Our expression succeeded the second time")
         after_name = result.GetName()
         after_ordinal = int(after_name[1:])
         self.assertEqual(ordinal + 1, after_ordinal) 

diff  --git a/lldb/test/API/commands/expression/scoped_enums/TestScopedEnumType.py b/lldb/test/API/commands/expression/scoped_enums/TestScopedEnumType.py
index dd40e87d68d3..2c45d213e4df 100644
--- a/lldb/test/API/commands/expression/scoped_enums/TestScopedEnumType.py
+++ b/lldb/test/API/commands/expression/scoped_enums/TestScopedEnumType.py
@@ -23,15 +23,8 @@ def test(self):
         self.expect("expr f == Foo::FooBar",
                 substrs=['(bool) $0 = true'])
 
-        value = frame.EvaluateExpression("f == Foo::FooBar")
-        self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
-        self.assertEqual(value.GetValueAsUnsigned(), 1)
-
-        value = frame.EvaluateExpression("b == BarBar")
-        self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
-        self.assertEqual(value.GetValueAsUnsigned(), 1)
+        self.expect_expr("f == Foo::FooBar", result_value='true')
+        self.expect_expr("b == BarBar", result_value='true')
 
         ## b is not a Foo
         value = frame.EvaluateExpression("b == Foo::FooBar")

diff  --git a/lldb/test/API/commands/expression/timeout/TestCallWithTimeout.py b/lldb/test/API/commands/expression/timeout/TestCallWithTimeout.py
index 36ed7ce26de1..733c9921487e 100644
--- a/lldb/test/API/commands/expression/timeout/TestCallWithTimeout.py
+++ b/lldb/test/API/commands/expression/timeout/TestCallWithTimeout.py
@@ -59,7 +59,7 @@ def test(self):
         options.SetTimeoutInMicroSeconds(1000000)
         value = frame.EvaluateExpression("wait_a_while (1000)", options)
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())
 
         # Now do the same thingwith the command line command, and make sure it
         # works too.
@@ -77,4 +77,4 @@ def test(self):
         options.SetOneThreadTimeoutInMicroSeconds(500000)
         value = frame.EvaluateExpression("wait_a_while (1000)", options)
         self.assertTrue(value.IsValid())
-        self.assertTrue(value.GetError().Success())
+        self.assertSuccess(value.GetError())

diff  --git a/lldb/test/API/commands/expression/unwind_expression/TestUnwindExpression.py b/lldb/test/API/commands/expression/unwind_expression/TestUnwindExpression.py
index 3839f7d89235..17424551fd83 100644
--- a/lldb/test/API/commands/expression/unwind_expression/TestUnwindExpression.py
+++ b/lldb/test/API/commands/expression/unwind_expression/TestUnwindExpression.py
@@ -45,9 +45,7 @@ def test_conditional_bktp(self):
 
         main_frame = self.thread.GetFrameAtIndex(0)
         val = main_frame.EvaluateExpression("second_function(47)", options)
-        self.assertTrue(
-            val.GetError().Success(),
-            "We did complete the execution.")
+        self.assertSuccess(val.GetError(), "We did complete the execution.")
         self.assertEquals(47, val.GetValueAsSigned())
 
 
@@ -92,8 +90,8 @@ def do_unwind_test(self, thread, bkpt, timeout):
 
         # Now unwind the expression, and make sure we got back to where we
         # started.
-        error = thread.UnwindInnermostExpression()
-        self.assertTrue(error.Success(), "We succeeded in unwinding")
+        self.assertSuccess(thread.UnwindInnermostExpression(),
+                "We succeeded in unwinding")
 
         cur_frame = thread.GetFrameAtIndex(0)
         self.assertTrue(

diff  --git a/lldb/test/API/commands/expression/weak_symbols/TestWeakSymbols.py b/lldb/test/API/commands/expression/weak_symbols/TestWeakSymbols.py
index b58d838b14b7..b67b5b4efe0b 100644
--- a/lldb/test/API/commands/expression/weak_symbols/TestWeakSymbols.py
+++ b/lldb/test/API/commands/expression/weak_symbols/TestWeakSymbols.py
@@ -39,7 +39,7 @@ def run_weak_var_check (self, weak_varname, present):
         # the bug that expressions with no result currently return False for Success()...
         expr = "if (&" + weak_varname + " != NULL) { present_weak_int = 10; } else { present_weak_int = 20;}; 10"
         result = self.frame.EvaluateExpression(expr)
-        self.assertTrue(result.GetError().Success(), "absent_weak_int expr failed: %s"%(result.GetError().GetCString()))
+        self.assertSuccess(result.GetError(), "absent_weak_int expr failed")
         self.assertEqual(value.GetValueAsSigned(), correct_value, "Didn't change present_weak_int correctly.")
         
     def do_test(self):

diff  --git a/lldb/test/API/commands/register/register/register_command/TestRegisters.py b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
index 01d2367c8550..b0931a7d6977 100644
--- a/lldb/test/API/commands/register/register/register_command/TestRegisters.py
+++ b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
@@ -235,12 +235,12 @@ def fp_special_purpose_register_read(self):
         error = lldb.SBError()
         reg_value_fstat_initial = value.GetValueAsUnsigned(error, 0)
 
-        self.assertTrue(error.Success(), "reading a value for fstat")
+        self.assertSuccess(error, "reading a value for fstat")
         value = currentFrame.FindValue("ftag", lldb.eValueTypeRegister)
         error = lldb.SBError()
         reg_value_ftag_initial = value.GetValueAsUnsigned(error, 0)
 
-        self.assertTrue(error.Success(), "reading a value for ftag")
+        self.assertSuccess(error, "reading a value for ftag")
         fstat_top_pointer_initial = (reg_value_fstat_initial & 0x3800) >> 11
 
         # Execute 'si' aka 'thread step-inst' instruction 5 times and with
@@ -292,7 +292,7 @@ def fp_register_write(self):
                 0, # launch flags
                 True, # stop at entry
                 error)
-        self.assertTrue(error.Success(), "Launch succeeds. Error is :" + str(error))
+        self.assertSuccess(error, "Launch succeeds")
 
         self.assertTrue(
             process.GetState() == lldb.eStateStopped,

diff  --git a/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py b/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
index 874a90853c2a..ae5822750d69 100644
--- a/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
+++ b/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
@@ -57,47 +57,26 @@ def test_target_auto_install_main_executable(self):
 
         new_platform = lldb.SBPlatform(lldb.remote_platform.GetName())
         self.dbg.SetSelectedPlatform(new_platform)
-        interpreter = self.dbg.GetCommandInterpreter()
 
         connect_url = "%s://%s:%s" % (protocol, hostname, str(hostport+1))
 
-        command = "platform connect %s" % (connect_url)
-
-        result = lldb.SBCommandReturnObject()
-
         # Test the default setting.
-        interpreter.HandleCommand("settings show target.auto-install-main-executable", result)
-        self.assertTrue(
-            result.Succeeded() and
-            "target.auto-install-main-executable (boolean) = true" in result.GetOutput(),
-            "Default settings for target.auto-install-main-executable failed.: %s - %s" %
-            (result.GetOutput(), result.GetError()))
+        self.expect("settings show target.auto-install-main-executable",
+                substrs=["target.auto-install-main-executable (boolean) = true"],
+                msg="Default settings for target.auto-install-main-executable failed.")
 
         # Disable the auto install.
-        interpreter.HandleCommand("settings set target.auto-install-main-executable false", result)
-        interpreter.HandleCommand("settings show target.auto-install-main-executable", result)
-        self.assertTrue(
-            result.Succeeded() and
-            "target.auto-install-main-executable (boolean) = false" in result.GetOutput(),
-            "Default settings for target.auto-install-main-executable failed.: %s - %s" %
-            (result.GetOutput(), result.GetError()))
+        self.runCmd("settings set target.auto-install-main-executable false")
+        self.expect("settings show target.auto-install-main-executable", 
+            substrs=["target.auto-install-main-executable (boolean) = false"])
 
-        interpreter.HandleCommand("platform select %s"%configuration.lldb_platform_name, result)
-        interpreter.HandleCommand(command, result)
-
-        self.assertTrue(
-            result.Succeeded(),
-            "platform process connect failed: %s - %s" %
-            (result.GetOutput(),result.GetError()))
+        self.runCmd("platform select %s"%configuration.lldb_platform_name)
+        self.runCmd("platform connect %s" % (connect_url))
 
         # Create the target with the original file.
-        interpreter.HandleCommand("target create --remote-file %s %s "%
-                                        (os.path.join(working_dir,dest.GetFilename()), self.getBuildArtifact("a.out")),
-                                      result)
-        self.assertTrue(
-            result.Succeeded(),
-            "platform create failed: %s - %s" %
-            (result.GetOutput(),result.GetError()))
+        self.runCmd("target create --remote-file %s %s "%
+                                        (os.path.join(working_dir,dest.GetFilename()),
+                                            self.getBuildArtifact("a.out")))
 
         target = new_debugger.GetSelectedTarget()
         breakpoint = target.BreakpointCreateByName("main")
@@ -115,10 +94,7 @@ def test_target_auto_install_main_executable(self):
         frame = thread.GetFrameAtIndex(0)
         self.assertEqual(frame.GetFunction().GetName(), "main")
 
-        interpreter.HandleCommand("target variable build", result)
-        self.assertTrue(
-            result.Succeeded() and
-            '"device"' in result.GetOutput(),
-            "Magic in the binary is wrong: %s " % result.GetOutput())
+        self.expect("target variable build", substrs=['"device"'],
+                msg="Magic in the binary is wrong")
 
         process.Continue()

diff  --git a/lldb/test/API/python_api/hello_world/TestHelloWorld.py b/lldb/test/API/python_api/hello_world/TestHelloWorld.py
index 75a55ab1f44d..c1155cf29814 100644
--- a/lldb/test/API/python_api/hello_world/TestHelloWorld.py
+++ b/lldb/test/API/python_api/hello_world/TestHelloWorld.py
@@ -142,7 +142,8 @@ def test_with_attach_to_process_with_name_api(self):
         target.ConnectRemote(listener, None, None, error)
 
         process = target.AttachToProcessWithName(listener, name, False, error)
-        self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
+        self.assertSuccess(error)
+        self.assertTrue(process, PROCESS_IS_VALID)
 
         # Verify that after attach, our selected target indeed matches name.
         self.expect(


        


More information about the lldb-commits mailing list