/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
1
# Copyright (C) 2005 by 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
import os
1123 by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest
18
from cStringIO import StringIO
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
19
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
20
from bzrlib.tests import BzrTestBase, TestCaseWithTransport
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
21
from bzrlib.log import LogFormatter, show_log, LongLogFormatter, ShortLogFormatter
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
22
from bzrlib.branch import Branch
974.1.54 by aaron.bentley at utoronto
Fixed the revno bug in log
23
from bzrlib.errors import InvalidRevisionNumber
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
24
25
class _LogEntry(object):
26
    # should probably move into bzrlib.log?
27
    pass
28
29
30
class LogCatcher(LogFormatter):
31
    """Pull log messages into list rather than displaying them.
32
33
    For ease of testing we save log messages here rather than actually
34
    formatting them, so that we can precisely check the result without
35
    being too dependent on the exact formatting.
36
37
    We should also test the LogFormatter.
38
    """
39
    def __init__(self):
40
        super(LogCatcher, self).__init__(to_file=None)
41
        self.logs = []
42
        
43
        
44
    def show(self, revno, rev, delta):
45
        le = _LogEntry()
46
        le.revno = revno
47
        le.rev = rev
48
        le.delta = delta
49
        self.logs.append(le)
50
51
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
52
class SimpleLogTest(TestCaseWithTransport):
1102 by Martin Pool
- merge test refactoring from robertc
53
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
54
    def checkDelta(self, delta, **kw):
55
        """Check the filenames touched by a delta are as expected."""
56
        for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
57
            expected = kw.get(n, [])
58
59
            # tests are written with unix paths; fix them up for windows
1185.31.34 by John Arbash Meinel
Removing instances of os.sep
60
            #if os.sep != '/':
61
            #    expected = [x.replace('/', os.sep) for x in expected]
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
62
63
            # strip out only the path components
64
            got = [x[0] for x in getattr(delta, n)]
65
            self.assertEquals(expected, got)
66
974.1.54 by aaron.bentley at utoronto
Fixed the revno bug in log
67
    def test_cur_revno(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
68
        wt = self.make_branch_and_tree('.')
69
        b = wt.branch
1092.3.4 by Robert Collins
update symlink branch to integration
70
71
        lf = LogCatcher()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
72
        wt.commit('empty commit')
1092.3.4 by Robert Collins
update symlink branch to integration
73
        show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
74
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
75
                          start_revision=2, end_revision=1) 
76
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
77
                          start_revision=1, end_revision=2) 
78
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
79
                          start_revision=0, end_revision=2) 
80
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
81
                          start_revision=1, end_revision=0) 
82
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
83
                          start_revision=-1, end_revision=1) 
84
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
85
                          start_revision=1, end_revision=-1) 
86
87
    def test_cur_revno(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
88
        wt = self.make_branch_and_tree('.')
89
        b = wt.branch
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
90
91
        lf = LogCatcher()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
92
        wt.commit('empty commit')
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
93
        show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
94
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
95
                          start_revision=2, end_revision=1) 
96
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
97
                          start_revision=1, end_revision=2) 
98
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
99
                          start_revision=0, end_revision=2) 
100
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
101
                          start_revision=1, end_revision=0) 
102
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
103
                          start_revision=-1, end_revision=1) 
104
        self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
105
                          start_revision=1, end_revision=-1) 
106
1102 by Martin Pool
- merge test refactoring from robertc
107
    def test_simple_log(self):
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
108
        eq = self.assertEquals
109
        
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
110
        wt = self.make_branch_and_tree('.')
111
        b = wt.branch
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
112
113
        lf = LogCatcher()
114
        show_log(b, lf)
115
        # no entries yet
116
        eq(lf.logs, [])
117
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
118
        b.working_tree().commit('empty commit')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
119
        lf = LogCatcher()
120
        show_log(b, lf, verbose=True)
121
        eq(len(lf.logs), 1)
122
        eq(lf.logs[0].revno, 1)
123
        eq(lf.logs[0].rev.message, 'empty commit')
124
        d = lf.logs[0].delta
125
        self.log('log delta: %r' % d)
126
        self.checkDelta(d)
127
128
        self.build_tree(['hello'])
1508.1.5 by Robert Collins
Move add from Branch to WorkingTree.
129
        b.working_tree().add('hello')
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
130
        b.working_tree().commit('add one file')
1123 by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest
131
132
        lf = StringIO()
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
133
        # log using regular thing
1123 by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest
134
        show_log(b, LongLogFormatter(lf))
135
        lf.seek(0)
136
        for l in lf.readlines():
137
            self.log(l)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
138
139
        # get log as data structure
140
        lf = LogCatcher()
141
        show_log(b, lf, verbose=True)
142
        eq(len(lf.logs), 2)
143
        self.log('log entries:')
144
        for logentry in lf.logs:
145
            self.log('%4d %s' % (logentry.revno, logentry.rev.message))
146
        
147
        # first one is most recent
148
        logentry = lf.logs[0]
149
        eq(logentry.revno, 2)
150
        eq(logentry.rev.message, 'add one file')
151
        d = logentry.delta
152
        self.log('log 2 delta: %r' % d)
153
        # self.checkDelta(d, added=['hello'])
154
        
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
155
        # commit a log message with control characters
