39
40
crash_dir = osutils.joinpath((self.test_base_dir, 'crash'))
40
41
os.mkdir(crash_dir)
41
42
self.overrideEnv('APPORT_CRASH_DIR', crash_dir)
42
self.assertEqual(crash_dir, bedding.crash_dir())
43
self.assertEqual(crash_dir, config.crash_dir())
45
breezy.get_global_state(),
47
48
{'example': ['Failed to load plugin foo']})
52
53
raise AssertionError("my error")
53
54
except AssertionError as e:
54
crash_filename = crash.report_bug_to_apport(sys.exc_info(), stderr)
57
crash_filename = crash.report_bug_to_apport(sys.exc_info(),
56
60
# message explaining the crash
57
61
self.assertContainsRe(stderr.getvalue(),
58
" apport-bug %s" % crash_filename)
62
" apport-bug %s" % crash_filename)
60
with open(crash_filename) as crash_file:
64
crash_file = open(crash_filename)
61
66
report = crash_file.read()
63
70
self.assertContainsRe(report,
64
'(?m)^BrzVersion:') # should be in the traceback
71
'(?m)^BzrVersion:') # should be in the traceback
65
72
self.assertContainsRe(report, 'my error')
66
73
self.assertContainsRe(report, 'AssertionError')
67
74
# see https://bugs.launchpad.net/bzr/+bug/528114
77
84
class TestNonApportReporting(tests.TestCase):
78
85
"""Reporting of crash-type bugs without apport.
80
87
This should work in all environments.
83
90
def setup_fake_plugins(self):
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)
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)
89
97
def test_report_bug_legacy(self):
90
98
self.setup_fake_plugins()
93
101
raise AssertionError("my error")
94
102
except AssertionError as e:
95
crash.report_bug_legacy(sys.exc_info(), err_file)
104
crash.report_bug_legacy(sys.exc_info(), err_file)
96
105
report = err_file.getvalue()
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)
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(