Index: Lib/test/test_gdb.py =================================================================== --- Lib/test/test_gdb.py (revision 79554) +++ Lib/test/test_gdb.py (working copy) @@ -9,7 +9,7 @@ import sys import unittest -from test.test_support import run_unittest +from test.test_support import run_unittest, findfile try: gdb_version, _ = subprocess.Popen(["gdb", "--version"], @@ -125,9 +125,13 @@ gdb_output = self.get_stack_trace(source, breakpoint='PyObject_Print', cmds_after_breakpoint=cmds_after_breakpoint, import_site=import_site) - m = re.match('.*#0 PyObject_Print \(op\=(.*?), fp=.*\).*', + # gdb can insert additional '\n' and space characters after the "=" + # sign, and before the "fp=", depending on the width of the terminal + # it's connected to + m = re.match('.*#0 PyObject_Print \(op\=\s*(.*?),\s+fp=.*\).*', gdb_output, re.DOTALL) #print m.groups() + self.assert_(m, msg='Unexpected gdb output: %r\n%s' % (gdb_output, gdb_output)) return m.group(1), gdb_output def assertEndsWith(self, actual, exp_end): @@ -140,6 +144,9 @@ self.assert_(m, msg='%r did not match %r' % (actual, pattern)) + def get_sample_script(self): + return findfile('test_gdb_sample.py') + class PrettyPrintTests(DebuggerTests): def test_getting_backtrace(self): gdb_output = self.get_stack_trace('print 42') @@ -453,7 +460,7 @@ 'Verify that very long output is truncated' gdb_repr, gdb_output = self.get_gdb_repr('print range(1000)') self.assertEquals(gdb_repr, - "\n [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, " + "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, " "14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, " "27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, " "40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, " @@ -475,7 +482,7 @@ "214, 215, 216, 217, 218, 219, 220, 221, 222, 223, " "224, 225, 226...(truncated)") self.assertEquals(len(gdb_repr), - len('\n ') + 1024 + len('...(truncated)')) + 1024 + len('...(truncated)')) def test_builtin_function(self): gdb_repr, gdb_output = self.get_gdb_repr('print len') @@ -514,144 +521,138 @@ def test_basic_command(self): 'Verify that the "py-list" command works' - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-list']) - self.assertListing(''' - 5 - 6 def bar(a, b, c): - 7 baz(a, b, c) - 8 - 9 def baz(*args): - >10 print(42) - 11 - 12 foo(1, 2, 3) -''', - bt) + self.assertListing(' 5 \n' + ' 6 def bar(a, b, c):\n' + ' 7 baz(a, b, c)\n' + ' 8 \n' + ' 9 def baz(*args):\n' + ' >10 print(42)\n' + ' 11 \n' + ' 12 foo(1, 2, 3)\n', + bt) def test_one_abs_arg(self): 'Verify the "py-list" command with one absolute argument' - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-list 9']) - self.assertListing(''' - 9 def baz(*args): - >10 print(42) - 11 - 12 foo(1, 2, 3) -''', - bt) + self.assertListing(' 9 def baz(*args):\n' + ' >10 print(42)\n' + ' 11 \n' + ' 12 foo(1, 2, 3)\n', + bt) def test_two_abs_args(self): 'Verify the "py-list" command with two absolute arguments' - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-list 1,3']) - self.assertListing(''' - 1 # Sample script for use by test_gdb.py - 2 - 3 def foo(a, b, c): -''', - bt) + self.assertListing(' 1 # Sample script for use by test_gdb.py\n' + ' 2 \n' + ' 3 def foo(a, b, c):\n', + bt) class StackNavigationTests(DebuggerTests): def test_pyup_command(self): 'Verify that the "py-up" command works' - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-up']) self.assertMultilineMatches(bt, r'''^.* -#[0-9]+ Frame 0x[0-9a-f]+, for file Lib/test/test_gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\) +#[0-9]+ Frame 0x[0-9a-f]+, for file .*test_gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\) baz\(a, b, c\) $''') def test_down_at_bottom(self): 'Verify handling of "py-down" at the bottom of the stack' - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-down']) self.assertEndsWith(bt, 'Unable to find a newer python frame\n') def test_up_at_top(self): 'Verify handling of "py-up" at the top of the stack' - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-up'] * 4) self.assertEndsWith(bt, 'Unable to find an older python frame\n') def test_up_then_down(self): 'Verify "py-up" followed by "py-down"' - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-up', 'py-down']) self.assertMultilineMatches(bt, r'''^.* -#[0-9]+ Frame 0x[0-9a-f]+, for file Lib/test/test_gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\) +#[0-9]+ Frame 0x[0-9a-f]+, for file .*test_gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\) baz\(a, b, c\) -#[0-9]+ Frame 0x[0-9a-f]+, for file Lib/test/test_gdb_sample.py, line 10, in baz \(args=\(1, 2, 3\)\) +#[0-9]+ Frame 0x[0-9a-f]+, for file .*test_gdb_sample.py, line 10, in baz \(args=\(1, 2, 3\)\) print\(42\) $''') class PyBtTests(DebuggerTests): def test_basic_command(self): 'Verify that the "py-bt" command works' - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-bt']) self.assertMultilineMatches(bt, r'''^.* -#[0-9]+ Frame 0x[0-9a-f]+, for file Lib/test/test_gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\) +#[0-9]+ Frame 0x[0-9a-f]+, for file .*test_gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\) baz\(a, b, c\) -#[0-9]+ Frame 0x[0-9a-f]+, for file Lib/test/test_gdb_sample.py, line 4, in foo \(a=1, b=2, c=3\) +#[0-9]+ Frame 0x[0-9a-f]+, for file .*test_gdb_sample.py, line 4, in foo \(a=1, b=2, c=3\) bar\(a, b, c\) -#[0-9]+ Frame 0x[0-9a-f]+, for file Lib/test/test_gdb_sample.py, line 12, in \(\) +#[0-9]+ Frame 0x[0-9a-f]+, for file .*test_gdb_sample.py, line 12, in \(\) foo\(1, 2, 3\) ''') class PyPrintTests(DebuggerTests): def test_basic_command(self): 'Verify that the "py-print" command works' - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-print args']) self.assertMultilineMatches(bt, r".*\nlocal 'args' = \(1, 2, 3\)\n.*") def test_print_after_up(self): - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-up', 'py-print c', 'py-print b', 'py-print a']) self.assertMultilineMatches(bt, r".*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*") def test_printing_global(self): - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-print __name__']) self.assertMultilineMatches(bt, r".*\nglobal '__name__' = '__main__'\n.*") def test_printing_builtin(self): - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-print len']) self.assertMultilineMatches(bt, r".*\nbuiltin 'len' = \n.*") class PyLocalsTests(DebuggerTests): def test_basic_command(self): - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-locals']) self.assertMultilineMatches(bt, r".*\nargs = \(1, 2, 3\)\n.*") def test_locals_after_up(self): - bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', + bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-up', 'py-locals']) self.assertMultilineMatches(bt, r".*\na = 1\nb = 2\nc = 3\n.*") def test_main(): run_unittest(PrettyPrintTests, - #PyListTests, - #StackNavigationTests, - #PyBtTests, - #PyPrintTests, - #PyLocalsTests + PyListTests, + StackNavigationTests, + PyBtTests, + PyPrintTests, + PyLocalsTests ) if __name__ == "__main__":