1
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
1
# Copyright (C) 2009, 2010, 2011, 2016 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
39
39
crash_dir = osutils.joinpath((self.test_base_dir, 'crash'))
40
40
os.mkdir(crash_dir)
41
41
self.overrideEnv('APPORT_CRASH_DIR', crash_dir)
42
self.assertEquals(crash_dir, config.crash_dir())
42
self.assertEqual(crash_dir, bedding.crash_dir())
45
breezy.get_global_state(),
47
47
{'example': ['Failed to load plugin foo']})
52
52
raise AssertionError("my error")
53
except AssertionError, e:
56
crash_filename = crash.report_bug_to_apport(sys.exc_info(),
53
except AssertionError as e:
54
crash_filename = crash.report_bug_to_apport(sys.exc_info(), stderr)
59
56
# message explaining the crash
60
57
self.assertContainsRe(stderr.getvalue(),
61
" apport-bug %s" % crash_filename)
58
" apport-bug %s" % crash_filename)
63
crash_file = open(crash_filename)
60
with open(crash_filename) as crash_file:
65
61
report = crash_file.read()
69
63
self.assertContainsRe(report,
70
'(?m)^BzrVersion:') # should be in the traceback
64
'(?m)^BrzVersion:') # should be in the traceback
71
65
self.assertContainsRe(report, 'my error')
72
66
self.assertContainsRe(report, 'AssertionError')
73
67
# see https://bugs.launchpad.net/bzr/+bug/528114
83
77
class TestNonApportReporting(tests.TestCase):
84
78
"""Reporting of crash-type bugs without apport.
86
80
This should work in all environments.
89
83
def setup_fake_plugins(self):
91
fake = plugin.PlugIn('fake_plugin', plugin)
92
fake.version_info = lambda: (1, 2, 3)
93
return {"fake_plugin": fake}
94
self.overrideAttr(plugin, 'plugins', fake_plugins)
84
fake = plugin.PlugIn('fake_plugin', plugin)
85
fake.version_info = lambda: (1, 2, 3)
86
fake_plugins = {"fake_plugin": fake}
87
self.overrideAttr(breezy.get_global_state(), 'plugins', fake_plugins)
96
89
def test_report_bug_legacy(self):
97
90
self.setup_fake_plugins()
98
91
err_file = StringIO()
100
93
raise AssertionError("my error")
101
except AssertionError, e:
103
crash.report_bug_legacy(sys.exc_info(), err_file)
94
except AssertionError as e:
95
crash.report_bug_legacy(sys.exc_info(), err_file)
104
96
report = err_file.getvalue()
106
"bzr: ERROR: exceptions.AssertionError: my error",
107
r"Traceback \(most recent call last\):",
108
r"plugins: fake_plugin\[1\.2\.3\]",
110
self.assertContainsRe(
98
"brz: ERROR: AssertionError: my error",
99
r"Traceback \(most recent call last\):",
100
r"plugins: fake_plugin\[1\.2\.3\]",
102
self.assertContainsRe(report, needle)