~bzr-pqm/bzr/bzr.dev

720 by Martin Pool
- start moving external tests into the testsuite framework
1
# Copyright (C) 2005 by Canonical Ltd
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
2
# -*- coding: utf-8 -*-
720 by Martin Pool
- start moving external tests into the testsuite framework
3
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
19
"""Black-box tests for bzr.
20
21
These check that it behaves properly when it's invoked through the regular
1403 by Robert Collins
merge from martin
22
command-line interface. This doesn't actually run a new interpreter but 
1393.1.45 by Martin Pool
doc
23
rather starts again from the run_bzr function.
720 by Martin Pool
- start moving external tests into the testsuite framework
24
"""
25
1393.1.45 by Martin Pool
doc
26
1185.1.25 by Robert Collins
merge David Clymer's patch for TestCaseInTestDir.runcmd
27
from cStringIO import StringIO
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
28
import os
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
29
import shutil
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
30
import sys
974.1.71 by Aaron Bentley
Added test for pull
31
import os
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
32
33
from bzrlib.branch import Branch
1393.3.3 by Jelmer Vernooij
Add test for empty commit messages.
34
from bzrlib.errors import BzrCommandError
1399.1.4 by Robert Collins
move diff and symlink conditionals into inventory.py from diff.py
35
from bzrlib.osutils import has_symlinks
1414 by Robert Collins
merge in an adjusted version of Jelmer's empty-log detection patch.
36
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
1400.1.1 by Robert Collins
implement a basic test for the ui branch command from http servers
37
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
38
898 by Martin Pool
- add new runbzr method for external tests
39
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
40
class ExternalBase(TestCaseInTempDir):
1185.1.31 by Robert Collins
Change the use of run_bzr to run_bzr_captured in blackbox tests - inspired by David Clymers patch to change run_bzr usage to runbzr
41
1185.3.23 by Martin Pool
- run some previously external tests in process
42
    def runbzr(self, args, retcode=0, backtick=False):
898 by Martin Pool
- add new runbzr method for external tests
43
        if isinstance(args, basestring):
44
            args = args.split()
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
45
46
        if backtick:
1185.3.23 by Martin Pool
- run some previously external tests in process
47
            return self.run_bzr_captured(args, retcode=retcode)[0]
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
48
        else:
1185.3.23 by Martin Pool
- run some previously external tests in process
49
            return self.run_bzr_captured(args, retcode=retcode)
904 by Martin Pool
- more selftest external-command fixes
50
1142 by Martin Pool
- remove dead code from blackbox tests (pychecker)
51
1102 by Martin Pool
- merge test refactoring from robertc
52
class TestCommands(ExternalBase):
53
54
    def test_help_commands(self):
898 by Martin Pool
- add new runbzr method for external tests
55
        self.runbzr('--help')
56
        self.runbzr('help')
57
        self.runbzr('help commands')
58
        self.runbzr('help help')
59
        self.runbzr('commit -h')
727 by Martin Pool
- move more code to run external commands from testbzr to selftest
60
1102 by Martin Pool
- merge test refactoring from robertc
61
    def test_init_branch(self):
898 by Martin Pool
- add new runbzr method for external tests
62
        self.runbzr(['init'])
732 by Martin Pool
- move more tests into bzr selftest
63
1102 by Martin Pool
- merge test refactoring from robertc
64
    def test_whoami(self):
732 by Martin Pool
- move more tests into bzr selftest
65
        # this should always identify something, if only "john@localhost"
898 by Martin Pool
- add new runbzr method for external tests
66
        self.runbzr("whoami")
67
        self.runbzr("whoami --email")
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
68
69
        self.assertEquals(self.runbzr("whoami --email",
70
                                      backtick=True).count('@'), 1)
71
        
1102 by Martin Pool
- merge test refactoring from robertc
72
    def test_whoami_branch(self):
73
        """branch specific user identity works."""
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
74
        self.runbzr('init')
75
        f = file('.bzr/email', 'wt')
76
        f.write('Branch Identity <branch@identi.ty>')
77
        f.close()
1185.6.1 by John Arbash Meinel
Updated the whomai test to handle BZREMAIL
78
        bzr_email = os.environ.get('BZREMAIL')
79
        if bzr_email is not None:
80
            del os.environ['BZREMAIL']
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
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'))
1185.6.1 by John Arbash Meinel
Updated the whomai test to handle BZREMAIL
85
        # Verify that the environment variable overrides the value 
86
        # in the file
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
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
94
1102 by Martin Pool
- merge test refactoring from robertc
95
    def test_invalid_commands(self):
898 by Martin Pool
- add new runbzr method for external tests
96
        self.runbzr("pants", retcode=1)
97
        self.runbzr("--pants off", retcode=1)
