1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
# -*- coding: utf-8 -*-
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Black-box tests for bzr log."""
import os
import bzrlib
from bzrlib.tests.blackbox import ExternalBase
from bzrlib.tests import TestCaseInTempDir, TestCaseWithTransport
class TestLog(ExternalBase):
def _prepare(self, format=None):
if format:
self.runbzr("init --format="+format)
else:
self.runbzr("init")
self.build_tree(['hello.txt', 'goodbye.txt', 'meep.txt'])
self.runbzr("add hello.txt")
self.runbzr("commit -m message1 hello.txt")
self.runbzr("add goodbye.txt")
self.runbzr("commit -m message2 goodbye.txt")
self.runbzr("add meep.txt")
self.runbzr("commit -m message3 meep.txt")
self.full_log = self.runbzr("log")[0]
def test_log_null_end_revspec(self):
self._prepare()
self.assertTrue('revno: 1\n' in self.full_log)
self.assertTrue('revno: 2\n' in self.full_log)
self.assertTrue('revno: 3\n' in self.full_log)
self.assertTrue('message:\n message1\n' in self.full_log)
self.assertTrue('message:\n message2\n' in self.full_log)
self.assertTrue('message:\n message3\n' in self.full_log)
log = self.runbzr("log -r 1..")[0]
self.assertEquals(log, self.full_log)
def test_log_null_begin_revspec(self):
self._prepare()
log = self.runbzr("log -r ..3")[0]
self.assertEquals(self.full_log, log)
def test_log_null_both_revspecs(self):
self._prepare()
log = self.runbzr("log -r ..")[0]
self.assertEquals(self.full_log, log)
def test_log_negative_begin_revspec_full_log(self):
self._prepare()
log = self.runbzr("log -r -3..")[0]
self.assertEquals(self.full_log, log)
def test_log_negative_both_revspec_full_log(self):
self._prepare()
log = self.runbzr("log -r -3..-1")[0]
self.assertEquals(self.full_log, log)
def test_log_negative_both_revspec_partial(self):
self._prepare()
log = self.runbzr("log -r -3..-2")[0]
self.assertTrue('revno: 1\n' in log)
self.assertTrue('revno: 2\n' in log)
self.assertTrue('revno: 3\n' not in log)
def test_log_negative_begin_revspec(self):
self._prepare()
log = self.runbzr("log -r -2..")[0]
self.assertTrue('revno: 1\n' not in log)
self.assertTrue('revno: 2\n' in log)
self.assertTrue('revno: 3\n' in log)
def test_log_postive_revspecs(self):
self._prepare()
log = self.runbzr("log -r 1..3")[0]
self.assertEquals(self.full_log, log)
def test_log_revno_n_path(self):
os.mkdir('branch1')
os.chdir('branch1')
self._prepare()
os.chdir('..')
os.mkdir('branch2')
os.chdir('branch2')
self._prepare()
os.chdir('..')
log = self.runbzr("log -r revno:2:branch1..revno:3:branch2",
retcode=3)[0]
log = self.runbzr("log -r revno:1:branch2..revno:3:branch2")[0]
self.assertEquals(self.full_log, log)
log = self.runbzr("log -r revno:1:branch2")[0]
self.assertTrue('revno: 1\n' in log)
self.assertTrue('revno: 2\n' not in log)
self.assertTrue('branch nick: branch2\n' in log)
self.assertTrue('branch nick: branch1\n' not in log)
def test_log_nonexistent_file(self):
# files that don't exist in either the basis tree or working tree
# should give an error
wt = self.make_branch_and_tree('.')
out, err = self.run_bzr('log', 'does-not-exist', retcode=3)
self.assertContainsRe(
err, 'Path does not have any revision history: does-not-exist')
def test_log_with_tags(self):
self._prepare(format='dirstate-tags')
self.runbzr('tag -r1 tag1')
self.runbzr('tag -r1 tag1.1')
self.runbzr('tag tag3')
log = self.runbzr("log -r-1")[0]
self.assertTrue('tags: tag3' in log)
log = self.runbzr("log -r1")[0]
# I guess that we can't know the order of tags in the output
# since dicts are unordered, need to check both possibilities
self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
def test_merged_log_with_tags(self):
os.mkdir('branch1')
os.chdir('branch1')
self._prepare(format='dirstate-tags')
os.chdir('..')
self.runbzr('branch branch1 branch2')
os.chdir('branch1')
self.runbzr('commit -m foobar --unchanged')
self.runbzr('tag tag1')
os.chdir('../branch2')
self.runbzr('merge ../branch1')
self.runbzr('commit -m merge_branch_1')
log = self.runbzr("log -r-1")[0]
self.assertContainsRe(log, r' tags: tag1')
class TestLogMerges(ExternalBase):
def test_merges_are_indented_by_level(self):
self.build_tree(['parent/'])
self.run_bzr('init', 'parent')
self.run_bzr('commit', '-m', 'first post', '--unchanged', 'parent')
self.run_bzr('branch', 'parent', 'child')
self.run_bzr('commit', '-m', 'branch 1', '--unchanged', 'child')
self.run_bzr('branch', 'child', 'smallerchild')
self.run_bzr('commit', '-m', 'branch 2', '--unchanged', 'smallerchild')
os.chdir('child')
self.run_bzr('merge', '../smallerchild')
self.run_bzr('commit', '-m', 'merge branch 2')
os.chdir('../parent')
self.run_bzr('merge', '../child')
self.run_bzr('commit', '-m', 'merge branch 1')
out,err = self.run_bzr('log')
# the log will look something like:
# self.assertEqual("""\
#------------------------------------------------------------
#revno: 2
#committer: Robert Collins <foo@example.com>
#branch nick: parent
#timestamp: Tue 2006-03-28 22:31:40 +1100
#message:
# merge branch 1
# ------------------------------------------------------------
# revno: 1.1.2
# merged: foo@example.com-20060328113140-91f43cfb46dc2863
# committer: Robert Collins <foo@example.com>
# branch nick: child
# timestamp: Tue 2006-03-28 22:31:40 +1100
# message:
# merge branch 2
# ------------------------------------------------------------
# revno: 1.1.1.1
# merged: foo@example.com-20060328113140-1ba24f850a0ef573
# committer: Robert Collins <foo@example.com>
# branch nick: smallerchild
# timestamp: Tue 2006-03-28 22:31:40 +1100
# message:
# branch 2
# ------------------------------------------------------------
# revno: 1.1.1
# merged: foo@example.com-20060328113140-5749a4757a8ac792
# committer: Robert Collins <foo@example.com>
# branch nick: child
# timestamp: Tue 2006-03-28 22:31:40 +1100
# message:
# branch 1
#------------------------------------------------------------
#revno: 1
#committer: Robert Collins <foo@example.com>
#branch nick: parent
#timestamp: Tue 2006-03-28 22:31:39 +1100
#message:
# first post
#""", out)
# but we dont have a nice pattern matcher hooked up yet, so:
# we check for the indenting of the commit message and the
# revision numbers
self.assertTrue('revno: 2' in out)
self.assertTrue(' merge branch 1' in out)
self.assertTrue(' revno: 1.1.2' in out)
self.assertTrue(' merge branch 2' in out)
self.assertTrue(' revno: 1.1.1.1' in out)
self.assertTrue(' branch 2' in out)
self.assertTrue(' revno: 1.1.1' in out)
self.assertTrue(' branch 1' in out)
self.assertTrue('revno: 1' in out)
self.assertTrue(' first post' in out)
self.assertEqual('', err)
class TestLogEncodings(TestCaseInTempDir):
_mu = u'\xb5'
_message = u'Message with \xb5'
# Encodings which can encode mu
good_encodings = [
'utf-8',
'latin-1',
'iso-8859-1',
'cp437', # Common windows encoding
'cp1251', # Alexander Belchenko's windows encoding
'cp1258', # Common windows encoding
]
# Encodings which cannot encode mu
bad_encodings = [
'ascii',
'iso-8859-2',
'koi8_r',
]
def setUp(self):
TestCaseInTempDir.setUp(self)
self.user_encoding = bzrlib.user_encoding
def tearDown(self):
bzrlib.user_encoding = self.user_encoding
TestCaseInTempDir.tearDown(self)
def create_branch(self):
bzr = self.run_bzr
bzr('init')
open('a', 'wb').write('some stuff\n')
bzr('add', 'a')
bzr('commit', '-m', self._message)
def try_encoding(self, encoding, fail=False):
bzr = self.run_bzr
if fail:
self.assertRaises(UnicodeEncodeError,
self._mu.encode, encoding)
encoded_msg = self._message.encode(encoding, 'replace')
else:
encoded_msg = self._message.encode(encoding)
old_encoding = bzrlib.user_encoding
# This test requires that 'run_bzr' uses the current
# bzrlib, because we override user_encoding, and expect
# it to be used
try:
bzrlib.user_encoding = 'ascii'
# We should be able to handle any encoding
out, err = bzr('log', encoding=encoding)
if not fail:
# Make sure we wrote mu as we expected it to exist
self.assertNotEqual(-1, out.find(encoded_msg))
out_unicode = out.decode(encoding)
self.assertNotEqual(-1, out_unicode.find(self._message))
else:
self.assertNotEqual(-1, out.find('Message with ?'))
finally:
bzrlib.user_encoding = old_encoding
def test_log_handles_encoding(self):
self.create_branch()
for encoding in self.good_encodings:
self.try_encoding(encoding)
def test_log_handles_bad_encoding(self):
self.create_branch()
for encoding in self.bad_encodings:
self.try_encoding(encoding, fail=True)
def test_stdout_encoding(self):
bzr = self.run_bzr
bzrlib.user_encoding = "cp1251"
bzr('init')
self.build_tree(['a'])
bzr('add', 'a')
bzr('commit', '-m', u'\u0422\u0435\u0441\u0442')
stdout, stderr = self.run_bzr('log', encoding='cp866')
message = stdout.splitlines()[-1]
# explanation of the check:
# u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
# in cp866 encoding this is string '\x92\xa5\xe1\xe2'
# in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
# This test should check that output of log command
# encoded to sys.stdout.encoding
test_in_cp866 = '\x92\xa5\xe1\xe2'
test_in_cp1251 = '\xd2\xe5\xf1\xf2'
# Make sure the log string is encoded in cp866
self.assertEquals(test_in_cp866, message[2:])
# Make sure the cp1251 string is not found anywhere
self.assertEquals(-1, stdout.find(test_in_cp1251))
class TestLogFile(TestCaseWithTransport):
def test_log_local_branch_file(self):
"""We should be able to log files in local treeless branches"""
tree = self.make_branch_and_tree('tree')
self.build_tree(['tree/file'])
tree.add('file')
tree.commit('revision 1')
tree.bzrdir.destroy_workingtree()
self.run_bzr('log', 'tree/file')
|