19
19
"""Black-box tests for bzr.
21
21
These check that it behaves properly when it's invoked through the regular
22
command-line interface. This doesn't actually run a new interpreter but
23
rather starts again from the run_bzr function.
22
command-line interface.
24
This always reinvokes bzr through a new Python interpreter, which is a
25
bit inefficient but arguably tests in a way more representative of how
26
it's normally invoked.
27
from cStringIO import StringIO
33
from bzrlib.branch import Branch
34
from bzrlib.errors import BzrCommandError
35
from bzrlib.osutils import has_symlinks
36
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
37
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
40
class ExternalBase(TestCaseInTempDir):
42
def runbzr(self, args, retcode=0, backtick=False):
43
if isinstance(args, basestring):
47
return self.run_bzr_captured(args, retcode=retcode)[0]
49
return self.run_bzr_captured(args, retcode=retcode)
52
class TestCommands(ExternalBase):
54
def test_help_commands(self):
57
self.runbzr('help commands')
58
self.runbzr('help help')
59
self.runbzr('commit -h')
61
def test_init_branch(self):
64
def test_whoami(self):
29
# this code was previously in testbzr
31
from unittest import TestCase
32
from bzrlib.selftest import TestBase, InTempDir
34
class TestVersion(TestBase):
36
# output is intentionally passed through to stdout so that we
37
# can see the version being tested
38
self.runcmd(['bzr', 'version'])
42
class HelpCommands(TestBase):
44
self.runcmd('bzr --help')
45
self.runcmd('bzr help')
46
self.runcmd('bzr help commands')
47
self.runcmd('bzr help help')
48
self.runcmd('bzr commit -h')
51
class InitBranch(InTempDir):
54
self.runcmd(['bzr', 'init'])
58
class UserIdentity(InTempDir):
65
60
# this should always identify something, if only "john@localhost"
67
self.runbzr("whoami --email")
69
self.assertEquals(self.runbzr("whoami --email",
70
backtick=True).count('@'), 1)
72
def test_whoami_branch(self):
73
"""branch specific user identity works."""
75
f = file('.bzr/email', 'wt')
76
f.write('Branch Identity <branch@identi.ty>')
78
bzr_email = os.environ.get('BZREMAIL')
79
if bzr_email is not None:
80
del os.environ['BZREMAIL']
81
whoami = self.runbzr("whoami",backtick=True)
82
whoami_email = self.runbzr("whoami --email",backtick=True)
83
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
84
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
85
# Verify that the environment variable overrides the value
87
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
88
whoami = self.runbzr("whoami",backtick=True)
89
whoami_email = self.runbzr("whoami --email",backtick=True)
90
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
91
self.assertTrue(whoami_email.startswith('other@environ.ment'))
92
if bzr_email is not None:
93
os.environ['BZREMAIL'] = bzr_email
95
def test_invalid_commands(self):
96
self.runbzr("pants", retcode=1)
97
self.runbzr("--pants off", retcode=1)
98
self.runbzr("diff --message foo", retcode=1)
100
def test_empty_commit(self):
61
self.runcmd("bzr whoami")
62
self.runcmd("bzr whoami --email")
63
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
67
class InvalidCommands(InTempDir):
69
self.runcmd("bzr pants", retcode=1)
70
self.runcmd("bzr --pants off", retcode=1)
71
self.runcmd("bzr diff --message foo", retcode=1)
75
class EmptyCommit(InTempDir):
77
self.runcmd("bzr init")
102
78
self.build_tree(['hello.txt'])
103
self.runbzr("commit -m empty", retcode=1)
104
self.runbzr("add hello.txt")
105
self.runbzr("commit -m added")
107
def test_empty_commit_message(self):
109
file('foo.c', 'wt').write('int main() {}')
110
self.runbzr(['add', 'foo.c'])
111
self.runbzr(["commit", "-m", ""] , retcode=1)
113
def test_ignore_patterns(self):
114
from bzrlib.branch import Branch
116
b = Branch.initialize('.')
117
self.assertEquals(list(b.unknowns()), [])
119
file('foo.tmp', 'wt').write('tmp files are ignored')
120
self.assertEquals(list(b.unknowns()), [])
121
assert self.capture('unknowns') == ''
123
file('foo.c', 'wt').write('int main() {}')
124
self.assertEquals(list(b.unknowns()), ['foo.c'])
125
assert self.capture('unknowns') == 'foo.c\n'
127
self.runbzr(['add', 'foo.c'])
128
assert self.capture('unknowns') == ''
130
# 'ignore' works when creating the .bzignore file
131
file('foo.blah', 'wt').write('blah')
132
self.assertEquals(list(b.unknowns()), ['foo.blah'])
133
self.runbzr('ignore *.blah')
134
self.assertEquals(list(b.unknowns()), [])
135
assert file('.bzrignore', 'rU').read() == '*.blah\n'
137
# 'ignore' works when then .bzrignore file already exists
138
file('garh', 'wt').write('garh')
139
self.assertEquals(list(b.unknowns()), ['garh'])
140
assert self.capture('unknowns') == 'garh\n'
141
self.runbzr('ignore garh')
142
self.assertEquals(list(b.unknowns()), [])
143
assert file('.bzrignore', 'rU').read() == '*.blah\ngarh\n'
145
def test_revert(self):
148
file('hello', 'wt').write('foo')
149
self.runbzr('add hello')
150
self.runbzr('commit -m setup hello')
152
file('goodbye', 'wt').write('baz')
153
self.runbzr('add goodbye')
154
self.runbzr('commit -m setup goodbye')
156
file('hello', 'wt').write('bar')
157
file('goodbye', 'wt').write('qux')
158
self.runbzr('revert hello')
159
self.check_file_contents('hello', 'foo')
160
self.check_file_contents('goodbye', 'qux')
161
self.runbzr('revert')
162
self.check_file_contents('goodbye', 'baz')
164
os.mkdir('revertdir')
165
self.runbzr('add revertdir')
166
self.runbzr('commit -m f')
167
os.rmdir('revertdir')
168
self.runbzr('revert')
170
os.symlink('/unlikely/to/exist', 'symlink')
171
self.runbzr('add symlink')
172
self.runbzr('commit -m f')
174
self.runbzr('revert')
176
file('hello', 'wt').write('xyz')
177
self.runbzr('commit -m xyz hello')
178
self.runbzr('revert -r 1 hello')
179
self.check_file_contents('hello', 'foo')
180
self.runbzr('revert hello')
181
self.check_file_contents('hello', 'xyz')
182
os.chdir('revertdir')
183
self.runbzr('revert')
187
def test_mv_modes(self):
188
"""Test two modes of operation for mv"""
189
from bzrlib.branch import Branch
190
b = Branch.initialize('.')
191
self.build_tree(['a', 'c', 'subdir/'])
192
self.run_bzr_captured(['add', self.test_dir])
193
self.run_bzr_captured(['mv', 'a', 'b'])
194
self.run_bzr_captured(['mv', 'b', 'subdir'])
195
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
196
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
197
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
199
def test_main_version(self):
200
"""Check output from version command and master option is reasonable"""
201
# output is intentionally passed through to stdout so that we
202
# can see the version being tested
203
output = self.runbzr('version', backtick=1)
204
self.log('bzr version output:')
206
self.assert_(output.startswith('bzr (bazaar-ng) '))
207
self.assertNotEqual(output.index('Canonical'), -1)
208
# make sure --version is consistent
209
tmp_output = self.runbzr('--version', backtick=1)
210
self.log('bzr --version output:')
212
self.assertEquals(output, tmp_output)
214
def example_branch(test):
216
file('hello', 'wt').write('foo')
217
test.runbzr('add hello')
218
test.runbzr('commit -m setup hello')
219
file('goodbye', 'wt').write('baz')
220
test.runbzr('add goodbye')
221
test.runbzr('commit -m setup goodbye')
223
def test_export(self):
226
self.example_branch()
227
self.runbzr('export ../latest')
228
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
229
self.runbzr('export ../first -r 1')
230
assert not os.path.exists('../first/goodbye')
231
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
232
self.runbzr('export ../first.gz -r 1')
233
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
234
self.runbzr('export ../first.bz2 -r 1')
235
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
236
self.runbzr('export ../first.tar -r 1')
237
assert os.path.isfile('../first.tar')
238
from tarfile import TarFile
239
tf = TarFile('../first.tar')
240
assert 'first/hello' in tf.getnames(), tf.getnames()
241
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
242
self.runbzr('export ../first.tar.gz -r 1')
243
assert os.path.isfile('../first.tar.gz')
244
self.runbzr('export ../first.tbz2 -r 1')
245
assert os.path.isfile('../first.tbz2')
246
self.runbzr('export ../first.tar.bz2 -r 1')
247
assert os.path.isfile('../first.tar.bz2')
248
self.runbzr('export ../first.tar.tbz2 -r 1')
249
assert os.path.isfile('../first.tar.tbz2')
250
from bz2 import BZ2File
251
tf = TarFile('../first.tar.tbz2',
252
fileobj=BZ2File('../first.tar.tbz2', 'r'))
253
assert 'first.tar/hello' in tf.getnames(), tf.getnames()
254
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
255
self.runbzr('export ../first2.tar -r 1 --root pizza')
256
tf = TarFile('../first2.tar')
257
assert 'pizza/hello' in tf.getnames(), tf.getnames()
260
self.example_branch()
261
file('hello', 'wt').write('hello world!')
262
self.runbzr('commit -m fixing hello')
263
output = self.runbzr('diff -r 2..3', backtick=1)
264
self.assert_('\n+hello world!' in output)
265
output = self.runbzr('diff -r last:3..last:1', backtick=1)
266
self.assert_('\n+baz' in output)
268
def test_branch(self):
269
"""Branch from one branch to another."""
272
self.example_branch()
274
self.runbzr('branch a b')
275
self.runbzr('branch a c -r 1')
277
self.runbzr('commit -m foo --unchanged')
279
# naughty - abstraction violations RBC 20050928
280
print "test_branch used to delete the stores, how is this meant to work ?"
281
#shutil.rmtree('a/.bzr/revision-store')
282
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
283
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
284
self.runbzr('branch a d --basis b')
286
def test_merge(self):
287
from bzrlib.branch import Branch
291
self.example_branch()
293
self.runbzr('branch a b')
295
file('goodbye', 'wt').write('quux')
296
self.runbzr(['commit', '-m', "more u's are always good"])
299
file('hello', 'wt').write('quuux')
300
# We can't merge when there are in-tree changes
301
self.runbzr('merge ../b', retcode=1)
302
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
303
self.runbzr('merge ../b')
304
self.check_file_contents('goodbye', 'quux')
305
# Merging a branch pulls its revision into the tree
307
b = Branch.open('../b')
308
a.get_revision_xml(b.last_revision())
309
self.log('pending merges: %s', a.pending_merges())
310
# assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
311
# % (a.pending_merges(), b.last_revision())
313
def test_merge_with_missing_file(self):
314
"""Merge handles missing file conflicts"""
318
print >> file('sub/a.txt', 'wb'), "hello"
319
print >> file('b.txt', 'wb'), "hello"
320
print >> file('sub/c.txt', 'wb'), "hello"
323
self.runbzr(('commit', '-m', 'added a'))
324
self.runbzr('branch . ../b')
325
print >> file('sub/a.txt', 'ab'), "there"
326
print >> file('b.txt', 'ab'), "there"
327
print >> file('sub/c.txt', 'ab'), "there"
328
self.runbzr(('commit', '-m', 'Added there'))
329
os.unlink('sub/a.txt')
330
os.unlink('sub/c.txt')
333
self.runbzr(('commit', '-m', 'Removed a.txt'))
335
print >> file('sub/a.txt', 'ab'), "something"
336
print >> file('b.txt', 'ab'), "something"
337
print >> file('sub/c.txt', 'ab'), "something"
338
self.runbzr(('commit', '-m', 'Modified a.txt'))
339
self.runbzr('merge ../a/')
340
assert os.path.exists('sub/a.txt.THIS')
341
assert os.path.exists('sub/a.txt.BASE')
343
self.runbzr('merge ../b/')
344
assert os.path.exists('sub/a.txt.OTHER')
345
assert os.path.exists('sub/a.txt.BASE')
348
"""Pull changes from one branch to another."""
352
self.example_branch()
353
self.runbzr('pull', retcode=1)
354
self.runbzr('missing', retcode=1)
355
self.runbzr('missing .')
356
self.runbzr('missing')
358
self.runbzr('pull /', retcode=1)
362
self.runbzr('branch a b')
366
self.runbzr('add subdir')
367
self.runbzr('commit -m blah --unchanged')
370
b = Branch.open('../b')
371
assert a.revision_history() == b.revision_history()[:-1]
372
self.runbzr('pull ../b')
373
assert a.revision_history() == b.revision_history()
374
self.runbzr('commit -m blah2 --unchanged')
376
self.runbzr('commit -m blah3 --unchanged')
377
self.runbzr('pull ../a', retcode=1)
378
print "DECIDE IF PULL CAN CONVERGE, blackbox.py"
381
self.runbzr('merge ../b')
382
self.runbzr('commit -m blah4 --unchanged')
383
os.chdir('../b/subdir')
384
self.runbzr('pull ../../a')
385
assert a.revision_history()[-1] == b.revision_history()[-1]
386
self.runbzr('commit -m blah5 --unchanged')
387
self.runbzr('commit -m blah6 --unchanged')
389
self.runbzr('pull ../a')
391
self.runbzr('commit -m blah7 --unchanged')
392
self.runbzr('merge ../b')
393
self.runbzr('commit -m blah8 --unchanged')
394
self.runbzr('pull ../b')
395
self.runbzr('pull ../b')
397
def test_add_reports(self):
398
"""add command prints the names of added files."""
399
b = Branch.initialize('.')
400
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
401
out = self.run_bzr_captured(['add'], retcode = 0)[0]
402
# the ordering is not defined at the moment
403
results = sorted(out.rstrip('\n').split('\n'))
404
self.assertEquals(['added dir',
405
'added dir'+os.sep+'sub.txt',
409
def test_unknown_command(self):
410
"""Handling of unknown command."""
411
out, err = self.run_bzr_captured(['fluffy-badger'],
413
self.assertEquals(out, '')
414
err.index('unknown command')
417
def listdir_sorted(dir):
423
class OldTests(ExternalBase):
424
"""old tests moved from ./testbzr."""
79
self.runcmd("bzr commit -m empty", retcode=1)
80
self.runcmd("bzr add hello.txt")
81
self.runcmd("bzr commit -m added")
85
class OldTests(InTempDir):
86
# old tests moved from ./testbzr
427
88
from os import chdir, mkdir
428
89
from os.path import exists
431
capture = self.capture
93
backtick = self.backtick
432
94
progress = self.log
434
96
progress("basic branch creation")
97
runcmd(['mkdir', 'branch1'])
439
self.assertEquals(capture('root').rstrip(),
101
self.assertEquals(backtick('bzr root').rstrip(),
440
102
os.path.join(self.test_dir, 'branch1'))
442
104
progress("status of new file")
471
134
os.unlink('test2.txt')
473
136
progress("command aliases")
474
out = capture("st --all")
137
out = backtick("bzr st --all")
475
138
assert out == ("unknown:\n"
478
out = capture("stat")
141
out = backtick("bzr stat")
479
142
assert out == ("unknown:\n"
482
145
progress("command help")
485
runbzr("help commands")
486
runbzr("help slartibartfast", 1)
146
runcmd("bzr help st")
148
runcmd("bzr help commands")
149
runcmd("bzr help slartibartfast", 1)
488
out = capture("help ci")
151
out = backtick("bzr help ci")
489
152
out.index('aliases: ')
491
154
progress("can't rename unversioned file")
492
runbzr("rename test.txt new-test.txt", 1)
155
runcmd("bzr rename test.txt new-test.txt", 1)
494
157
progress("adding a file")
496
runbzr("add test.txt")
497
assert capture("unknowns") == ''
498
assert capture("status --all") == ("added:\n"
159
runcmd("bzr add test.txt")
160
assert backtick("bzr unknowns") == ''
161
assert backtick("bzr status --all") == ("added:\n"
501
164
progress("rename newly-added file")
502
runbzr("rename test.txt hello.txt")
165
runcmd("bzr rename test.txt hello.txt")
503
166
assert os.path.exists("hello.txt")
504
167
assert not os.path.exists("test.txt")
506
assert capture("revno") == '0\n'
169
assert backtick("bzr revno") == '0\n'
508
171
progress("add first revision")
509
runbzr(['commit', '-m', 'add first revision'])
172
runcmd(["bzr", "commit", "-m", 'add first revision'])
511
174
progress("more complex renames")
513
runbzr("rename hello.txt sub1", 1)
514
runbzr("rename hello.txt sub1/hello.txt", 1)
515
runbzr("move hello.txt sub1", 1)
176
runcmd("bzr rename hello.txt sub1", 1)
177
runcmd("bzr rename hello.txt sub1/hello.txt", 1)
178
runcmd("bzr move hello.txt sub1", 1)
518
runbzr("rename sub1 sub2")
519
runbzr("move hello.txt sub2")
520
assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
180
runcmd("bzr add sub1")
181
runcmd("bzr rename sub1 sub2")
182
runcmd("bzr move hello.txt sub2")
183
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
522
185
assert exists("sub2")
523
186
assert exists("sub2/hello.txt")
524
187
assert not exists("sub1")
525
188
assert not exists("hello.txt")
527
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
190
runcmd(['bzr', 'commit', '-m', 'commit with some things moved to subdirs'])
531
runbzr('move sub2/hello.txt sub1')
193
runcmd('bzr add sub1')
194
runcmd('bzr move sub2/hello.txt sub1')
532
195
assert not exists('sub2/hello.txt')
533
196
assert exists('sub1/hello.txt')
534
runbzr('move sub2 sub1')
197
runcmd('bzr move sub2 sub1')
535
198
assert not exists('sub2')
536
199
assert exists('sub1/sub2')
538
runbzr(['commit', '-m', 'rename nested subdirectories'])
201
runcmd(['bzr', 'commit', '-m', 'rename nested subdirectories'])
540
203
chdir('sub1/sub2')
541
self.assertEquals(capture('root')[:-1],
204
self.assertEquals(backtick('bzr root')[:-1],
542
205
os.path.join(self.test_dir, 'branch1'))
543
runbzr('move ../hello.txt .')
206
runcmd('bzr move ../hello.txt .')
544
207
assert exists('./hello.txt')
545
self.assertEquals(capture('relpath hello.txt'),
546
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
547
assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
548
runbzr(['commit', '-m', 'move to parent directory'])
208
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
209
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
210
runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
550
assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
212
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
552
runbzr('move sub2/hello.txt .')
214
runcmd('bzr move sub2/hello.txt .')
553
215
assert exists('hello.txt')
555
217
f = file('hello.txt', 'wt')
560
222
f.write('this is my new commit\n')
563
runbzr('commit -F msg.tmp')
565
assert capture('revno') == '5\n'
566
runbzr('export -r 5 export-5.tmp')
567
runbzr('export export.tmp')
571
runbzr('log -v --forward')
572
runbzr('log -m', retcode=1)
573
log_out = capture('log -m commit')
574
assert "this is my new commit" in log_out
575
assert "rename nested" not in log_out
576
assert 'revision-id' not in log_out
577
assert 'revision-id' in capture('log --show-ids -m commit')
225
runcmd('bzr commit -F msg.tmp')
227
assert backtick('bzr revno') == '5\n'
228
runcmd('bzr export -r 5 export-5.tmp')
229
runcmd('bzr export export.tmp')
580
236
progress("file with spaces in name")
581
237
mkdir('sub directory')
582
238
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
585
runbzr('commit -m add-spaces')
589
runbzr('log --forward')
598
os.symlink("NOWHERE1", "link1")
600
assert self.capture('unknowns') == ''
601
runbzr(['commit', '-m', '1: added symlink link1'])
605
assert self.capture('unknowns') == ''
606
os.symlink("NOWHERE2", "d1/link2")
607
assert self.capture('unknowns') == 'd1/link2\n'
608
# is d1/link2 found when adding d1
610
assert self.capture('unknowns') == ''
611
os.symlink("NOWHERE3", "d1/link3")
612
assert self.capture('unknowns') == 'd1/link3\n'
613
runbzr(['commit', '-m', '2: added dir, symlink'])
615
runbzr('rename d1 d2')
616
runbzr('move d2/link2 .')
617
runbzr('move link1 d2')
618
assert os.readlink("./link2") == "NOWHERE2"
619
assert os.readlink("d2/link1") == "NOWHERE1"
620
runbzr('add d2/link3')
622
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
625
os.symlink("TARGET 2", "link2")
626
os.unlink("d2/link1")
627
os.symlink("TARGET 1", "d2/link1")
629
assert self.capture("relpath d2/link1") == "d2/link1\n"
630
runbzr(['commit', '-m', '4: retarget of two links'])
632
runbzr('remove d2/link1')
633
assert self.capture('unknowns') == 'd2/link1\n'
634
runbzr(['commit', '-m', '5: remove d2/link1'])
638
runbzr('rename d2/link3 d1/link3new')
639
assert self.capture('unknowns') == 'd2/link1\n'
640
runbzr(['commit', '-m', '6: remove d2/link1, move/rename link3'])
644
runbzr(['export', '-r', '1', 'exp1.tmp'])
646
assert listdir_sorted(".") == [ "link1" ]
647
assert os.readlink("link1") == "NOWHERE1"
650
runbzr(['export', '-r', '2', 'exp2.tmp'])
652
assert listdir_sorted(".") == [ "d1", "link1" ]
655
runbzr(['export', '-r', '3', 'exp3.tmp'])
657
assert listdir_sorted(".") == [ "d2", "link2" ]
658
assert listdir_sorted("d2") == [ "link1", "link3" ]
659
assert os.readlink("d2/link1") == "NOWHERE1"
660
assert os.readlink("link2") == "NOWHERE2"
663
runbzr(['export', '-r', '4', 'exp4.tmp'])
665
assert listdir_sorted(".") == [ "d2", "link2" ]
666
assert os.readlink("d2/link1") == "TARGET 1"
667
assert os.readlink("link2") == "TARGET 2"
668
assert listdir_sorted("d2") == [ "link1", "link3" ]
671
runbzr(['export', '-r', '5', 'exp5.tmp'])
673
assert listdir_sorted(".") == [ "d2", "link2" ]
674
assert os.path.islink("link2")
675
assert listdir_sorted("d2")== [ "link3" ]
678
runbzr(['export', '-r', '6', 'exp6.tmp'])
680
assert listdir_sorted(".") == [ "d1", "d2", "link2" ]
681
assert listdir_sorted("d1") == [ "link3new" ]
682
assert listdir_sorted("d2") == []
683
assert os.readlink("d1/link3new") == "NOWHERE3"
686
progress("skipping symlink tests")
689
class HttpTests(TestCaseWithWebserver):
690
"""Test bzr ui commands against remote branches."""
692
def test_branch(self):
694
branch = Branch.initialize('from')
695
branch.commit('empty commit for nonsense', allow_pointless=True)
696
url = self.get_remote_url('from')
697
self.run_bzr('branch', url, 'to')
698
branch = Branch.open('to')
699
self.assertEqual(1, len(branch.revision_history()))
241
runcmd('bzr commit -m add-spaces')
245
runcmd('bzr log --forward')
257
# Can't create a branch if it already exists
258
runcmd('bzr branch branch1', retcode=1)
259
# Can't create a branch if its parent doesn't exist
260
runcmd('bzr branch /unlikely/to/exist', retcode=1)
261
runcmd('bzr branch branch1 branch2')
265
runcmd('bzr pull', retcode=1)
266
runcmd('bzr pull ../branch2')
269
runcmd('bzr commit --unchanged -m empty')
271
chdir('../../branch2')
273
runcmd('bzr commit --unchanged -m empty')
275
runcmd('bzr commit --unchanged -m empty')
276
runcmd('bzr pull', retcode=1)
279
progress('status after remove')
280
mkdir('status-after-remove')
281
# see mail from William Dodé, 2005-05-25
282
# $ bzr init; touch a; bzr add a; bzr commit -m "add a"
283
# * looking for changes...
288
# bzr: local variable 'kind' referenced before assignment
289
# at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
290
# see ~/.bzr.log for debug information
291
chdir('status-after-remove')
293
file('a', 'w').write('foo')
295
runcmd(['bzr', 'commit', '-m', 'add a'])
296
runcmd('bzr remove a')
301
progress('ignore patterns')
302
mkdir('ignorebranch')
303
chdir('ignorebranch')
305
assert backtick('bzr unknowns') == ''
307
file('foo.tmp', 'wt').write('tmp files are ignored')
308
assert backtick('bzr unknowns') == ''
310
file('foo.c', 'wt').write('int main() {}')
311
assert backtick('bzr unknowns') == 'foo.c\n'
312
runcmd('bzr add foo.c')
313
assert backtick('bzr unknowns') == ''
315
# 'ignore' works when creating the .bzignore file
316
file('foo.blah', 'wt').write('blah')
317
assert backtick('bzr unknowns') == 'foo.blah\n'
318
runcmd('bzr ignore *.blah')
319
assert backtick('bzr unknowns') == ''
320
assert file('.bzrignore', 'rb').read() == '*.blah\n'
322
# 'ignore' works when then .bzrignore file already exists
323
file('garh', 'wt').write('garh')
324
assert backtick('bzr unknowns') == 'garh\n'
325
runcmd('bzr ignore garh')
326
assert backtick('bzr unknowns') == ''
327
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
334
progress("recursive and non-recursive add")
339
fp = os.path.join('foo', 'test.txt')
343
runcmd('bzr add --no-recurse foo')
344
runcmd('bzr file-id foo')
345
runcmd('bzr file-id ' + fp, 1) # not versioned yet
346
runcmd('bzr commit -m add-dir-only')
348
runcmd('bzr file-id ' + fp, 1) # still not versioned
350
runcmd('bzr add foo')
351
runcmd('bzr file-id ' + fp)
352
runcmd('bzr commit -m add-sub-file')
358
class RevertCommand(InTempDir):
360
self.runcmd('bzr init')
362
file('hello', 'wt').write('foo')
363
self.runcmd('bzr add hello')
364
self.runcmd('bzr commit -m setup hello')
366
file('hello', 'wt').write('bar')
367
self.runcmd('bzr revert hello')
368
self.check_file_contents('hello', 'foo')
374
# lists all tests from this module in the best order to run them. we
375
# do it this way rather than just discovering them all because it
376
# allows us to test more basic functions first where failures will be
377
# easiest to understand.
378
TEST_CLASSES = [TestVersion,