~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_crash.py

  • Committer: Robert Collins
  • Date: 2007-04-19 02:27:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2426.
  • Revision ID: robertc@robertcollins.net-20070419022744-pfdqz42kp1wizh43
``make docs`` now creates a man page at ``man1/bzr.1`` fixing bug 107388.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
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
 
 
18
 
from StringIO import StringIO
19
 
import sys
20
 
 
21
 
 
22
 
import os
23
 
 
24
 
 
25
 
from bzrlib import (
26
 
    config,
27
 
    crash,
28
 
    osutils,
29
 
    plugin,
30
 
    tests,
31
 
    )
32
 
 
33
 
from bzrlib.tests import features
34
 
 
35
 
 
36
 
class TestApportReporting(tests.TestCaseInTempDir):
37
 
 
38
 
    _test_needs_features = [features.apport]
39
 
 
40
 
    def test_apport_report(self):
41
 
        crash_dir = osutils.joinpath((self.test_base_dir, 'crash'))
42
 
        os.mkdir(crash_dir)
43
 
        self.overrideEnv('APPORT_CRASH_DIR', crash_dir)
44
 
        self.assertEquals(crash_dir, config.crash_dir())
45
 
 
46
 
        self.overrideAttr(
47
 
            plugin,
48
 
            'plugin_warnings',
49
 
            {'example': ['Failed to load plugin foo']})
50
 
 
51
 
        stderr = StringIO()
52
 
 
53
 
        try:
54
 
            raise AssertionError("my error")
55
 
        except AssertionError, e:
56
 
            pass
57
 
 
58
 
        crash_filename = crash.report_bug_to_apport(sys.exc_info(),
59
 
            stderr)
60
 
 
61
 
        # message explaining the crash
62
 
        self.assertContainsRe(stderr.getvalue(),
63
 
            "    apport-bug %s" % crash_filename)
64
 
 
65
 
        crash_file = open(crash_filename)
66
 
        try:
67
 
            report = crash_file.read()
68
 
        finally:
69
 
            crash_file.close()
70
 
 
71
 
        self.assertContainsRe(report,
72
 
            '(?m)^BzrVersion:') # should be in the traceback
73
 
        self.assertContainsRe(report, 'my error')
74
 
        self.assertContainsRe(report, 'AssertionError')
75
 
        # see https://bugs.launchpad.net/bzr/+bug/528114
76
 
        self.assertContainsRe(report, 'ExecutablePath')
77
 
        self.assertContainsRe(report, 'test_apport_report')
78
 
        # should also be in there
79
 
        self.assertContainsRe(report, '(?m)^CommandLine:')
80
 
        self.assertContainsRe(
81
 
            report,
82
 
            'Failed to load plugin foo')