1
# Copyright (C) 2006 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Tests for display of exceptions."""
22
from bzrlib import bzrdir, repository, trace
23
from bzrlib.tests import TestCaseInTempDir, TestCase, TestSkipped
24
from bzrlib.errors import NotBranchError
27
class TestExceptionReporting(TestCase):
29
def test_report_exception(self):
30
"""When an error occurs, display bug report details to stderr"""
31
old_use_apport = trace._use_apport
32
trace._use_apport = False
36
r'bzr: ERROR: exceptions\.AssertionError: always fails\n',
37
r'please send this report to',
41
trace._use_apport = old_use_apport
43
def test_apport_report(self):
44
# If apport is present, bzr should tell the user the url to visit to
45
# file the bug, and the file to upload as an attachment containing the
46
# backtrace, installed versions, plugin information etc.
47
# the file contents are tested in the library tests, this test just
52
raise TestSkipped('apport not present')
53
out, err = self.run_bzr_error(
55
r'bzr: ERROR: exceptions\.AssertionError: always fails\n',
56
r'This is an unexpected error within bzr and we would appreciate a bug report.\n',
57
r'bzr has written a crash report file that will assist our debugging of this\n',
58
r'in the file /tmp/bzr-crash-[a-zA-Z0-9_]+\.txt\n',
59
r'This is a plain text file, whose contents you can check if you have privacy\n',
60
r'concerns. We gather the package data about bzr, your command line, plugins\n',
61
r'And the backtrace from within bzr. If you had a password in the URL you\n',
62
r'provided to bzr, you should edit that file to remove the password.\n',
63
r'\*\* To file a bug for this please visit our bugtracker at the URL \n',
64
r'"https://launchpad.net/products/bzr/\+filebug" and report a bug describing\n',
65
r'what you were attempting and attach the bzr-crash file mentioned above.\n',
66
r'Alternatively you can email bazaar-ng@lists.canonical.com with the same\n',
67
r'description and attach the bzr-crash file to the email\.\n',
70
self.assertEqualDiff('', out)
73
# TODO: assert-fail doesn't need to always be present; we could just
74
# register (and unregister) it from tests that want to touch it.
76
# TODO: Some kind of test for the feature of invoking pdb
79
class TestDeprecationWarning(TestCaseInTempDir):
81
def test_repository_deprecation_warning(self):
82
"""Old formats give a warning"""
83
# the warning's normally off for testing but we reenable it
84
repository._deprecation_warning_done = False
87
bzrdir.BzrDirFormat5().initialize('foo')
88
out, err = self.run_bzr("status", "foo")
89
self.assertContainsRe(self._get_log(keep_log_file=True),
92
repository._deprecation_warning_done = True