5557.1.7
by John Arbash Meinel
Merge in the bzr.dev 5582 |
1 |
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
|
4584.3.21
by Martin Pool
Start adding tests for apport |
2 |
#
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
17 |
||
5609.23.6
by Martin Pool
Show concise list of plugins in non-apport crash; add test for this |
18 |
import doctest |
19 |
import os |
|
4584.3.21
by Martin Pool
Start adding tests for apport |
20 |
from StringIO import StringIO |
21 |
import sys |
|
22 |
||
4634.128.18
by Martin Pool
Update apport crash tests |
23 |
from bzrlib import ( |
24 |
config, |
|
25 |
crash, |
|
5003.2.1
by Vincent Ladeuil
Avoid infinite recursion when probing for apport. |
26 |
osutils, |
5616.7.2
by Martin Pool
Include plugin warnings in apport crash |
27 |
plugin, |
4660.1.1
by Vincent Ladeuil
Let user decide what command is used to run the test suite. |
28 |
tests, |
5003.2.1
by Vincent Ladeuil
Avoid infinite recursion when probing for apport. |
29 |
)
|
30 |
||
31 |
from bzrlib.tests import features |
|
32 |
||
33 |
||
34 |
class TestApportReporting(tests.TestCaseInTempDir): |
|
35 |
||
36 |
_test_needs_features = [features.apport] |
|
4584.3.21
by Martin Pool
Start adding tests for apport |
37 |
|
4634.128.18
by Martin Pool
Update apport crash tests |
38 |
def test_apport_report(self): |
39 |
crash_dir = osutils.joinpath((self.test_base_dir, 'crash')) |
|
40 |
os.mkdir(crash_dir) |
|
5570.3.9
by Vincent Ladeuil
More use cases for overrideEnv, _cleanEnvironment *may* contain too much variables now. |
41 |
self.overrideEnv('APPORT_CRASH_DIR', crash_dir) |
4634.128.18
by Martin Pool
Update apport crash tests |
42 |
self.assertEquals(crash_dir, config.crash_dir()) |
5003.2.1
by Vincent Ladeuil
Avoid infinite recursion when probing for apport. |
43 |
|
5616.7.2
by Martin Pool
Include plugin warnings in apport crash |
44 |
self.overrideAttr( |
45 |
plugin, |
|
46 |
'plugin_warnings', |
|
47 |
{'example': ['Failed to load plugin foo']}) |
|
48 |
||
4634.128.18
by Martin Pool
Update apport crash tests |
49 |
stderr = StringIO() |
50 |
||
4584.3.21
by Martin Pool
Start adding tests for apport |
51 |
try: |
52 |
raise AssertionError("my error") |
|
53 |
except AssertionError, e: |
|
54 |
pass
|
|
4634.128.18
by Martin Pool
Update apport crash tests |
55 |
|
56 |
crash_filename = crash.report_bug_to_apport(sys.exc_info(), |
|
57 |
stderr) |
|
58 |
||
59 |
# message explaining the crash
|
|
60 |
self.assertContainsRe(stderr.getvalue(), |
|
61 |
" apport-bug %s" % crash_filename) |
|
62 |
||
63 |
crash_file = open(crash_filename) |
|
64 |
try: |
|
65 |
report = crash_file.read() |
|
66 |
finally: |
|
67 |
crash_file.close() |
|
68 |
||
69 |
self.assertContainsRe(report, |
|
70 |
'(?m)^BzrVersion:') # should be in the traceback |
|
71 |
self.assertContainsRe(report, 'my error') |
|
72 |
self.assertContainsRe(report, 'AssertionError') |
|
4797.33.9
by Martin Pool
Call apport add_proc_info to make sure necessary fields are present |
73 |
# see https://bugs.launchpad.net/bzr/+bug/528114
|
74 |
self.assertContainsRe(report, 'ExecutablePath') |
|
4634.128.18
by Martin Pool
Update apport crash tests |
75 |
self.assertContainsRe(report, 'test_apport_report') |
4584.3.22
by Martin Pool
further tweaks to and tests of bzr apport reporting |
76 |
# should also be in there
|
4660.1.2
by Vincent Ladeuil
Review feedback, fix typo and more cleanups. |
77 |
self.assertContainsRe(report, '(?m)^CommandLine:') |
5616.7.3
by Martin Pool
Put plugin warnings into both the apport and plain crash report |
78 |
self.assertContainsRe( |
79 |
report, |
|
80 |
'Failed to load plugin foo') |
|
5609.23.6
by Martin Pool
Show concise list of plugins in non-apport crash; add test for this |
81 |
|
82 |
||
83 |
class TestNonApportReporting(tests.TestCase): |
|
84 |
"""Reporting of crash-type bugs without apport.
|
|
85 |
|
|
86 |
This should work in all environments.
|
|
87 |
"""
|
|
88 |
||
89 |
def setup_fake_plugins(self): |
|
90 |
def 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) |
|
95 |
||
96 |
def test_report_bug_legacy(self): |
|
97 |
self.setup_fake_plugins() |
|
98 |
err_file = StringIO() |
|
99 |
try: |
|
100 |
raise AssertionError("my error") |
|
101 |
except AssertionError, e: |
|
102 |
pass
|
|
103 |
crash.report_bug_legacy(sys.exc_info(), err_file) |
|
5784.2.1
by Martin Pool
Rewrite test_report_bug_legacy away from using doctest (see bug 764188) |
104 |
report = err_file.getvalue() |
105 |
for needle in [ |
|
106 |
"bzr: ERROR: exceptions.AssertionError: my error", |
|
107 |
r"Traceback \(most recent call last\):", |
|
108 |
r"plugins: fake_plugin\[1\.2\.3\]", |
|
109 |
]:
|
|
110 |
self.assertContainsRe( |
|
111 |
report, |
|
112 |
needle) |