156
        msg = "All 8-bit chars: " +  ''.join([unichr(x) for x in range(256)])
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
157
        self.log("original commit message: %r", msg)
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
158
        b.working_tree().commit(msg)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
159
        lf = LogCatcher()
160
        show_log(b, lf, verbose=True)
161
        committed_msg = lf.logs[0].rev.message
162
        self.log("escaped commit message: %r", committed_msg)
163
        self.assert_(msg != committed_msg)
164
        self.assert_(len(committed_msg) > len(msg))
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
165
166
        # Check that log message with only XML-valid characters isn't
167
        # escaped.  As ElementTree apparently does some kind of
168
        # newline conversion, neither LF (\x0A) nor CR (\x0D) are
169
        # included in the test commit message, even though they are
170
        # valid XML 1.0 characters.
171
        msg = "\x09" + ''.join([unichr(x) for x in range(0x20, 256)])
172
        self.log("original commit message: %r", msg)
1185.33.32 by Martin Pool
[merge] fix \t in commit messages
173
        b.working_tree().commit(msg)
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
174
        lf = LogCatcher()
175
        show_log(b, lf, verbose=True)
176
        committed_msg = lf.logs[0].rev.message
177
        self.log("escaped commit message: %r", committed_msg)
178
        self.assert_(msg == committed_msg)
1185.31.22 by John Arbash Meinel
[merge] bzr.dev
179
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
180
    def test_trailing_newlines(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
181
        wt = self.make_branch_and_tree('.')
182
        b = wt.branch
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
183
        b.nick='test'
184
        wt = b.working_tree()
185
        open('a', 'wb').write('hello moto\n')
1185.33.54 by Martin Pool
[merge] test renames and other fixes (John)
186
        wt.add('a')
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
187
        wt.commit('simple log message', rev_id='a1'
188
                , timestamp=1132586655.459960938, timezone=-6*3600
189
                , committer='Joe Foo <joe@foo.com>')
190
        open('b', 'wb').write('goodbye\n')
1185.33.54 by Martin Pool
[merge] test renames and other fixes (John)
191
        wt.add('b')
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
192
        wt.commit('multiline\nlog\nmessage\n', rev_id='a2'
193
                , timestamp=1132586842.411175966, timezone=-6*3600
194
                , committer='Joe Foo <joe@foo.com>')
195
196
        open('c', 'wb').write('just another manic monday\n')
1185.33.54 by Martin Pool
[merge] test renames and other fixes (John)
197
        wt.add('c')
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
198
        wt.commit('single line with trailing newline\n', rev_id='a3'
199
                , timestamp=1132587176.835228920, timezone=-6*3600
200
                , committer = 'Joe Foo <joe@foo.com>')
201
202
        sio = StringIO()
203
        lf = ShortLogFormatter(to_file=sio)
204
        show_log(b, lf)
205
        self.assertEquals(sio.getvalue(), """\
206
    3 Joe Foo\t2005-11-21
207
      single line with trailing newline
208
209
    2 Joe Foo\t2005-11-21
210
      multiline
211
      log
212
      message
213
214
    1 Joe Foo\t2005-11-21
215
      simple log message
216
217
""")
218
219
        sio = StringIO()
220
        lf = LongLogFormatter(to_file=sio)
221
        show_log(b, lf)
222
        self.assertEquals(sio.getvalue(), """\
223
------------------------------------------------------------
224
revno: 3
225
committer: Joe Foo <joe@foo.com>
226
branch nick: test
227
timestamp: Mon 2005-11-21 09:32:56 -0600
228
message:
229
  single line with trailing newline
230
------------------------------------------------------------
231
revno: 2
232
committer: Joe Foo <joe@foo.com>
233
branch nick: test
234
timestamp: Mon 2005-11-21 09:27:22 -0600
235
message:
236
  multiline
237
  log
238
  message
239
------------------------------------------------------------
240
revno: 1
241
committer: Joe Foo <joe@foo.com>
242
branch nick: test
243
timestamp: Mon 2005-11-21 09:24:15 -0600
244
message:
245
  simple log message
246
""")
247
        
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
248
    def test_verbose_log(self):
249
        """Verbose log includes changed files
250
        
251
        bug #4676
252
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
253
        wt = self.make_branch_and_tree('.')
254
        b = wt.branch
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
255
        self.build_tree(['a'])
1185.33.45 by Martin Pool
[merge] refactoring of branch vs working tree, etc (robertc)
256
        wt.add('a')
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
257
        # XXX: why does a longer nick show up?
258
        b.nick = 'test_verbose_log'
259
        wt.commit(message='add a', 
260
                  timestamp=1132711707, 
261
                  timezone=36000,
262
                  committer='Lorem Ipsum <test@example.com>')
263
        logfile = file('out.tmp', 'w+')
264
        formatter = LongLogFormatter(to_file=logfile)
265
        show_log(b, formatter, verbose=True)
266
        logfile.flush()
267
        logfile.seek(0)
268
        log_contents = logfile.read()
269
        self.assertEqualDiff(log_contents, '''\
270
------------------------------------------------------------
271
revno: 1
272
committer: Lorem Ipsum <test@example.com>
273
branch nick: test_verbose_log
274
timestamp: Wed 2005-11-23 12:08:27 +1000
275
message:
276
  add a
277
added:
278
  a
279
''')