From bb12aba0beb09ecc262a8e61a7b49b5aef1049b9 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 25 Feb 2010 19:43:16 -0500 Subject: Add test for the gdb representation of old-style classes --- test_gdb.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'test_gdb.py') diff --git a/test_gdb.py b/test_gdb.py index 127f19a..bf57a13 100644 --- a/test_gdb.py +++ b/test_gdb.py @@ -75,7 +75,7 @@ class DebuggerTests(unittest.TestCase): sys.executable, "-S", "-c", source) return gdb_output - def get_gdb_repr(self, in_repr): + def get_gdb_repr(self, source): # Given an input python source representation of data, # run "python -c'print DATA'" under gdb with a breakpoint on # PyObject_Print and scrape out gdb's representation of the "op" @@ -83,7 +83,7 @@ class DebuggerTests(unittest.TestCase): # # For a nested structure, the first time we hit the breakpoint will # give us the top-level structure - gdb_output = self.get_stack_trace('print ' + in_repr) + gdb_output = self.get_stack_trace(source) m = re.match('.*Breakpoint 1, PyObject_Print \(op\=(.*?), fp=.*\).*', gdb_output, re.DOTALL) # print m.groups() return m.group(1), gdb_output @@ -95,7 +95,7 @@ class DebuggerTests(unittest.TestCase): def assertGdbRepr(self, val): # Ensure that gdb's rendering of the value in a debugged process # matches repr(value) in this process: - gdb_repr, gdb_output = self.get_gdb_repr(repr(val)) + gdb_repr, gdb_output = self.get_gdb_repr('print ' + repr(val)) self.assertEquals(gdb_repr, repr(val), gdb_output) def test_int(self): @@ -136,13 +136,24 @@ class DebuggerTests(unittest.TestCase): self.assertGdbRepr( u'hello world', ) self.assertGdbRepr( u'\u2620') + def test_classic_class(self): + gdb_repr, gdb_output = self.get_gdb_repr(''' +class Foo: + pass +foo = Foo(); +foo.an_int = 42; +print foo''') + # FIXME: is there an "assertMatches"; should there be? + m = re.match(r'', gdb_repr) + self.assertTrue(m, msg='Unexpected classic-class rendering %r' % gdb_repr) + # TODO: - # old-style classes # new-style classes # frames def test_main(): - run_unittest(DebuggerTests) + #run_unittest(DebuggerTests) + unittest.main() if __name__ == "__main__": -- cgit