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