98
        self.runbzr("diff --message foo", retcode=1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
99
1102 by Martin Pool
- merge test refactoring from robertc
100
    def test_empty_commit(self):
898 by Martin Pool
- add new runbzr method for external tests
101
        self.runbzr("init")
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
102
        self.build_tree(['hello.txt'])
898 by Martin Pool
- add new runbzr method for external tests
103
        self.runbzr("commit -m empty", retcode=1)
104
        self.runbzr("add hello.txt")
105
        self.runbzr("commit -m added")
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
106
1393.3.3 by Jelmer Vernooij
Add test for empty commit messages.
107
    def test_empty_commit_message(self):
108
        self.runbzr("init")
109
        file('foo.c', 'wt').write('int main() {}')
110
        self.runbzr(['add', 'foo.c'])
1414 by Robert Collins
merge in an adjusted version of Jelmer's empty-log detection patch.
111
        self.runbzr(["commit", "-m", ""] , retcode=1) 
1393.3.3 by Jelmer Vernooij
Add test for empty commit messages.
112
1102 by Martin Pool
- merge test refactoring from robertc
113
    def test_ignore_patterns(self):
906 by Martin Pool
- split out black-box ignore commands
114
        from bzrlib.branch import Branch
115
        
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
116
        b = Branch.initialize('.')
906 by Martin Pool
- split out black-box ignore commands
117
        self.assertEquals(list(b.unknowns()), [])
118
119
        file('foo.tmp', 'wt').write('tmp files are ignored')
120
        self.assertEquals(list(b.unknowns()), [])
1185.3.26 by Martin Pool
- remove remaining external executions of bzr
121
        assert self.capture('unknowns') == ''
906 by Martin Pool
- split out black-box ignore commands
122
123
        file('foo.c', 'wt').write('int main() {}')
124
        self.assertEquals(list(b.unknowns()), ['foo.c'])
1185.3.26 by Martin Pool
- remove remaining external executions of bzr
125
        assert self.capture('unknowns') == 'foo.c\n'
906 by Martin Pool
- split out black-box ignore commands
126
127
        self.runbzr(['add', 'foo.c'])
1185.3.26 by Martin Pool
- remove remaining external executions of bzr
128
        assert self.capture('unknowns') == ''
906 by Martin Pool
- split out black-box ignore commands
129
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()), [])
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
135
        assert file('.bzrignore', 'rU').read() == '*.blah\n'
906 by Martin Pool
- split out black-box ignore commands
136
137
        # 'ignore' works when then .bzrignore file already exists
138
        file('garh', 'wt').write('garh')
139
        self.assertEquals(list(b.unknowns()), ['garh'])
1185.3.26 by Martin Pool
- remove remaining external executions of bzr
140
        assert self.capture('unknowns') == 'garh\n'
906 by Martin Pool
- split out black-box ignore commands
141
        self.runbzr('ignore garh')
142
        self.assertEquals(list(b.unknowns()), [])
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
143
        assert file('.bzrignore', 'rU').read() == '*.blah\ngarh\n'
1102 by Martin Pool
- merge test refactoring from robertc
144
145
    def test_revert(self):
146
        self.runbzr('init')
147
148
        file('hello', 'wt').write('foo')
149
        self.runbzr('add hello')
150
        self.runbzr('commit -m setup hello')
151
152
        file('goodbye', 'wt').write('baz')
153
        self.runbzr('add goodbye')
154
        self.runbzr('commit -m setup goodbye')
1092.2.18 by Robert Collins
merge from symlink branch
155
1102 by Martin Pool
- merge test refactoring from robertc
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')
163
164
        os.mkdir('revertdir')
165
        self.runbzr('add revertdir')
166
        self.runbzr('commit -m f')
167
        os.rmdir('revertdir')
168
        self.runbzr('revert')
169
1092.2.18 by Robert Collins
merge from symlink branch
170
        os.symlink('/unlikely/to/exist', 'symlink')
171
        self.runbzr('add symlink')
172
        self.runbzr('commit -m f')
173
        os.unlink('symlink')
174
        self.runbzr('revert')
175
        
1185.5.8 by John Arbash Meinel
Fixed bzr revert with the new RevisionSpec code.
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')
1185.8.5 by Aaron Bentley
Fixed non-tree-root bug in branch, revert, merge
182
        os.chdir('revertdir')
183
        self.runbzr('revert')
184
        os.chdir('..')
185
1185.5.8 by John Arbash Meinel
Fixed bzr revert with the new RevisionSpec code.
186
1185.1.8 by Robert Collins
David Clymers patch to use rename rather than mv for two argument non-directory target bzr mv calls.
187
    def test_mv_modes(self):
1102 by Martin Pool
- merge test refactoring from robertc
188
        """Test two modes of operation for mv"""
189
        from bzrlib.branch import Branch
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
190
        b = Branch.initialize('.')
