~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
1185.46.9 by Aaron Bentley
Added verbose option to bzr add, to list all ignored files.
18
# Mr. Smoketoomuch: I'm sorry?
19
# Mr. Bounder: You'd better cut down a little then.
20
# Mr. Smoketoomuch: Oh, I see! Smoke too much so I'd better cut down a little
21
#                   then!
720 by Martin Pool
- start moving external tests into the testsuite framework
22
23
"""Black-box tests for bzr.
24
25
These check that it behaves properly when it's invoked through the regular
1403 by Robert Collins
merge from martin
26
command-line interface. This doesn't actually run a new interpreter but 
1393.1.45 by Martin Pool
doc
27
rather starts again from the run_bzr function.
720 by Martin Pool
- start moving external tests into the testsuite framework
28
"""
29
1393.1.45 by Martin Pool
doc
30
1185.33.14 by Martin Pool
doc
31
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
32
# Note: Please don't add new tests here, it's too big and bulky.  Instead add
1512 by Robert Collins
Merge from Martin. Adjust check to work with HTTP again.
33
# them into small suites in bzrlib.tests.blackbox.test_FOO for the particular
34
# UI command/aspect that is being tested.
1185.33.14 by Martin Pool
doc
35
36
1185.1.25 by Robert Collins
merge David Clymer's patch for TestCaseInTestDir.runcmd
37
from cStringIO import StringIO
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
38
import os
1185.16.43 by Martin Pool
- clean up handling of option objects
39
import re
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
40
import sys
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
41
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
42
import bzrlib
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
43
from bzrlib.branch import Branch
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
44
import bzrlib.bzrdir as bzrdir
1393.3.3 by Jelmer Vernooij
Add test for empty commit messages.
45
from bzrlib.errors import BzrCommandError
1692.3.5 by Robert Collins
Merge integration, fixing test failure in test_too_much due to terminal width changing.
46
from bzrlib.osutils import (
47
    has_symlinks,
48
    pathjoin,
49
    rmtree,
50
    terminal_width,
51
    )
1185.31.25 by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py
52
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
1530.1.7 by Robert Collins
merge integration.
53
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
1513 by Robert Collins
Blackbox tests are maintained within the bzrlib.tests.blackbox directory.
54
from bzrlib.tests.blackbox import ExternalBase
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
55
from bzrlib.workingtree import WorkingTree
1142 by Martin Pool
- remove dead code from blackbox tests (pychecker)
56
1185.65.29 by Robert Collins
Implement final review suggestions.
57
1102 by Martin Pool
- merge test refactoring from robertc
58
class TestCommands(ExternalBase):
59
60
    def test_whoami(self):
732 by Martin Pool
- move more tests into bzr selftest
61
        # this should always identify something, if only "john@localhost"
898 by Martin Pool
- add new runbzr method for external tests
62
        self.runbzr("whoami")
63
        self.runbzr("whoami --email")
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
64
65
        self.assertEquals(self.runbzr("whoami --email",
66
                                      backtick=True).count('@'), 1)
67
        
1102 by Martin Pool
- merge test refactoring from robertc
68
    def test_whoami_branch(self):
69
        """branch specific user identity works."""
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
70
        self.runbzr('init')
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
71
        b = bzrlib.branch.Branch.open('.')
72
        b.control_files.put_utf8('email', 'Branch Identity <branch@identi.ty>')
1185.6.1 by John Arbash Meinel
Updated the whomai test to handle BZREMAIL
73
        bzr_email = os.environ.get('BZREMAIL')
74
        if bzr_email is not None:
75
            del os.environ['BZREMAIL']
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
76
        whoami = self.runbzr("whoami",backtick=True)
77
        whoami_email = self.runbzr("whoami --email",backtick=True)
78
        self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
79
        self.assertTrue(whoami_email.startswith('branch@identi.ty'))
1185.6.1 by John Arbash Meinel
Updated the whomai test to handle BZREMAIL
80
        # Verify that the environment variable overrides the value 
81
        # in the file
82
        os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
83
        whoami = self.runbzr("whoami",backtick=True)
84
        whoami_email = self.runbzr("whoami --email",backtick=True)
85
        self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
86
        self.assertTrue(whoami_email.startswith('other@environ.ment'))
87
        if bzr_email is not None:
88
            os.environ['BZREMAIL'] = bzr_email
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
89
1185.35.14 by Aaron Bentley
Implemented nick command
90
    def test_nick_command(self):
91
        """bzr nick for viewing, setting nicknames"""
92
        os.mkdir('me.dev')
93
        os.chdir('me.dev')
94
        self.runbzr('init')
95
        nick = self.runbzr("nick",backtick=True)
96
        self.assertEqual(nick, 'me.dev\n')
97
        nick = self.runbzr("nick moo")
98
        nick = self.runbzr("nick",backtick=True)
99
        self.assertEqual(nick, 'moo\n')
100
1102 by Martin Pool
- merge test refactoring from robertc
101
    def test_invalid_commands(self):
1185.35.21 by Aaron Bentley
Changed error status to 3
102
        self.runbzr("pants", retcode=3)
103
        self.runbzr("--pants off", retcode=3)
104
        self.runbzr("diff --message foo", retcode=3)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
