~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_logformats.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2009 Canonical Ltd
2
2
#
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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
16
18
"""Black-box tests for default log_formats/log_formatters
17
19
"""
18
20
 
 
21
 
19
22
import os
20
23
 
 
24
 
21
25
from bzrlib.branch import Branch
22
26
from bzrlib.tests import TestCaseInTempDir
23
27
from bzrlib.config import (ensure_config_dir_exists, config_filename)
25
29
 
26
30
class TestLogFormats(TestCaseInTempDir):
27
31
 
28
 
    def bzr(self, *args, **kwargs):
29
 
        return self.run_bzr(*args, **kwargs)[0]
30
 
 
31
32
    def test_log_default_format(self):
32
33
        self.setup_config()
33
34
 
34
 
        self.bzr('init')
 
35
        self.run_bzr('init')
35
36
        open('a', 'wb').write('foo\n')
36
 
        self.bzr('add a')
 
37
        self.run_bzr('add a')
37
38
 
38
 
        self.bzr('commit -m 1')
 
39
        self.run_bzr('commit -m 1')
39
40
        open('a', 'wb').write('baz\n')
40
41
 
41
 
        self.bzr('commit -m 2')
 
42
        self.run_bzr('commit -m 2')
42
43
 
43
44
        # only the lines formatter is this short
44
 
        self.assertEquals(3, len(self.bzr('log').split('\n')))
 
45
        self.assertEquals(3, len(self.run_bzr('log')[0].split('\n')))
45
46
 
46
47
    def test_log_format_arg(self):
47
 
        self.bzr('init')
 
48
        self.run_bzr('init')
48
49
        open('a', 'wb').write('foo\n')
49
 
        self.bzr('add a')
 
50
        self.run_bzr('add a')
50
51
 
51
 
        self.bzr('commit -m 1')
 
52
        self.run_bzr('commit -m 1')
52
53
        open('a', 'wb').write('baz\n')
53
54
 
54
 
        self.bzr('commit -m 2')
 
55
        self.run_bzr('commit -m 2')
55
56
 
56
57
        # only the lines formatter is this short
57
 
        self.assertEquals(7, len(self.bzr('log --log-format short').split('\n')))
 
58
        self.assertEquals(7,
 
59
            len(self.run_bzr('log --log-format short')[0].split('\n')))
58
60
 
59
61
    def test_missing_default_format(self):
60
62
        self.setup_config()
61
63
 
62
64
        os.mkdir('a')
63
65
        os.chdir('a')
64
 
        self.bzr('init')
 
66
        self.run_bzr('init')
65
67
 
66
68
        open('a', 'wb').write('foo\n')
67
 
        self.bzr('add a')
68
 
        self.bzr('commit -m 1')
 
69
        self.run_bzr('add a')
 
70
        self.run_bzr('commit -m 1')
69
71
 
70
72
        os.chdir('..')
71
 
        self.bzr('branch a b')
 
73
        self.run_bzr('branch a b')
72
74
        os.chdir('a')
73
75
 
74
76
        open('a', 'wb').write('bar\n')
75
 
        self.bzr('commit -m 2')
 
77
        self.run_bzr('commit -m 2')
76
78
 
77
79
        open('a', 'wb').write('baz\n')
78
 
        self.bzr('commit -m 3')
 
80
        self.run_bzr('commit -m 3')
79
81
 
80
82
        os.chdir('../b')
81
83
 
82
 
        self.assertEquals(5, len(self.bzr('missing', retcode=1).split('\n')))
 
84
        self.assertEquals(5,
 
85
            len(self.run_bzr('missing', retcode=1)[0].split('\n')))
83
86
 
84
87
        os.chdir('..')
85
88
 
88
91
 
89
92
        os.mkdir('a')
90
93
        os.chdir('a')
91
 
        self.bzr('init')
 
94
        self.run_bzr('init')
92
95
 
93
96
        open('a', 'wb').write('foo\n')
94
 
        self.bzr('add a')
95
 
        self.bzr('commit -m 1')
 
97
        self.run_bzr('add a')
 
98
        self.run_bzr('commit -m 1')
96
99
 
97
100
        os.chdir('..')
98
 
        self.bzr('branch a b')
 
101
        self.run_bzr('branch a b')
99
102
        os.chdir('a')
100
103
 
101
104
        open('a', 'wb').write('bar\n')
102
 
        self.bzr('commit -m 2')
 
105
        self.run_bzr('commit -m 2')
103
106
 
104
107
        open('a', 'wb').write('baz\n')
105
 
        self.bzr('commit -m 3')
 
108
        self.run_bzr('commit -m 3')
106
109
 
107
110
        os.chdir('../b')
108
111
 
109
 
        self.assertEquals(9, len(self.bzr('missing --log-format short',
110
 
                                          retcode=1).split('\n')))
 
112
        self.assertEquals(9,
 
113
            len(self.run_bzr('missing --log-format short',
 
114
                retcode=1)[0].split('\n')))
111
115
 
112
116
        os.chdir('..')
113
117
 
 
118
    def test_logformat_gnu_changelog(self):
 
119
        # from http://launchpad.net/bugs/29582/
 
120
        self.setup_config()
 
121
        repo_url = self.make_trivial_history()
 
122
 
 
123
        out, err = self.run_bzr(
 
124
            ['log', self.get_url('repo/a'),
 
125
             '--log-format=gnu-changelog',
 
126
             '--timezone=utc'])
 
127
        self.assertEquals(err, '')
 
128
        self.assertEqualDiff(out,
 
129
"""2009-03-03  Joe Foo  <joe@foo.com>
 
130
 
 
131
\tcommit 1
 
132
 
 
133
""")
 
134
 
 
135
    def make_trivial_history(self):
 
136
        """Make a one-commit history and return the URL of the branch"""
 
137
        repo = self.make_repository('repo', shared=True, format='1.6')
 
138
        bb = self.make_branch_builder('repo/a')
 
139
        bb.start_series()
 
140
        bb.build_snapshot('rev-1', None,
 
141
            [('add', ('', 'root-id', 'directory', ''))],
 
142
            timestamp=1236045060)
 
143
        bb.finish_series()
 
144
        return self.get_url('repo/a')
114
145
 
115
146
    def setup_config(self):
116
147
        if os.path.isfile(config_filename()):
117
 
                # Something is wrong in environment, 
118
 
                # we risk overwriting users config 
 
148
                # Something is wrong in environment,
 
149
                # we risk overwriting users config
119
150
                self.assert_(config_filename() + "exists, abort")
120
 
            
 
151
 
121
152
        ensure_config_dir_exists()
122
153
        CONFIG=("[DEFAULT]\n"
123
154
                "email=Joe Foo <joe@foo.com>\n"