1102 by Martin Pool
- merge test refactoring from robertc
191
        self.build_tree(['a', 'c', 'subdir/'])
1185.1.31 by Robert Collins
Change the use of run_bzr to run_bzr_captured in blackbox tests - inspired by David Clymers patch to change run_bzr usage to runbzr
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'])
1102 by Martin Pool
- merge test refactoring from robertc
198
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:')
205
        self.log(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:')
211
        self.log(tmp_output)
212
        self.assertEquals(output, tmp_output)
906 by Martin Pool
- split out black-box ignore commands
213
1092.1.39 by Robert Collins
merge from mpool
214
    def example_branch(test):
215
        test.runbzr('init')
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')
222
1185.12.1 by Aaron Bentley
Fixed export
223
    def test_export(self):
224
        os.mkdir('branch')
225
        os.chdir('branch')
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()
258
1185.4.1 by Lalo Martins
blackbox tests for diff
259
    def test_diff(self):
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)
267
1185.8.4 by Aaron Bentley
Fixed branch -r
268
    def test_branch(self):
269
        """Branch from one branch to another."""
270
        os.mkdir('a')
271
        os.chdir('a')
272
        self.example_branch()
273
        os.chdir('..')
274
        self.runbzr('branch a b')
275
        self.runbzr('branch a c -r 1')
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
276
        os.chdir('b')
277
        self.runbzr('commit -m foo --unchanged')
278
        os.chdir('..')
1391 by Robert Collins
merge from integration
279
        # naughty - abstraction violations RBC 20050928  
1393 by Robert Collins
reenable remotebranch tests
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)
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
284
        self.runbzr('branch a d --basis b')
1185.8.4 by Aaron Bentley
Fixed branch -r
285
1092.1.39 by Robert Collins
merge from mpool
286
    def test_merge(self):
287
        from bzrlib.branch import Branch
1139 by Martin Pool
- merge in merge improvements and additional tests
288
        
1092.1.39 by Robert Collins
merge from mpool
289
        os.mkdir('a')
290
        os.chdir('a')
291
        self.example_branch()
292
        os.chdir('..')
293
        self.runbzr('branch a b')
294
        os.chdir('b')
295
        file('goodbye', 'wt').write('quux')
296
        self.runbzr(['commit',  '-m',  "more u's are always good"])
297
298
        os.chdir('../a')
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
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
306
        a = Branch.open('.')
307
        b = Branch.open('../b')
1241 by Martin Pool
- rename last_patch to last_revision
308
        a.get_revision_xml(b.last_revision())
1139 by Martin Pool
- merge in merge improvements and additional tests
309
        self.log('pending merges: %s', a.pending_merges())
1241 by Martin Pool
- rename last_patch to last_revision
310
        #        assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
311
        #        % (a.pending_merges(), b.last_patch())
312
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
313
    def test_merge_with_missing_file(self):
314
        """Merge handles missing file conflicts"""
315
        os.mkdir('a')
316
        os.chdir('a')
317
        os.mkdir('sub')
318
        print >> file('sub/a.txt', 'wb'), "hello"
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
319
        print >> file('b.txt', 'wb'), "hello"
320
        print >> file('sub/c.txt', 'wb'), "hello"
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
321
        self.runbzr('init')
322
        self.runbzr('add')
323
        self.runbzr(('commit', '-m', 'added a'))
324
        self.runbzr('branch . ../b')
325
        print >> file('sub/a.txt', 'ab'), "there"
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
326
        print >> file('b.txt', 'ab'), "there"
327
        print >> file('sub/c.txt', 'ab'), "there"
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
328
        self.runbzr(('commit', '-m', 'Added there'))
329
        os.unlink('sub/a.txt')
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
330
        os.unlink('sub/c.txt')
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
331
        os.rmdir('sub')
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
332
        os.unlink('b.txt')
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
333
        self.runbzr(('commit', '-m', 'Removed a.txt'))
334
        os.chdir('../b')
335
        print >> file('sub/a.txt', 'ab'), "something"
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
336
        print >> file('b.txt', 'ab'), "something"
337
        print >> file('sub/c.txt', 'ab'), "something"
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
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')
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
342
        os.chdir('../a')
343
        self.runbzr('merge ../b/')
344
        assert os.path.exists('sub/a.txt.OTHER')
345
        assert os.path.exists('sub/a.txt.BASE')
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
346
347
    def test_merge_with_missing_file(self):
348
        """Merge handles missing file conflicts"""
349
        os.mkdir('a')
350
        os.chdir('a')
351
        os.mkdir('sub')
352
        print >> file('sub/a.txt', 'wb'), "hello"
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
353
        print >> file('b.txt', 'wb'), "hello"
354
        print >> file('sub/c.txt', 'wb'), "hello"
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
355
        self.runbzr('init')