105
1102 by Martin Pool
- merge test refactoring from robertc
106
    def test_ignore_patterns(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
107
        self.runbzr('init')
1508.1.6 by Robert Collins
Move Branch.unknowns() to WorkingTree.
108
        self.assertEquals(self.capture('unknowns'), '')
906 by Martin Pool
- split out black-box ignore commands
109
110
        file('foo.tmp', 'wt').write('tmp files are ignored')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
111
        self.assertEquals(self.capture('unknowns'), '')
906 by Martin Pool
- split out black-box ignore commands
112
113
        file('foo.c', 'wt').write('int main() {}')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
114
        self.assertEquals(self.capture('unknowns'), 'foo.c\n')
906 by Martin Pool
- split out black-box ignore commands
115
116
        self.runbzr(['add', 'foo.c'])
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
117
        self.assertEquals(self.capture('unknowns'), '')
906 by Martin Pool
- split out black-box ignore commands
118
119
        # 'ignore' works when creating the .bzignore file
120
        file('foo.blah', 'wt').write('blah')
1508.1.6 by Robert Collins
Move Branch.unknowns() to WorkingTree.
121
        self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
906 by Martin Pool
- split out black-box ignore commands
122
        self.runbzr('ignore *.blah')
1508.1.6 by Robert Collins
Move Branch.unknowns() to WorkingTree.
123
        self.assertEquals(self.capture('unknowns'), '')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
124
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
906 by Martin Pool
- split out black-box ignore commands
125
126
        # 'ignore' works when then .bzrignore file already exists
127
        file('garh', 'wt').write('garh')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
128
        self.assertEquals(self.capture('unknowns'), 'garh\n')
906 by Martin Pool
- split out black-box ignore commands
129
        self.runbzr('ignore garh')
1508.1.6 by Robert Collins
Move Branch.unknowns() to WorkingTree.
130
        self.assertEquals(self.capture('unknowns'), '')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
131
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
1102 by Martin Pool
- merge test refactoring from robertc
132
1185.1.8 by Robert Collins
David Clymers patch to use rename rather than mv for two argument non-directory target bzr mv calls.
133
    def test_mv_modes(self):
1102 by Martin Pool
- merge test refactoring from robertc
134
        """Test two modes of operation for mv"""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
135
        self.runbzr('init')
1102 by Martin Pool
- merge test refactoring from robertc
136
        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
137
        self.run_bzr_captured(['add', self.test_dir])
138
        self.run_bzr_captured(['mv', 'a', 'b'])
139
        self.run_bzr_captured(['mv', 'b', 'subdir'])
140
        self.run_bzr_captured(['mv', 'subdir/b', 'a'])
141
        self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
142
        self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
1102 by Martin Pool
- merge test refactoring from robertc
143
144
    def test_main_version(self):
145
        """Check output from version command and master option is reasonable"""
146
        # output is intentionally passed through to stdout so that we
147
        # can see the version being tested
148
        output = self.runbzr('version', backtick=1)
149
        self.log('bzr version output:')
150
        self.log(output)
151
        self.assert_(output.startswith('bzr (bazaar-ng) '))
152
        self.assertNotEqual(output.index('Canonical'), -1)
153
        # make sure --version is consistent
154
        tmp_output = self.runbzr('--version', backtick=1)
155
        self.log('bzr --version output:')
156
        self.log(tmp_output)
157
        self.assertEquals(output, tmp_output)
906 by Martin Pool
- split out black-box ignore commands
158
1092.1.39 by Robert Collins
merge from mpool
159
    def example_branch(test):
160
        test.runbzr('init')
161
        file('hello', 'wt').write('foo')
162
        test.runbzr('add hello')
163
        test.runbzr('commit -m setup hello')
164
        file('goodbye', 'wt').write('baz')
165
        test.runbzr('add goodbye')
166
        test.runbzr('commit -m setup goodbye')
167
1185.12.1 by Aaron Bentley
Fixed export
168
    def test_export(self):
169
        os.mkdir('branch')
170
        os.chdir('branch')
171
        self.example_branch()
172
        self.runbzr('export ../latest')
173
        self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
174
        self.runbzr('export ../first -r 1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
175
        self.assert_(not os.path.exists('../first/goodbye'))
1185.12.1 by Aaron Bentley
Fixed export
176
        self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
177
        self.runbzr('export ../first.gz -r 1')
178
        self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
179
        self.runbzr('export ../first.bz2 -r 1')
180
        self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
1185.31.13 by John Arbash Meinel
Updated the test to also test zip exports. Fixed some small bugs exposed by test suite.
181
182
        from tarfile import TarFile
1185.12.1 by Aaron Bentley
Fixed export
183
        self.runbzr('export ../first.tar -r 1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
184
        self.assert_(os.path.isfile('../first.tar'))
1185.12.1 by Aaron Bentley
Fixed export
185
        tf = TarFile('../first.tar')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
186
        self.assert_('first/hello' in tf.getnames(), tf.getnames())
1185.12.1 by Aaron Bentley
Fixed export
187
        self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
188
        self.runbzr('export ../first.tar.gz -r 1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
189
        self.assert_(os.path.isfile('../first.tar.gz'))
1185.12.1 by Aaron Bentley
Fixed export
190
        self.runbzr('export ../first.tbz2 -r 1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
191
        self.assert_(os.path.isfile('../first.tbz2'))
1185.12.1 by Aaron Bentley
Fixed export
192
        self.runbzr('export ../first.tar.bz2 -r 1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
193
        self.assert_(os.path.isfile('../first.tar.bz2'))
1185.12.1 by Aaron Bentley
Fixed export
194
        self.runbzr('export ../first.tar.tbz2 -r 1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
195
        self.assert_(os.path.isfile('../first.tar.tbz2'))
1185.31.13 by John Arbash Meinel
Updated the test to also test zip exports. Fixed some small bugs exposed by test suite.
196
1185.12.1 by Aaron Bentley
Fixed export
197
        from bz2 import BZ2File
198
        tf = TarFile('../first.tar.tbz2', 
199
                     fileobj=BZ2File('../first.tar.tbz2', 'r'))
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
200
        self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
1185.12.1 by Aaron Bentley
Fixed export
201
        self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
202
        self.runbzr('export ../first2.tar -r 1 --root pizza')
203
        tf = TarFile('../first2.tar')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
204
        self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
1185.12.1 by Aaron Bentley
Fixed export
205
1185.31.13 by John Arbash Meinel
Updated the test to also test zip exports. Fixed some small bugs exposed by test suite.
206
        from zipfile import ZipFile
207
        self.runbzr('export ../first.zip -r 1')
208
        self.failUnlessExists('../first.zip')
209
        zf = ZipFile('../first.zip')
210
        self.assert_('first/hello' in zf.namelist(), zf.namelist())
211
        self.assertEqual(zf.read('first/hello'), 'foo')
212
213
        self.runbzr('export ../first2.zip -r 1 --root pizza')
214
        zf = ZipFile('../first2.zip')
215
        self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
216
        
217
        self.runbzr('export ../first-zip --format=zip -r 1')
218
        zf = ZipFile('../first-zip')
219
        self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
220
1185.33.33 by Martin Pool
[patch] add 'bzr inventory --kind directory'; remove 'bzr directories'
221
    def test_inventory(self):
222
        bzr = self.runbzr
223
        def output_equals(value, *args):
224
            out = self.runbzr(['inventory'] + list(args), backtick=True)
225
            self.assertEquals(out, value)
226
227
        bzr('init')
228
        open('a', 'wb').write('hello\n')
229
        os.mkdir('b')
230
231
        bzr('add a b')
232
        bzr('commit -m add')
233
234
        output_equals('a\n', '--kind', 'file')
235
        output_equals('b\n', '--kind', 'directory')        
236
1551.6.36 by Aaron Bentley
Revert --debris/--detritus changes
237
    def test_ls(self):
238
        """Test the abilities of 'bzr ls'"""
239
        bzr = self.runbzr
240
        def bzrout(*args, **kwargs):
241
            kwargs['backtick'] = True
242
            return self.runbzr(*args, **kwargs)
243
244
        def ls_equals(value, *args):
245
            out = self.runbzr(['ls'] + list(args), backtick=True)
246
            self.assertEquals(out, value)
247
248
        bzr('init')
249
        open('a', 'wb').write('hello\n')
250
251
        # Can't supply both
252
        bzr('ls --verbose --null', retcode=3)
253
254
        ls_equals('a\n')
255
        ls_equals('?        a\n', '--verbose')
256
        ls_equals('a\n', '--unknown')
257
        ls_equals('', '--ignored')
258
        ls_equals('', '--versioned')
259
        ls_equals('a\n', '--unknown', '--ignored', '--versioned')
260
        ls_equals('', '--ignored', '--versioned')
261
        ls_equals('a\0', '--null')
262
263
        bzr('add a')
264
        ls_equals('V        a\n', '--verbose')
265
        bzr('commit -m add')
266
        
267
        os.mkdir('subdir')
268
        ls_equals('V        a\n'
269
                  '?        subdir/\n'
270
                  , '--verbose')
271
        open('subdir/b', 'wb').write('b\n')
272
        bzr('add')
273
        ls_equals('V        a\n'
274
                  'V        subdir/\n'
275
                  'V        subdir/b\n'
276
                  , '--verbose')
277
        bzr('commit -m subdir')
278
279
        ls_equals('a\n'
280
                  'subdir\n'
281
                  , '--non-recursive')
282
283
        ls_equals('V        a\n'
284
                  'V        subdir/\n'
285
                  , '--verbose', '--non-recursive')
286
287
        # Check what happens in a sub-directory
288
        os.chdir('subdir')
289
        ls_equals('b\n')
290
        ls_equals('b\0'
291
                  , '--null')
292
        ls_equals('a\n'
293
                  'subdir\n'
294
                  'subdir/b\n'
295
                  , '--from-root')
296
        ls_equals('a\0'
297
                  'subdir\0'
298
                  'subdir/b\0'
299
                  , '--from-root', '--null')
300
        ls_equals('a\n'
301
                  'subdir\n'
302
                  , '--from-root', '--non-recursive')
303
304
        os.chdir('..')
305
306
        # Check what happens when we supply a specific revision
307
        ls_equals('a\n', '--revision', '1')
308
        ls_equals('V        a\n'
309
                  , '--verbose', '--revision', '1')
310
311
        os.chdir('subdir')
312
        ls_equals('', '--revision', '1')
313
314
        # Now try to do ignored files.
315
        os.chdir('..')
316
        open('blah.py', 'wb').write('unknown\n')
317
        open('blah.pyo', 'wb').write('ignored\n')
318
        ls_equals('a\n'
319
                  'blah.py\n'
320
                  'blah.pyo\n'
321
                  'subdir\n'
322
                  'subdir/b\n')
323
        ls_equals('V        a\n'
324
                  '?        blah.py\n'
325
                  'I        blah.pyo\n'
326
                  'V        subdir/\n'
327
                  'V        subdir/b\n'
328
                  , '--verbose')
329
        ls_equals('blah.pyo\n'
330
                  , '--ignored')
331
        ls_equals('blah.py\n'
332
                  , '--unknown')
333
        ls_equals('a\n'
334
                  'subdir\n'
335
                  'subdir/b\n'
336
                  , '--versioned')
337
1185.65.4 by Aaron Bentley
Fixed cat command
338
    def test_cat(self):
339
        self.runbzr('init')
340
        file("myfile", "wb").write("My contents\n")
341
        self.runbzr('add')
342
        self.runbzr('commit -m myfile')
343
        self.run_bzr_captured('cat -r 1 myfile'.split(' '))
344
1185.32.2 by John Arbash Meinel
Refactor pull --verbose into a log.py function, add tests.
345
    def test_pull_verbose(self):
346
        """Pull changes from one branch to another and watch the output."""
347
348
        os.mkdir('a')
349
        os.chdir('a')
350
351
        bzr = self.runbzr
352
        self.example_branch()
353
354
        os.chdir('..')
355
        bzr('branch a b')
356
        os.chdir('b')
357
        open('b', 'wb').write('else\n')
358
        bzr('add b')
359
        bzr(['commit', '-m', 'added b'])
360
361
        os.chdir('../a')
362
        out = bzr('pull --verbose ../b', backtick=True)
363
        self.failIfEqual(out.find('Added Revisions:'), -1)
364
        self.failIfEqual(out.find('message:\n  added b'), -1)
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
365
        self.failIfEqual(out.find('added b'), -1)
1185.32.2 by John Arbash Meinel
Refactor pull --verbose into a log.py function, add tests.
366
1185.32.4 by John Arbash Meinel
[merge] up-to-date against bzr.dev
367
        # Check that --overwrite --verbose prints out the removed entries
1185.32.2 by John Arbash Meinel
Refactor pull --verbose into a log.py function, add tests.
368
        bzr('commit -m foo --unchanged')
369
        os.chdir('../b')
370
        bzr('commit -m baz --unchanged')
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
371
        bzr('pull ../a', retcode=3)
1185.32.4 by John Arbash Meinel
[merge] up-to-date against bzr.dev
372
        out = bzr('pull --overwrite --verbose ../a', backtick=1)
1185.32.2 by John Arbash Meinel
Refactor pull --verbose into a log.py function, add tests.
373
374
        remove_loc = out.find('Removed Revisions:')
375
        self.failIfEqual(remove_loc, -1)
376
        added_loc = out.find('Added Revisions:')
377
        self.failIfEqual(added_loc, -1)
378
379
        removed_message = out.find('message:\n  baz')
380
        self.failIfEqual(removed_message, -1)
381
        self.failUnless(remove_loc < removed_message < added_loc)
382
383
        added_message = out.find('message:\n  foo')
384
        self.failIfEqual(added_message, -1)
385
        self.failUnless(added_loc < added_message)
386
        
1185.12.11 by Aaron Bentley
Made pull only save the parent location if it is unset, or on --remember
387
    def test_locations(self):
388
        """Using and remembering different locations"""
389
        os.mkdir('a')
390
        os.chdir('a')
391
        self.runbzr('init')
392
        self.runbzr('commit -m unchanged --unchanged')
1185.35.21 by Aaron Bentley
Changed error status to 3
393
        self.runbzr('pull', retcode=3)
394
        self.runbzr('merge', retcode=3)
1185.12.11 by Aaron Bentley
Made pull only save the parent location if it is unset, or on --remember
395
        self.runbzr('branch . ../b')
396
        os.chdir('../b')
397
        self.runbzr('pull')
398
        self.runbzr('branch . ../c')
399
        self.runbzr('pull ../c')
1185.12.12 by Aaron Bentley
Made merge use pull location or die if no branch specified.
400
        self.runbzr('merge')
1185.12.11 by Aaron Bentley
Made pull only save the parent location if it is unset, or on --remember
401
        os.chdir('../a')
402
        self.runbzr('pull ../b')
403
        self.runbzr('pull')
404
        self.runbzr('pull ../c')
405
        self.runbzr('branch ../c ../d')
1692.7.6 by Martin Pool
[patch] force deletion of trees containing readonly files (alexander)
406
        rmtree('../c')
1185.12.11 by Aaron Bentley
Made pull only save the parent location if it is unset, or on --remember
407
        self.runbzr('pull')
408
        os.chdir('../b')
409
        self.runbzr('pull')
410
        os.chdir('../d')
1185.35.21 by Aaron Bentley
Changed error status to 3
411
        self.runbzr('pull', retcode=3)
1185.12.11 by Aaron Bentley
Made pull only save the parent location if it is unset, or on --remember
412
        self.runbzr('pull ../a --remember')
413
        self.runbzr('pull')
974.1.74 by Aaron Bentley
Made pull work after remote branch has merged latest revision
414
        
1185.3.20 by Martin Pool
- run_bzr_captured also includes logged errors in
415
    def test_unknown_command(self):
416
        """Handling of unknown command."""
417
        out, err = self.run_bzr_captured(['fluffy-badger'],
1185.35.21 by Aaron Bentley
Changed error status to 3
418
                                         retcode=3)
1185.3.20 by Martin Pool
- run_bzr_captured also includes logged errors in
419
        self.assertEquals(out, '')
420
        err.index('unknown command')
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
421
1185.35.4 by Aaron Bentley
Implemented remerge
422
    def create_conflicts(self):
423
        """Create a conflicted tree"""
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
424
        os.mkdir('base')
425
        os.chdir('base')
426
        file('hello', 'wb').write("hi world")
427
        file('answer', 'wb').write("42")
428
        self.runbzr('init')
429
        self.runbzr('add')
430
        self.runbzr('commit -m base')
431
        self.runbzr('branch . ../other')
432
        self.runbzr('branch . ../this')
433
        os.chdir('../other')
434
        file('hello', 'wb').write("Hello.")
435
        file('answer', 'wb').write("Is anyone there?")
436
        self.runbzr('commit -m other')
437
        os.chdir('../this')
438
        file('hello', 'wb').write("Hello, world")
439
        self.runbzr('mv answer question')
440
        file('question', 'wb').write("What do you get when you multiply six"
441
                                   "times nine?")
442
        self.runbzr('commit -m this')
1185.35.4 by Aaron Bentley
Implemented remerge
443
1185.65.6 by Aaron Bentley
Fixed inner merges in status
444
    def test_status(self):
445
        os.mkdir('branch1')
446
        os.chdir('branch1')
447
        self.runbzr('init')
448
        self.runbzr('commit --unchanged --message f')
449
        self.runbzr('branch . ../branch2')
450
        self.runbzr('branch . ../branch3')
451
        self.runbzr('commit --unchanged --message peter')
452
        os.chdir('../branch2')
453
        self.runbzr('merge ../branch1')
454
        self.runbzr('commit --unchanged --message pumpkin')
455
        os.chdir('../branch3')
456
        self.runbzr('merge ../branch2')
457
        message = self.capture('status')
458
1185.35.4 by Aaron Bentley
Implemented remerge
459
460
    def test_conflicts(self):
461
        """Handling of merge conflicts"""
462
        self.create_conflicts()
1476 by Robert Collins
Merge now has a retcode of 1 when conflicts occur. (Robert Collins)
463
        self.runbzr('merge ../other --show-base', retcode=1)
1185.18.1 by Aaron Bentley
Added --show-base to merge
464
        conflict_text = file('hello').read()
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
465
        self.assert_('<<<<<<<' in conflict_text)
466
        self.assert_('>>>>>>>' in conflict_text)
467
        self.assert_('=======' in conflict_text)
468
        self.assert_('|||||||' in conflict_text)
469
        self.assert_('hi world' in conflict_text)
1185.18.1 by Aaron Bentley
Added --show-base to merge
470
        self.runbzr('revert')
471
        self.runbzr('resolve --all')
1476 by Robert Collins
Merge now has a retcode of 1 when conflicts occur. (Robert Collins)
472
        self.runbzr('merge ../other', retcode=1)
1185.18.1 by Aaron Bentley
Added --show-base to merge
473
        conflict_text = file('hello').read()
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
474
        self.assert_('|||||||' not in conflict_text)
475
        self.assert_('hi world' not in conflict_text)
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
476
        result = self.runbzr('conflicts', backtick=1)
1534.10.9 by Aaron Bentley
Switched display functions to conflict_lines
477
        self.assertEquals(result, "Text conflict in hello\nText conflict in"
478
                                  " question\n")
1185.14.11 by Aaron Bentley
moved conflict listing into status and stopped monkey-patching
479
        result = self.runbzr('status', backtick=1)
1534.10.9 by Aaron Bentley
Switched display functions to conflict_lines
480
        self.assert_("conflicts:\n  Text conflict in hello\n"
481
                     "  Text conflict in question\n" in result, result)
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
482
        self.runbzr('resolve hello')
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
483
        result = self.runbzr('conflicts', backtick=1)
1534.10.9 by Aaron Bentley
Switched display functions to conflict_lines
484
        self.assertEquals(result, "Text conflict in question\n")
1185.35.21 by Aaron Bentley
Changed error status to 3
485
        self.runbzr('commit -m conflicts', retcode=3)
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
486
        self.runbzr('resolve --all')
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
487
        result = self.runbzr('conflicts', backtick=1)
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
488
        self.runbzr('commit -m conflicts')
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
489
        self.assertEquals(result, "")
1185.3.20 by Martin Pool
- run_bzr_captured also includes logged errors in
490
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
491
    def test_push(self):
492
        # create a source branch
493
        os.mkdir('my-branch')
494
        os.chdir('my-branch')
495
        self.example_branch()
496
497
        # with no push target, fail
1185.35.21 by Aaron Bentley
Changed error status to 3
498
        self.runbzr('push', retcode=3)
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
499
        # with an explicit target work
500
        self.runbzr('push ../output-branch')
501
        # with an implicit target work
502
        self.runbzr('push')
503
        # nothing missing
504
        self.runbzr('missing ../output-branch')
505
        # advance this branch
506
        self.runbzr('commit --unchanged -m unchanged')
507
508
        os.chdir('../output-branch')
1185.50.6 by John Arbash Meinel
Fixed a broken test from my 'push updates local working tree' fix
509
        # There is no longer a difference as long as we have
510
        # access to the working tree
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
511
        self.runbzr('diff')
1185.50.6 by John Arbash Meinel
Fixed a broken test from my 'push updates local working tree' fix
512
513
        # But we should be missing a revision
514
        self.runbzr('missing ../my-branch', retcode=1)
515
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
516
        # diverge the branches
517
        self.runbzr('commit --unchanged -m unchanged')
518
        os.chdir('../my-branch')
519
        # cannot push now
1185.35.21 by Aaron Bentley
Changed error status to 3
520
        self.runbzr('push', retcode=3)
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
521
        # and there are difference
522
        self.runbzr('missing ../output-branch', retcode=1)
1185.35.30 by Aaron Bentley
Fixed missing --verbose
523
        self.runbzr('missing --verbose ../output-branch', retcode=1)
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
524
        # but we can force a push
525
        self.runbzr('push --overwrite')
526
        # nothing missing
527
        self.runbzr('missing ../output-branch')
1495 by Robert Collins
Add a --create-prefix to the new push command.
528
        
529
        # pushing to a new dir with no parent should fail
1185.35.21 by Aaron Bentley
Changed error status to 3
530
        self.runbzr('push ../missing/new-branch', retcode=3)
1495 by Robert Collins
Add a --create-prefix to the new push command.
531
        # unless we provide --create-prefix
532
        self.runbzr('push --create-prefix ../missing/new-branch')
533
        # nothing missing
534
        self.runbzr('missing ../missing/new-branch')
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
535
1185.31.3 by John Arbash Meinel
Fix ExternalCommand to not run random files in the current directory, unless it is truly in BZRPATH
536
    def test_external_command(self):
1588.1.1 by Martin Pool
Supress "hello from test-command" noise from test_external_command
537
        """Test that external commands can be run by setting the path
538
        """
539
        # We don't at present run bzr in a subprocess for blackbox tests, and so 
540
        # don't really capture stdout, only the internal python stream.
541
        # Therefore we don't use a subcommand that produces any output or does
542
        # anything -- we just check that it can be run successfully.  
1185.31.3 by John Arbash Meinel
Fix ExternalCommand to not run random files in the current directory, unless it is truly in BZRPATH
543
        cmd_name = 'test-command'
544
        if sys.platform == 'win32':
545
            cmd_name += '.bat'
546
        oldpath = os.environ.get('BZRPATH', None)
547
        bzr = self.capture
548
        try:
549
            if os.environ.has_key('BZRPATH'):
550
                del os.environ['BZRPATH']
551
552
            f = file(cmd_name, 'wb')
553
            if sys.platform == 'win32':
554
                f.write('@echo off\n')
555
            else:
556
                f.write('#!/bin/sh\n')
1588.1.1 by Martin Pool
Supress "hello from test-command" noise from test_external_command
557
            # f.write('echo Hello from test-command')
1185.31.3 by John Arbash Meinel
Fix ExternalCommand to not run random files in the current directory, unless it is truly in BZRPATH
558
            f.close()
559
            os.chmod(cmd_name, 0755)
560
561
            # It should not find the command in the local 
562
            # directory by default, since it is not in my path
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
563
            bzr(cmd_name, retcode=3)
1185.31.3 by John Arbash Meinel
Fix ExternalCommand to not run random files in the current directory, unless it is truly in BZRPATH
564
565
            # Now put it into my path
566
            os.environ['BZRPATH'] = '.'
567
568
            bzr(cmd_name)
569
570
            # Make sure empty path elements are ignored
571
            os.environ['BZRPATH'] = os.pathsep
572
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
573
            bzr(cmd_name, retcode=3)
1185.31.3 by John Arbash Meinel
Fix ExternalCommand to not run random files in the current directory, unless it is truly in BZRPATH
574
575
        finally:
576
            if oldpath:
577
                os.environ['BZRPATH'] = oldpath
578
579
1092.2.6 by Robert Collins
symlink support updated to work
580
def listdir_sorted(dir):
581
    L = os.listdir(dir)
582
    L.sort()
583
    return L
1185.3.20 by Martin Pool
- run_bzr_captured also includes logged errors in
584
1092.2.12 by Robert Collins
merge from HEAD
585
904 by Martin Pool
- more selftest external-command fixes
586
class OldTests(ExternalBase):
1092.1.39 by Robert Collins
merge from mpool
587
    """old tests moved from ./testbzr."""
588
1102 by Martin Pool
- merge test refactoring from robertc
589
    def test_bzr(self):
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
590
        from os import chdir, mkdir
591
        from os.path import exists
592
904 by Martin Pool
- more selftest external-command fixes
593
        runbzr = self.runbzr
1185.3.26 by Martin Pool
- remove remaining external executions of bzr
594
        capture = self.capture
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
595
        progress = self.log
596
597
        progress("basic branch creation")
904 by Martin Pool
- more selftest external-command fixes
598
        mkdir('branch1')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
599
        chdir('branch1')
898 by Martin Pool
- add new runbzr method for external tests
600
        runbzr('init')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
601
1185.3.25 by Martin Pool
- run blackbox tests in-process
602
        self.assertEquals(capture('root').rstrip(),
1185.31.32 by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \
603
                          pathjoin(self.test_dir, 'branch1'))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
604
605
        progress("status of new file")
606
607
        f = file('test.txt', 'wt')
608
        f.write('hello world!\n')
609
        f.close()
610
1185.3.25 by Martin Pool
- run blackbox tests in-process
611
        self.assertEquals(capture('unknowns'), 'test.txt\n')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
612
1185.3.25 by Martin Pool
- run blackbox tests in-process
613
        out = capture("status")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
614
        self.assertEquals(out, 'unknown:\n  test.txt\n')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
615
616
        f = file('test2.txt', 'wt')
617
        f.write('goodbye cruel world...\n')
618
        f.close()
619
1185.3.25 by Martin Pool
- run blackbox tests in-process
620
        out = capture("status test.txt")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
621
        self.assertEquals(out, "unknown:\n  test.txt\n")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
622
1185.3.25 by Martin Pool
- run blackbox tests in-process
623
        out = capture("status")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
624
        self.assertEquals(out, ("unknown:\n" "  test.txt\n" "  test2.txt\n"))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
625
626
        os.unlink('test2.txt')
627
628
        progress("command aliases")
1777.1.1 by Robert Collins
(robertc)Remove --all option from status and deprecate the underlying api.
629
        out = capture("st")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
630
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
631
1185.3.25 by Martin Pool
- run blackbox tests in-process
632
        out = capture("stat")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
633
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
634
635
        progress("command help")
898 by Martin Pool
- add new runbzr method for external tests
636
        runbzr("help st")
637
        runbzr("help")
638
        runbzr("help commands")
1185.35.21 by Aaron Bentley
Changed error status to 3
639
        runbzr("help slartibartfast", 3)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
640
1185.3.25 by Martin Pool
- run blackbox tests in-process
641
        out = capture("help ci")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
642
        out.index('aliases: ')
643
644
        progress("can't rename unversioned file")
1185.35.21 by Aaron Bentley
Changed error status to 3
645
        runbzr("rename test.txt new-test.txt", 3)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
646
647
        progress("adding a file")
648
898 by Martin Pool
- add new runbzr method for external tests
649
        runbzr("add test.txt")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
650
        self.assertEquals(capture("unknowns"), '')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
651
652
        progress("rename newly-added file")
898 by Martin Pool
- add new runbzr method for external tests
653
        runbzr("rename test.txt hello.txt")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
654
        self.assert_(os.path.exists("hello.txt"))
655
        self.assert_(not os.path.exists("test.txt"))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
656
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
657
        self.assertEquals(capture("revno"), '0\n')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
658
659
        progress("add first revision")
904 by Martin Pool
- more selftest external-command fixes
660
        runbzr(['commit', '-m', 'add first revision'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
661
662
        progress("more complex renames")
663
        os.mkdir("sub1")
1185.35.21 by Aaron Bentley
Changed error status to 3
664
        runbzr("rename hello.txt sub1", 3)
665
        runbzr("rename hello.txt sub1/hello.txt", 3)
666
        runbzr("move hello.txt sub1", 3)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
667
898 by Martin Pool
- add new runbzr method for external tests
668
        runbzr("add sub1")
669
        runbzr("rename sub1 sub2")
670
        runbzr("move hello.txt sub2")
1457.1.4 by Robert Collins
Branch.relpath has been moved to WorkingTree.relpath.
671
        self.assertEqual(capture("relpath sub2/hello.txt"),
1185.31.32 by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \
672
                         pathjoin("sub2", "hello.txt\n"))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
673
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
674
        self.assert_(exists("sub2"))
675
        self.assert_(exists("sub2/hello.txt"))
676
        self.assert_(not exists("sub1"))
677
        self.assert_(not exists("hello.txt"))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
678
898 by Martin Pool
- add new runbzr method for external tests
679
        runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
680
681
        mkdir("sub1")
898 by Martin Pool
- add new runbzr method for external tests
682
        runbzr('add sub1')
683
        runbzr('move sub2/hello.txt sub1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
684
        self.assert_(not exists('sub2/hello.txt'))
685
        self.assert_(exists('sub1/hello.txt'))
898 by Martin Pool
- add new runbzr method for external tests
686
        runbzr('move sub2 sub1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
687
        self.assert_(not exists('sub2'))
688
        self.assert_(exists('sub1/sub2'))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
689
898 by Martin Pool
- add new runbzr method for external tests
690
        runbzr(['commit', '-m', 'rename nested subdirectories'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
691
692
        chdir('sub1/sub2')
1185.3.25 by Martin Pool
- run blackbox tests in-process
693
        self.assertEquals(capture('root')[:-1],
1185.31.32 by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \
694
                          pathjoin(self.test_dir, 'branch1'))
898 by Martin Pool
- add new runbzr method for external tests
695
        runbzr('move ../hello.txt .')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
696
        self.assert_(exists('./hello.txt'))
1185.3.25 by Martin Pool
- run blackbox tests in-process
697
        self.assertEquals(capture('relpath hello.txt'),
1185.31.32 by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \
698
                          pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
699
        self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
898 by Martin Pool
- add new runbzr method for external tests
700
        runbzr(['commit', '-m', 'move to parent directory'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
701
        chdir('..')
1185.31.32 by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \
702
        self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
703
898 by Martin Pool
- add new runbzr method for external tests
704
        runbzr('move sub2/hello.txt .')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
705
        self.assert_(exists('hello.txt'))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
706
707
        f = file('hello.txt', 'wt')
708
        f.write('some nice new content\n')
709
        f.close()
710
711
        f = file('msg.tmp', 'wt')
1185.12.25 by Aaron Bentley
Added one-line log format
712
        f.write('this is my new commit\nand it has multiple lines, for fun')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
713
        f.close()
714
898 by Martin Pool
- add new runbzr method for external tests
715
        runbzr('commit -F msg.tmp')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
716
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
717
        self.assertEquals(capture('revno'), '5\n')
898 by Martin Pool
- add new runbzr method for external tests
718
        runbzr('export -r 5 export-5.tmp')
719
        runbzr('export export.tmp')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
720
898 by Martin Pool
- add new runbzr method for external tests
721
        runbzr('log')
722
        runbzr('log -v')
909.1.5 by Aaron Bentley
Fixed log -v (mostly)
723
        runbzr('log -v --forward')
1185.35.21 by Aaron Bentley
Changed error status to 3
724
        runbzr('log -m', retcode=3)
1185.3.25 by Martin Pool
- run blackbox tests in-process
725
        log_out = capture('log -m commit')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
726
        self.assert_("this is my new commit\n  and" in log_out)
727
        self.assert_("rename nested" not in log_out)
728
        self.assert_('revision-id' not in log_out)
729
        self.assert_('revision-id' in capture('log --show-ids -m commit'))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
730
1185.12.25 by Aaron Bentley
Added one-line log format
731
        log_out = capture('log --line')
1692.3.5 by Robert Collins
Merge integration, fixing test failure in test_too_much due to terminal width changing.
732
        # determine the widest line we want
733
        max_width = terminal_width() - 1
1185.12.25 by Aaron Bentley
Added one-line log format
734
        for line in log_out.splitlines():
1692.3.5 by Robert Collins
Merge integration, fixing test failure in test_too_much due to terminal width changing.
735
            self.assert_(len(line) <= max_width, len(line))
1740.2.5 by Aaron Bentley
Merge from bzr.dev
736
        self.assert_("this is my new commit and" not in log_out)
737
        self.assert_("this is my new commit" in log_out)
1185.12.25 by Aaron Bentley
Added one-line log format
738
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
739
        progress("file with spaces in name")
740
        mkdir('sub directory')
741
        file('sub directory/file with spaces ', 'wt').write('see how this works\n')
898 by Martin Pool
- add new runbzr method for external tests
742
        runbzr('add .')
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
743
        runbzr('diff', retcode=1)
898 by Martin Pool
- add new runbzr method for external tests
744
        runbzr('commit -m add-spaces')
745
        runbzr('check')
746
747
        runbzr('log')
748
        runbzr('log --forward')
749
750
        runbzr('info')
1092.1.35 by Robert Collins
merge from mpool up to rev 1110
751
1092.2.6 by Robert Collins
symlink support updated to work
752
        if has_symlinks():
753
            progress("symlinks")
754
            mkdir('symlinks')
755
            chdir('symlinks')
756
            runbzr('init')
757
            os.symlink("NOWHERE1", "link1")
758
            runbzr('add link1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
759
            self.assertEquals(self.capture('unknowns'), '')
1092.2.6 by Robert Collins
symlink support updated to work
760
            runbzr(['commit', '-m', '1: added symlink link1'])
761
    
762
            mkdir('d1')
763
            runbzr('add d1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
764
            self.assertEquals(self.capture('unknowns'), '')
1092.2.6 by Robert Collins
symlink support updated to work
765
            os.symlink("NOWHERE2", "d1/link2")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
766
            self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
1092.2.6 by Robert Collins
symlink support updated to work
767
            # is d1/link2 found when adding d1
768
            runbzr('add d1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
769
            self.assertEquals(self.capture('unknowns'), '')
1092.2.6 by Robert Collins
symlink support updated to work
770
            os.symlink("NOWHERE3", "d1/link3")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
771
            self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
1092.2.6 by Robert Collins
symlink support updated to work
772
            runbzr(['commit', '-m', '2: added dir, symlink'])
773
    
774
            runbzr('rename d1 d2')
775
            runbzr('move d2/link2 .')
776
            runbzr('move link1 d2')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
777
            self.assertEquals(os.readlink("./link2"), "NOWHERE2")
778
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1092.2.6 by Robert Collins
symlink support updated to work
779
            runbzr('add d2/link3')
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
780
            runbzr('diff', retcode=1)
1092.2.6 by Robert Collins
symlink support updated to work
781
            runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
782
    
783
            os.unlink("link2")
784
            os.symlink("TARGET 2", "link2")
785
            os.unlink("d2/link1")
786
            os.symlink("TARGET 1", "d2/link1")
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
787
            runbzr('diff', retcode=1)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
788
            self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
1092.2.6 by Robert Collins
symlink support updated to work
789
            runbzr(['commit', '-m', '4: retarget of two links'])
790
    
791
            runbzr('remove d2/link1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
792
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1092.2.20 by Robert Collins
symlink and weaves, whaddya know
793
            runbzr(['commit', '-m', '5: remove d2/link1'])
1424 by Robert Collins
add rm alias to remove
794
            # try with the rm alias
795
            runbzr('add d2/link1')
796
            runbzr(['commit', '-m', '6: add d2/link1'])
797
            runbzr('rm d2/link1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
798
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1424 by Robert Collins
add rm alias to remove
799
            runbzr(['commit', '-m', '7: remove d2/link1'])
1092.2.6 by Robert Collins
symlink support updated to work
800
    
801
            os.mkdir("d1")
802
            runbzr('add d1')
803
            runbzr('rename d2/link3 d1/link3new')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
804
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1424 by Robert Collins
add rm alias to remove
805
            runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1092.2.6 by Robert Collins
symlink support updated to work
806
            
807
            runbzr(['check'])
808
            
809
            runbzr(['export', '-r', '1', 'exp1.tmp'])
810
            chdir("exp1.tmp")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
811
            self.assertEquals(listdir_sorted("."), [ "link1" ])
812
            self.assertEquals(os.readlink("link1"), "NOWHERE1")
1092.2.6 by Robert Collins
symlink support updated to work
813
            chdir("..")
814
            
815
            runbzr(['export', '-r', '2', 'exp2.tmp'])
816
            chdir("exp2.tmp")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
817
            self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
1092.2.6 by Robert Collins
symlink support updated to work
818
            chdir("..")
819
            
820
            runbzr(['export', '-r', '3', 'exp3.tmp'])
821
            chdir("exp3.tmp")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
822
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
823
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
824
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
825
            self.assertEquals(os.readlink("link2")   , "NOWHERE2")
1092.2.6 by Robert Collins
symlink support updated to work
826
            chdir("..")
827
            
828
            runbzr(['export', '-r', '4', 'exp4.tmp'])
829
            chdir("exp4.tmp")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
830
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
831
            self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
832
            self.assertEquals(os.readlink("link2")   , "TARGET 2")
833
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1092.2.6 by Robert Collins
symlink support updated to work
834
            chdir("..")
835
            
836
            runbzr(['export', '-r', '5', 'exp5.tmp'])
837
            chdir("exp5.tmp")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
838
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
839
            self.assert_(os.path.islink("link2"))
840
            self.assert_(listdir_sorted("d2")== [ "link3" ])
1092.2.6 by Robert Collins
symlink support updated to work
841
            chdir("..")
842
            
1424 by Robert Collins
add rm alias to remove
843
            runbzr(['export', '-r', '8', 'exp6.tmp'])
1092.2.6 by Robert Collins
symlink support updated to work
844
            chdir("exp6.tmp")
1424 by Robert Collins
add rm alias to remove
845
            self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
846
            self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
847
            self.assertEquals(listdir_sorted("d2"), [])
848
            self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
1092.2.6 by Robert Collins
symlink support updated to work
849
            chdir("..")
850
        else:
851
            progress("skipping symlink tests")
1400.1.1 by Robert Collins
implement a basic test for the ui branch command from http servers
852
853
1524.1.1 by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir
854
class RemoteTests(object):
1400.1.1 by Robert Collins
implement a basic test for the ui branch command from http servers
855
    """Test bzr ui commands against remote branches."""
856
857
    def test_branch(self):
858
        os.mkdir('from')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
859
        wt = self.make_branch_and_tree('from')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
860
        branch = wt.branch
861
        wt.commit('empty commit for nonsense', allow_pointless=True)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
862
        url = self.get_readonly_url('from')
1400.1.1 by Robert Collins
implement a basic test for the ui branch command from http servers
863
        self.run_bzr('branch', url, 'to')
864
        branch = Branch.open('to')
865
        self.assertEqual(1, len(branch.revision_history()))
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
866
        # the branch should be set in to to from
867
        self.assertEqual(url + '/', branch.get_parent())
1185.16.48 by mbp at sourcefrog
- more refactoring of and tests for option parsing
868
1442.1.64 by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path).
869
    def test_log(self):
870
        self.build_tree(['branch/', 'branch/file'])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
871
        self.capture('init branch')
872
        self.capture('add branch/file')
873
        self.capture('commit -m foo branch')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
874
        url = self.get_readonly_url('branch/file')
1442.1.64 by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path).
875
        output = self.capture('log %s' % url)
1185.35.17 by Aaron Bentley
Added branch nicks to long-format logs
876
        self.assertEqual(8, len(output.split('\n')))
1442.1.64 by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path).
877
        
1510 by Robert Collins
Merge from mpool, adjusting check to retain HTTP support.
878
    def test_check(self):
879
        self.build_tree(['branch/', 'branch/file'])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
880
        self.capture('init branch')
881
        self.capture('add branch/file')
882
        self.capture('commit -m foo branch')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
883
        url = self.get_readonly_url('branch/')
1510 by Robert Collins
Merge from mpool, adjusting check to retain HTTP support.
884
        self.run_bzr('check', url)
1524.1.1 by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir
885
    
1563.1.6 by Robert Collins
Add tests for sftp push, and NonLocalTets for BzrDir.create_branch_convenience, before fixing the failure of it to work on non-local urls.
886
    def test_push(self):
887
        # create a source branch
888
        os.mkdir('my-branch')
889
        os.chdir('my-branch')
890
        self.run_bzr('init')
891
        file('hello', 'wt').write('foo')
892
        self.run_bzr('add', 'hello')
893
        self.run_bzr('commit', '-m', 'setup')
894
895
        # with an explicit target work
896
        self.run_bzr('push', self.get_url('output-branch'))
897
1524.1.1 by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir
898
    
899
class HTTPTests(TestCaseWithWebserver, RemoteTests):
900
    """Test various commands against a HTTP server."""
901
    
902
    
903
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
904
    """Test various commands against a SFTP server using abs paths."""
905
906
    
907
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
908
    """Test various commands against a SFTP server using abs paths."""
909
910
    def setUp(self):
911
        super(SFTPTestsAbsoluteSibling, self).setUp()
912
        self._override_home = '/dev/noone/runs/tests/here'
913
914
    
915
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
916
    """Test various commands against a SFTP server using homedir rel paths."""
917
918
    def setUp(self):
919
        super(SFTPTestsRelative, self).setUp()
920
        self._get_remote_is_absolute = False