Files
clang-p2996/lldb/test/API/python_api/sbvalue_persist/TestSBValuePersist.py
Raphael Isemann b3a0c4d7dc [lldb] Replace assertTrue(a == b, "msg") with assertEquals(a, b, "msg") in the test suite
Summary:
The error message from the construct `assertTrue(a == b, "msg") ` are nearly always completely useless for actually debugging the issue.
This patch is just replacing this construct (and similar ones like `assertTrue(a != b, ...)` with the proper call to assertEqual or assertNotEquals.

This patch was mostly written by a shell script with some manual verification afterwards:
```
lang=python
import sys

def sanitize_line(line):
  if line.strip().startswith("self.assertTrue(") and " == " in line:
    line = line.replace("self.assertTrue(", "self.assertEquals(")
    line = line.replace(" == ", ", ", 1)
  if line.strip().startswith("self.assertTrue(") and " != " in line:
    line = line.replace("self.assertTrue(", "self.assertNotEqual(")
    line = line.replace(" != ", ", ", 1)
  return line

for a in sys.argv[1:]:
  with open(a, "r") as f:
    lines = f.readlines()
  with open(a, "w") as f:
    for line in lines:
      f.write(sanitize_line(line))
```

Reviewers: labath, JDevlieghere

Reviewed By: labath

Subscribers: abidh, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D74475
2020-02-13 15:00:55 +01:00

83 lines
2.9 KiB
Python

"""Test SBValue::Persist"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class SBValuePersistTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True
@add_test_categories(['pyapi'])
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24772")
def test(self):
"""Test SBValue::Persist"""
self.build()
self.setTearDownCleanup()
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
lldbutil.run_break_set_by_source_regexp(self, "break here")
self.runCmd("run", RUN_SUCCEEDED)
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])
# This is the function to remove the custom formats in order to have a
# clean slate for the next test case.
def cleanup():
self.runCmd('type format clear', check=False)
self.runCmd('type summary clear', check=False)
self.runCmd('type filter clear', check=False)
self.runCmd('type synthetic clear', check=False)
# Execute the cleanup function during test case tear down.
self.addTearDownHook(cleanup)
foo = self.frame().FindVariable("foo")
bar = self.frame().FindVariable("bar")
baz = self.frame().FindVariable("baz")
self.assertTrue(foo.IsValid(), "foo is not valid")
self.assertTrue(bar.IsValid(), "bar is not valid")
self.assertTrue(baz.IsValid(), "baz is not valid")
fooPersist = foo.Persist()
barPersist = bar.Persist()
bazPersist = baz.Persist()
self.assertTrue(fooPersist.IsValid(), "fooPersist is not valid")
self.assertTrue(barPersist.IsValid(), "barPersist is not valid")
self.assertTrue(bazPersist.IsValid(), "bazPersist is not valid")
self.assertTrue(
fooPersist.GetValueAsUnsigned(0) == 10,
"fooPersist != 10")
self.assertTrue(
barPersist.GetPointeeData().sint32[0] == 4,
"barPersist != 4")
self.assertEquals(bazPersist.GetSummary(), '"85"', "bazPersist != 85")
self.runCmd("continue")
self.assertTrue(fooPersist.IsValid(), "fooPersist is not valid")
self.assertTrue(barPersist.IsValid(), "barPersist is not valid")
self.assertTrue(bazPersist.IsValid(), "bazPersist is not valid")
self.assertTrue(
fooPersist.GetValueAsUnsigned(0) == 10,
"fooPersist != 10")
self.assertTrue(
barPersist.GetPointeeData().sint32[0] == 4,
"barPersist != 4")
self.assertEquals(bazPersist.GetSummary(), '"85"', "bazPersist != 85")
self.expect("expr *(%s)" % (barPersist.GetName()), substrs=['= 4'])