356
        self.runbzr('add')
357
        self.runbzr(('commit', '-m', 'added a'))
358
        self.runbzr('branch . ../b')
359
        print >> file('sub/a.txt', 'ab'), "there"
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
360
        print >> file('b.txt', 'ab'), "there"
361
        print >> file('sub/c.txt', 'ab'), "there"
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
362
        self.runbzr(('commit', '-m', 'Added there'))
363
        os.unlink('sub/a.txt')
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
364
        os.unlink('sub/c.txt')
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
365
        os.rmdir('sub')
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
366
        os.unlink('b.txt')
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
367
        self.runbzr(('commit', '-m', 'Removed a.txt'))
368
        os.chdir('../b')
369
        print >> file('sub/a.txt', 'ab'), "something"
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
370
        print >> file('b.txt', 'ab'), "something"
371
        print >> file('sub/c.txt', 'ab'), "something"
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
372
        self.runbzr(('commit', '-m', 'Modified a.txt'))
373
        self.runbzr('merge ../a/')
374
        assert os.path.exists('sub/a.txt.THIS')
375
        assert os.path.exists('sub/a.txt.BASE')
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
376
        os.chdir('../a')
377
        self.runbzr('merge ../b/')
378
        assert os.path.exists('sub/a.txt.OTHER')
379
        assert os.path.exists('sub/a.txt.BASE')
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
380
974.1.71 by Aaron Bentley
Added test for pull
381
    def test_pull(self):
382
        """Pull changes from one branch to another."""
383
        os.mkdir('a')
384
        os.chdir('a')
385
386
        self.example_branch()
974.1.79 by Aaron Bentley
Fixed issues with pull not having a default location after branch
387
        self.runbzr('pull', retcode=1)
388
        self.runbzr('missing', retcode=1)
389
        self.runbzr('missing .')
390
        self.runbzr('missing')
391
        self.runbzr('pull')
392
        self.runbzr('pull /', retcode=1)
393
        self.runbzr('pull')
394
974.1.71 by Aaron Bentley
Added test for pull
395
        os.chdir('..')
396
        self.runbzr('branch a b')
397
        os.chdir('b')
974.1.79 by Aaron Bentley
Fixed issues with pull not having a default location after branch
398
        self.runbzr('pull')
1185.8.5 by Aaron Bentley
Fixed non-tree-root bug in branch, revert, merge
399
        os.mkdir('subdir')
400
        self.runbzr('add subdir')
974.1.71 by Aaron Bentley
Added test for pull
401
        self.runbzr('commit -m blah --unchanged')
402
        os.chdir('../a')
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
403
        a = Branch.open('.')
404
        b = Branch.open('../b')
974.1.71 by Aaron Bentley
Added test for pull
405
        assert a.revision_history() == b.revision_history()[:-1]
406
        self.runbzr('pull ../b')
407
        assert a.revision_history() == b.revision_history()
408
        self.runbzr('commit -m blah2 --unchanged')
409
        os.chdir('../b')
410
        self.runbzr('commit -m blah3 --unchanged')
411
        self.runbzr('pull ../a', retcode=1)
1390 by Robert Collins
pair programming worx... merge integration and weave
412
        print "DECIDE IF PULL CAN CONVERGE, blackbox.py"
1391 by Robert Collins
merge from integration
413
        return
974.1.74 by Aaron Bentley
Made pull work after remote branch has merged latest revision
414
        os.chdir('../a')
415
        self.runbzr('merge ../b')
416
        self.runbzr('commit -m blah4 --unchanged')
1185.8.5 by Aaron Bentley
Fixed non-tree-root bug in branch, revert, merge
417
        os.chdir('../b/subdir')
418
        self.runbzr('pull ../../a')
974.1.74 by Aaron Bentley
Made pull work after remote branch has merged latest revision
419
        assert a.revision_history()[-1] == b.revision_history()[-1]
1185.10.7 by Aaron Bentley
Fixed bug where pull throws DivergedBranches if branch is newer than upstream
420
        self.runbzr('commit -m blah5 --unchanged')
421
        self.runbzr('commit -m blah6 --unchanged')
422
        os.chdir('..')
423
        self.runbzr('pull ../a')
424
        os.chdir('../a')
425
        self.runbzr('commit -m blah7 --unchanged')
426
        self.runbzr('merge ../b')
427
        self.runbzr('commit -m blah8 --unchanged')
428
        self.runbzr('pull ../b')
429
        self.runbzr('pull ../b')
1185.12.11 by Aaron Bentley
Made pull only save the parent location if it is unset, or on --remember
430
431
    def test_locations(self):
432
        """Using and remembering different locations"""
433
        os.mkdir('a')
434
        os.chdir('a')
435
        self.runbzr('init')
436
        self.runbzr('commit -m unchanged --unchanged')
