1
# Copyright (C) 2009, 2010, 2011, 2016 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29
from ..sixish import (
32
from . import features
35
class TestApportReporting(tests.TestCaseInTempDir):
37
_test_needs_features = [features.apport]
39
def test_apport_report(self):
40
crash_dir = osutils.joinpath((self.test_base_dir, 'crash'))
42
self.overrideEnv('APPORT_CRASH_DIR', crash_dir)
43
self.assertEqual(crash_dir, config.crash_dir())
48
{'example': ['Failed to load plugin foo']})
53
raise AssertionError("my error")
54
except AssertionError as e:
57
crash_filename = crash.report_bug_to_apport(sys.exc_info(),
60
# message explaining the crash
61
self.assertContainsRe(stderr.getvalue(),
62
" apport-bug %s" % crash_filename)
64
crash_file = open(crash_filename)
66
report = crash_file.read()
70
self.assertContainsRe(report,
71
'(?m)^BzrVersion:') # should be in the traceback
72
self.assertContainsRe(report, 'my error')
73
self.assertContainsRe(report, 'AssertionError')
74
# see https://bugs.launchpad.net/bzr/+bug/528114
75
self.assertContainsRe(report, 'ExecutablePath')
76
self.assertContainsRe(report, 'test_apport_report')
77
# should also be in there
78
self.assertContainsRe(report, '(?m)^CommandLine:')
79
self.assertContainsRe(
81
'Failed to load plugin foo')
84
class TestNonApportReporting(tests.TestCase):
85
"""Reporting of crash-type bugs without apport.
87
This should work in all environments.
90
def setup_fake_plugins(self):
92
fake = plugin.PlugIn('fake_plugin', plugin)
93
fake.version_info = lambda: (1, 2, 3)
94
return {"fake_plugin": fake}
95
self.overrideAttr(plugin, 'plugins', fake_plugins)
97
def test_report_bug_legacy(self):
98
self.setup_fake_plugins()
101
raise AssertionError("my error")
102
except AssertionError as e:
104
crash.report_bug_legacy(sys.exc_info(), err_file)
105
report = err_file.getvalue()
107
"brz: ERROR: exceptions.AssertionError: my error",
108
r"Traceback \(most recent call last\):",
109
r"plugins: fake_plugin\[1\.2\.3\]",
111
self.assertContainsRe(