1185.12.12 by Aaron Bentley
Made merge use pull location or die if no branch specified.
437
        self.runbzr('pull', retcode=1)
438
        self.runbzr('merge', retcode=1)
1185.12.11 by Aaron Bentley
Made pull only save the parent location if it is unset, or on --remember
439
        self.runbzr('branch . ../b')
440
        os.chdir('../b')
441
        self.runbzr('pull')
442
        self.runbzr('branch . ../c')
443
        self.runbzr('pull ../c')
1185.12.12 by Aaron Bentley
Made merge use pull location or die if no branch specified.
444
        self.runbzr('merge')
1185.12.11 by Aaron Bentley
Made pull only save the parent location if it is unset, or on --remember
445
        os.chdir('../a')
446
        self.runbzr('pull ../b')
447
        self.runbzr('pull')
448
        self.runbzr('pull ../c')
449
        self.runbzr('branch ../c ../d')
450
        shutil.rmtree('../c')
451
        self.runbzr('pull')
452
        os.chdir('../b')
453
        self.runbzr('pull')
454
        os.chdir('../d')
455
        self.runbzr('pull', retcode=1)
456
        self.runbzr('pull ../a --remember')
457
        self.runbzr('pull')
974.1.74 by Aaron Bentley
Made pull work after remote branch has merged latest revision
458
        
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
459
    def test_add_reports(self):
460
        """add command prints the names of added files."""
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
461
        b = Branch.initialize('.')
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
462
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
1185.1.31 by Robert Collins
Change the use of run_bzr to run_bzr_captured in blackbox tests - inspired by David Clymers patch to change run_bzr usage to runbzr
463
        out = self.run_bzr_captured(['add'], retcode = 0)[0]
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
464
        # the ordering is not defined at the moment
1185.1.31 by Robert Collins
Change the use of run_bzr to run_bzr_captured in blackbox tests - inspired by David Clymers patch to change run_bzr usage to runbzr
465
        results = sorted(out.rstrip('\n').split('\n'))
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
466
        self.assertEquals(['added dir',
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
467
                           'added dir'+os.sep+'sub.txt',
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
468
                           'added top.txt',],
469
                          results)
470
1185.3.20 by Martin Pool
- run_bzr_captured also includes logged errors in
471
    def test_unknown_command(self):
472
        """Handling of unknown command."""
473
        out, err = self.run_bzr_captured(['fluffy-badger'],
474
                                         retcode=1)
475
        self.assertEquals(out, '')
476
        err.index('unknown command')
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
477
478
    def test_conflicts(self):
479
        """Handling of merge conflicts"""
480
        os.mkdir('base')
481
        os.chdir('base')
482
        file('hello', 'wb').write("hi world")
483
        file('answer', 'wb').write("42")
484
        self.runbzr('init')
485
        self.runbzr('add')
486
        self.runbzr('commit -m base')
487
        self.runbzr('branch . ../other')
488
        self.runbzr('branch . ../this')
489
        os.chdir('../other')
490
        file('hello', 'wb').write("Hello.")
491
        file('answer', 'wb').write("Is anyone there?")
492
        self.runbzr('commit -m other')
493
        os.chdir('../this')
494
        file('hello', 'wb').write("Hello, world")
495
        self.runbzr('mv answer question')
496
        file('question', 'wb').write("What do you get when you multiply six"
497
                                   "times nine?")
498
        self.runbzr('commit -m this')
499
        self.runbzr('merge ../other')
500
        result = self.runbzr('conflicts', backtick=1)
501
        self.assertEquals(result, "hello\nquestion\n")
1185.14.11 by Aaron Bentley
moved conflict listing into status and stopped monkey-patching
502
        result = self.runbzr('status', backtick=1)
503
        assert "conflicts:\n  hello\n  question\n" in result, result
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
504
        self.runbzr('resolve hello')
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
505
        result = self.runbzr('conflicts', backtick=1)
506
        self.assertEquals(result, "question\n")
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
507
        self.runbzr('commit -m conflicts', retcode=1)
508
        self.runbzr('resolve --all')
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
509
        result = self.runbzr('conflicts', backtick=1)
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
510
        self.runbzr('commit -m conflicts')
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
511
        self.assertEquals(result, "")
1185.3.20 by Martin Pool
- run_bzr_captured also includes logged errors in
512
1092.2.6 by Robert Collins
symlink support updated to work
513
def listdir_sorted(dir):
514
    L = os.listdir(dir)
515
    L.sort()
516
    return L
1185.3.20 by Martin Pool
- run_bzr_captured also includes logged errors in
517
1092.2.12 by Robert Collins
merge from HEAD
518
904 by Martin Pool
- more selftest external-command fixes
519
class OldTests(ExternalBase):
1092.1.39 by Robert Collins
merge from mpool
520
    """old tests moved from ./testbzr."""
521
1102 by Martin Pool
- merge test refactoring from robertc
522
    def test_bzr(self):
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
523
        from os import chdir, mkdir
524
        from os.path import exists
525
904 by Martin Pool
- more selftest external-command fixes
526
        runbzr = self.runbzr
1185.3.26 by Martin Pool
- remove remaining external executions of bzr
527
        capture = self.capture
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
528
        progress = self.log
529
530
        progress("basic branch creation")
904 by Martin Pool
- more selftest external-command fixes
531
        mkdir('branch1')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
532
        chdir('branch1')
898 by Martin Pool
- add new runbzr method for external tests
533
        runbzr('init')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
534
1185.3.25 by Martin Pool
- run blackbox tests in-process
535
        self.assertEquals(capture('root').rstrip(),
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
536
                          os.path.join(self.test_dir, 'branch1'))
537
538
        progress("status of new file")
539
540
        f = file('test.txt', 'wt')
541
        f.write('hello world!\n')
542
        f.close()
543
1185.3.25 by Martin Pool
- run blackbox tests in-process
544
        self.assertEquals(capture('unknowns'), 'test.txt\n')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
545
1185.3.25 by Martin Pool
- run blackbox tests in-process
546
        out = capture("status")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
547
        assert out == 'unknown:\n  test.txt\n'
548
1185.3.25 by Martin Pool
- run blackbox tests in-process
549
        out = capture("status --all")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
550
        assert out == "unknown:\n  test.txt\n"
551
1185.3.25 by Martin Pool
- run blackbox tests in-process
552
        out = capture("status test.txt --all")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
553
        assert out == "unknown:\n  test.txt\n"
554
555
        f = file('test2.txt', 'wt')
556
        f.write('goodbye cruel world...\n')
557
        f.close()
558
1185.3.25 by Martin Pool
- run blackbox tests in-process
559
        out = capture("status test.txt")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
560
        assert out == "unknown:\n  test.txt\n"
561
1185.3.25 by Martin Pool
- run blackbox tests in-process
562
        out = capture("status")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
563
        assert out == ("unknown:\n"
564
                       "  test.txt\n"
565
                       "  test2.txt\n")
566
567
        os.unlink('test2.txt')
568
569
        progress("command aliases")
1185.3.25 by Martin Pool
- run blackbox tests in-process
570
        out = capture("st --all")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
571
        assert out == ("unknown:\n"
572
                       "  test.txt\n")
573
1185.3.25 by Martin Pool
- run blackbox tests in-process
574
        out = capture("stat")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
575
        assert out == ("unknown:\n"
576
                       "  test.txt\n")
577
578
        progress("command help")
898 by Martin Pool
- add new runbzr method for external tests
579
        runbzr("help st")
580
        runbzr("help")
581
        runbzr("help commands")
582
        runbzr("help slartibartfast", 1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
583
1185.3.25 by Martin Pool
- run blackbox tests in-process
584
        out = capture("help ci")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
585
        out.index('aliases: ')
586
587
        progress("can't rename unversioned file")
898 by Martin Pool
- add new runbzr method for external tests
588
        runbzr("rename test.txt new-test.txt", 1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
589
590
        progress("adding a file")
591
898 by Martin Pool
- add new runbzr method for external tests
592
        runbzr("add test.txt")
1185.3.25 by Martin Pool
- run blackbox tests in-process
593
        assert capture("unknowns") == ''
594
        assert capture("status --all") == ("added:\n"
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
595
                                                "  test.txt\n")
596
597
        progress("rename newly-added file")
898 by Martin Pool
- add new runbzr method for external tests
598
        runbzr("rename test.txt hello.txt")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
599
        assert os.path.exists("hello.txt")
600
        assert not os.path.exists("test.txt")
601
1185.3.25 by Martin Pool
- run blackbox tests in-process
602
        assert capture("revno") == '0\n'
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
603
604
        progress("add first revision")
904 by Martin Pool
- more selftest external-command fixes
605
        runbzr(['commit', '-m', 'add first revision'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
606
607
        progress("more complex renames")
608
        os.mkdir("sub1")
898 by Martin Pool
- add new runbzr method for external tests
609
        runbzr("rename hello.txt sub1", 1)
610
        runbzr("rename hello.txt sub1/hello.txt", 1)
611
        runbzr("move hello.txt sub1", 1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
612
898 by Martin Pool
- add new runbzr method for external tests
613
        runbzr("add sub1")
614
        runbzr("rename sub1 sub2")
615
        runbzr("move hello.txt sub2")
1185.3.25 by Martin Pool
- run blackbox tests in-process
616
        assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
617
618
        assert exists("sub2")
619
        assert exists("sub2/hello.txt")
620
        assert not exists("sub1")
621
        assert not exists("hello.txt")
622
898 by Martin Pool
- add new runbzr method for external tests
623
        runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
624
625
        mkdir("sub1")
898 by Martin Pool
- add new runbzr method for external tests
626
        runbzr('add sub1')
627
        runbzr('move sub2/hello.txt sub1')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
628
        assert not exists('sub2/hello.txt')
629
        assert exists('sub1/hello.txt')
898 by Martin Pool
- add new runbzr method for external tests
630
        runbzr('move sub2 sub1')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
631
        assert not exists('sub2')
632
        assert exists('sub1/sub2')
633
898 by Martin Pool
- add new runbzr method for external tests
634
        runbzr(['commit', '-m', 'rename nested subdirectories'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
635
636
        chdir('sub1/sub2')
1185.3.25 by Martin Pool
- run blackbox tests in-process
637
        self.assertEquals(capture('root')[:-1],
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
638
                          os.path.join(self.test_dir, 'branch1'))
898 by Martin Pool
- add new runbzr method for external tests
639
        runbzr('move ../hello.txt .')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
640
        assert exists('./hello.txt')
1185.3.25 by Martin Pool
- run blackbox tests in-process
641
        self.assertEquals(capture('relpath hello.txt'),
642
                          os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
643
        assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
898 by Martin Pool
- add new runbzr method for external tests
644
        runbzr(['commit', '-m', 'move to parent directory'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
645
        chdir('..')
1185.3.25 by Martin Pool
- run blackbox tests in-process
646
        assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
647
898 by Martin Pool
- add new runbzr method for external tests
648
        runbzr('move sub2/hello.txt .')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
649
        assert exists('hello.txt')
650
651
        f = file('hello.txt', 'wt')
652
        f.write('some nice new content\n')
653
        f.close()
654
655
        f = file('msg.tmp', 'wt')
656
        f.write('this is my new commit\n')
657
        f.close()
658
898 by Martin Pool
- add new runbzr method for external tests
659
        runbzr('commit -F msg.tmp')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
660
1185.3.25 by Martin Pool
- run blackbox tests in-process
661
        assert capture('revno') == '5\n'
898 by Martin Pool
- add new runbzr method for external tests
662
        runbzr('export -r 5 export-5.tmp')
663
        runbzr('export export.tmp')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
664
898 by Martin Pool
- add new runbzr method for external tests
665
        runbzr('log')
666
        runbzr('log -v')
909.1.5 by Aaron Bentley
Fixed log -v (mostly)
667
        runbzr('log -v --forward')
668
        runbzr('log -m', retcode=1)
1185.3.25 by Martin Pool
- run blackbox tests in-process
669
        log_out = capture('log -m commit')
909.1.5 by Aaron Bentley
Fixed log -v (mostly)
670
        assert "this is my new commit" in log_out
671
        assert "rename nested" not in log_out
672
        assert 'revision-id' not in log_out
1185.3.25 by Martin Pool
- run blackbox tests in-process
673
        assert 'revision-id' in capture('log --show-ids -m commit')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
674
675
676
        progress("file with spaces in name")
677
        mkdir('sub directory')
678
        file('sub directory/file with spaces ', 'wt').write('see how this works\n')
898 by Martin Pool
- add new runbzr method for external tests
679
        runbzr('add .')
680
        runbzr('diff')
681
        runbzr('commit -m add-spaces')
682
        runbzr('check')
683
684
        runbzr('log')
685
        runbzr('log --forward')
686
687
        runbzr('info')
1092.1.35 by Robert Collins
merge from mpool up to rev 1110
688
1092.2.6 by Robert Collins
symlink support updated to work
689
        if has_symlinks():
690
            progress("symlinks")
691
            mkdir('symlinks')
692
            chdir('symlinks')
693
            runbzr('init')
694
            os.symlink("NOWHERE1", "link1")
695
            runbzr('add link1')
1092.3.4 by Robert Collins
update symlink branch to integration
696
            assert self.capture('unknowns') == ''
1092.2.6 by Robert Collins
symlink support updated to work
697
            runbzr(['commit', '-m', '1: added symlink link1'])
698
    
699
            mkdir('d1')
700
            runbzr('add d1')
1092.3.4 by Robert Collins
update symlink branch to integration
701
            assert self.capture('unknowns') == ''
1092.2.6 by Robert Collins
symlink support updated to work
702
            os.symlink("NOWHERE2", "d1/link2")
1092.3.4 by Robert Collins
update symlink branch to integration
703
            assert self.capture('unknowns') == 'd1/link2\n'
1092.2.6 by Robert Collins
symlink support updated to work
704
            # is d1/link2 found when adding d1
705
            runbzr('add d1')
1092.3.4 by Robert Collins
update symlink branch to integration
706
            assert self.capture('unknowns') == ''
1092.2.6 by Robert Collins
symlink support updated to work
707
            os.symlink("NOWHERE3", "d1/link3")
1092.3.4 by Robert Collins
update symlink branch to integration
708
            assert self.capture('unknowns') == 'd1/link3\n'
1092.2.6 by Robert Collins
symlink support updated to work
709
            runbzr(['commit', '-m', '2: added dir, symlink'])
710
    
711
            runbzr('rename d1 d2')
712
            runbzr('move d2/link2 .')
713
            runbzr('move link1 d2')
714
            assert os.readlink("./link2") == "NOWHERE2"
715
            assert os.readlink("d2/link1") == "NOWHERE1"
716
            runbzr('add d2/link3')
717
            runbzr('diff')
718
            runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
719
    
720
            os.unlink("link2")
721
            os.symlink("TARGET 2", "link2")
722
            os.unlink("d2/link1")
723
            os.symlink("TARGET 1", "d2/link1")
724
            runbzr('diff')
1092.3.4 by Robert Collins
update symlink branch to integration
725
            assert self.capture("relpath d2/link1") == "d2/link1\n"
1092.2.6 by Robert Collins
symlink support updated to work
726
            runbzr(['commit', '-m', '4: retarget of two links'])
727
    
728
            runbzr('remove d2/link1')
1092.3.4 by Robert Collins
update symlink branch to integration
729
            assert self.capture('unknowns') == 'd2/link1\n'
1092.2.20 by Robert Collins
symlink and weaves, whaddya know
730
            runbzr(['commit', '-m', '5: remove d2/link1'])
1092.2.6 by Robert Collins
symlink support updated to work
731
    
732
            os.mkdir("d1")
733
            runbzr('add d1')
734
            runbzr('rename d2/link3 d1/link3new')
1092.3.4 by Robert Collins
update symlink branch to integration
735
            assert self.capture('unknowns') == 'd2/link1\n'
1092.2.6 by Robert Collins
symlink support updated to work
736
            runbzr(['commit', '-m', '6: remove d2/link1, move/rename link3'])
737
            
738
            runbzr(['check'])
739
            
740
            runbzr(['export', '-r', '1', 'exp1.tmp'])
741
            chdir("exp1.tmp")
742
            assert listdir_sorted(".") == [ "link1" ]
743
            assert os.readlink("link1") == "NOWHERE1"
744
            chdir("..")
745
            
746
            runbzr(['export', '-r', '2', 'exp2.tmp'])
747
            chdir("exp2.tmp")
748
            assert listdir_sorted(".") == [ "d1", "link1" ]
749
            chdir("..")
750
            
751
            runbzr(['export', '-r', '3', 'exp3.tmp'])
752
            chdir("exp3.tmp")
753
            assert listdir_sorted(".") == [ "d2", "link2" ]
754
            assert listdir_sorted("d2") == [ "link1", "link3" ]
755
            assert os.readlink("d2/link1") == "NOWHERE1"
756
            assert os.readlink("link2")    == "NOWHERE2"
757
            chdir("..")
758
            
759
            runbzr(['export', '-r', '4', 'exp4.tmp'])
760
            chdir("exp4.tmp")
761
            assert listdir_sorted(".") == [ "d2", "link2" ]
762
            assert os.readlink("d2/link1") == "TARGET 1"
763
            assert os.readlink("link2")    == "TARGET 2"
764
            assert listdir_sorted("d2") == [ "link1", "link3" ]
765
            chdir("..")
766
            
767
            runbzr(['export', '-r', '5', 'exp5.tmp'])
768
            chdir("exp5.tmp")
769
            assert listdir_sorted(".") == [ "d2", "link2" ]
770
            assert os.path.islink("link2")
771
            assert listdir_sorted("d2")== [ "link3" ]
772
            chdir("..")
773
            
774
            runbzr(['export', '-r', '6', 'exp6.tmp'])
775
            chdir("exp6.tmp")
776
            assert listdir_sorted(".") == [ "d1", "d2", "link2" ]
777
            assert listdir_sorted("d1") == [ "link3new" ]
778
            assert listdir_sorted("d2") == []
779
            assert os.readlink("d1/link3new") == "NOWHERE3"
780
            chdir("..")
781
        else:
782
            progress("skipping symlink tests")
1400.1.1 by Robert Collins
implement a basic test for the ui branch command from http servers
783
784
785
class HttpTests(TestCaseWithWebserver):
786
    """Test bzr ui commands against remote branches."""
787
788
    def test_branch(self):
789
        os.mkdir('from')
790
        branch = Branch.initialize('from')
791
        branch.commit('empty commit for nonsense', allow_pointless=True)
792
        url = self.get_remote_url('from')
793
        self.run_bzr('branch', url, 'to')
794
        branch = Branch.open('to')
795
        self.assertEqual(1, len(branch.revision_history()))