~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
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
40
import shutil
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
41
import sys
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
42
43
from bzrlib.branch import Branch
1432 by Robert Collins
branch: namespace
44
from bzrlib.clone import copy_branch
1393.3.3 by Jelmer Vernooij
Add test for empty commit messages.
45
from bzrlib.errors import BzrCommandError
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 \
46
from bzrlib.osutils import has_symlinks, pathjoin
1185.31.25 by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py
47
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
1530.1.7 by Robert Collins
merge integration.
48
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
1513 by Robert Collins
Blackbox tests are maintained within the bzrlib.tests.blackbox directory.
49
from bzrlib.tests.blackbox import ExternalBase
1142 by Martin Pool
- remove dead code from blackbox tests (pychecker)
50
1102 by Martin Pool
- merge test refactoring from robertc
51
class TestCommands(ExternalBase):
52
53
    def test_help_commands(self):
898 by Martin Pool
- add new runbzr method for external tests
54
        self.runbzr('--help')
55
        self.runbzr('help')
56
        self.runbzr('help commands')
57
        self.runbzr('help help')
58
        self.runbzr('commit -h')
727 by Martin Pool
- move more code to run external commands from testbzr to selftest
59
1102 by Martin Pool
- merge test refactoring from robertc
60
    def test_init_branch(self):
898 by Martin Pool
- add new runbzr method for external tests
61
        self.runbzr(['init'])
732 by Martin Pool
- move more tests into bzr selftest
62
1185.16.138 by Martin Pool
[patch] 'bzr init DIR' (John)
63
        # Can it handle subdirectories as well?
64
        self.runbzr('init subdir1')
65
        self.assert_(os.path.exists('subdir1'))
66
        self.assert_(os.path.exists('subdir1/.bzr'))
67
1185.35.21 by Aaron Bentley
Changed error status to 3
68
        self.runbzr('init subdir2/nothere', retcode=3)
1185.16.138 by Martin Pool
[patch] 'bzr init DIR' (John)
69
        
70
        os.mkdir('subdir2')
71
        self.runbzr('init subdir2')
1185.35.21 by Aaron Bentley
Changed error status to 3
72
        self.runbzr('init subdir2', retcode=3)
1185.16.138 by Martin Pool
[patch] 'bzr init DIR' (John)
73
74
        self.runbzr('init subdir2/subsubdir1')
75
        self.assert_(os.path.exists('subdir2/subsubdir1/.bzr'))
76
1102 by Martin Pool
- merge test refactoring from robertc
77
    def test_whoami(self):
732 by Martin Pool
- move more tests into bzr selftest
78
        # this should always identify something, if only "john@localhost"
898 by Martin Pool
- add new runbzr method for external tests
79
        self.runbzr("whoami")
80
        self.runbzr("whoami --email")
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
81
82
        self.assertEquals(self.runbzr("whoami --email",
83
                                      backtick=True).count('@'), 1)
84
        
1102 by Martin Pool
- merge test refactoring from robertc
85
    def test_whoami_branch(self):
86
        """branch specific user identity works."""
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
87
        self.runbzr('init')
88
        f = file('.bzr/email', 'wt')
89
        f.write('Branch Identity <branch@identi.ty>')
90
        f.close()
1185.6.1 by John Arbash Meinel
Updated the whomai test to handle BZREMAIL
91
        bzr_email = os.environ.get('BZREMAIL')
92
        if bzr_email is not None:
93
            del os.environ['BZREMAIL']
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
94
        whoami = self.runbzr("whoami",backtick=True)
95
        whoami_email = self.runbzr("whoami --email",backtick=True)
96
        self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
97
        self.assertTrue(whoami_email.startswith('branch@identi.ty'))
1185.6.1 by John Arbash Meinel
Updated the whomai test to handle BZREMAIL
98
        # Verify that the environment variable overrides the value 
99
        # in the file
100
        os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
101
        whoami = self.runbzr("whoami",backtick=True)
102
        whoami_email = self.runbzr("whoami --email",backtick=True)
103
        self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
104
        self.assertTrue(whoami_email.startswith('other@environ.ment'))
105
        if bzr_email is not None:
106
            os.environ['BZREMAIL'] = bzr_email
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
107
1185.35.14 by Aaron Bentley
Implemented nick command
108
    def test_nick_command(self):
109
        """bzr nick for viewing, setting nicknames"""
110
        os.mkdir('me.dev')
111
        os.chdir('me.dev')
112
        self.runbzr('init')
113
        nick = self.runbzr("nick",backtick=True)
114
        self.assertEqual(nick, 'me.dev\n')
115
        nick = self.runbzr("nick moo")
116
        nick = self.runbzr("nick",backtick=True)
117
        self.assertEqual(nick, 'moo\n')
118
119
1102 by Martin Pool
- merge test refactoring from robertc
120
    def test_invalid_commands(self):
1185.35.21 by Aaron Bentley
Changed error status to 3
121
        self.runbzr("pants", retcode=3)
122
        self.runbzr("--pants off", retcode=3)
123
        self.runbzr("diff --message foo", retcode=3)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
124
1102 by Martin Pool
- merge test refactoring from robertc
125
    def test_empty_commit(self):
898 by Martin Pool
- add new runbzr method for external tests
126
        self.runbzr("init")
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
127
        self.build_tree(['hello.txt'])
1185.35.21 by Aaron Bentley
Changed error status to 3
128
        self.runbzr("commit -m empty", retcode=3)
898 by Martin Pool
- add new runbzr method for external tests
129
        self.runbzr("add hello.txt")
1185.34.4 by Jelmer Vernooij
Support -r option to bzr status. The backend code already handled
130
        self.runbzr("commit -m added")       
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
131
1393.3.3 by Jelmer Vernooij
Add test for empty commit messages.
132
    def test_empty_commit_message(self):
133
        self.runbzr("init")
134
        file('foo.c', 'wt').write('int main() {}')
135
        self.runbzr(['add', 'foo.c'])
1185.35.21 by Aaron Bentley
Changed error status to 3
136
        self.runbzr(["commit", "-m", ""] , retcode=3) 
1393.3.3 by Jelmer Vernooij
Add test for empty commit messages.
137
1507 by Robert Collins
Test case for removing deleted contents from Wouter van Heyst.
138
    def test_remove_deleted(self):
139
        self.runbzr("init")
140
        self.build_tree(['a'])
141
        self.runbzr(['add', 'a'])
142
        self.runbzr(['commit', '-m', 'added a'])
143
        os.unlink('a')
144
        self.runbzr(['remove', 'a'])
145
1185.12.101 by Aaron Bentley
Made commit take branch from first argument, if supplied.
146
    def test_other_branch_commit(self):
147
        # this branch is to ensure consistent behaviour, whether we're run
148
        # inside a branch, or not.
149
        os.mkdir('empty_branch')
150
        os.chdir('empty_branch')
151
        self.runbzr('init')
152
        os.mkdir('branch')
153
        os.chdir('branch')
154
        self.runbzr('init')
155
        file('foo.c', 'wt').write('int main() {}')
156
        file('bar.c', 'wt').write('int main() {}')
157
        os.chdir('..')
158
        self.runbzr(['add', 'branch/foo.c'])
159
        self.runbzr(['add', 'branch'])
160
        # can't commit files in different trees; sane error
1185.35.21 by Aaron Bentley
Changed error status to 3
161
        self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
1185.12.101 by Aaron Bentley
Made commit take branch from first argument, if supplied.
162
        self.runbzr('commit -m newstuff branch/foo.c')
163
        self.runbzr('commit -m newstuff branch')
1185.35.21 by Aaron Bentley
Changed error status to 3
164
        self.runbzr('commit -m newstuff branch', retcode=3)
1185.12.101 by Aaron Bentley
Made commit take branch from first argument, if supplied.
165
1102 by Martin Pool
- merge test refactoring from robertc
166
    def test_ignore_patterns(self):
906 by Martin Pool
- split out black-box ignore commands
167
        from bzrlib.branch import Branch
1508.1.6 by Robert Collins
Move Branch.unknowns() to WorkingTree.
168
        Branch.initialize('.')
169
        self.assertEquals(self.capture('unknowns'), '')
906 by Martin Pool
- split out black-box ignore commands
170
171
        file('foo.tmp', 'wt').write('tmp files are ignored')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
172
        self.assertEquals(self.capture('unknowns'), '')
906 by Martin Pool
- split out black-box ignore commands
173
174
        file('foo.c', 'wt').write('int main() {}')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
175
        self.assertEquals(self.capture('unknowns'), 'foo.c\n')
906 by Martin Pool
- split out black-box ignore commands
176
177
        self.runbzr(['add', 'foo.c'])
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
178
        self.assertEquals(self.capture('unknowns'), '')
906 by Martin Pool
- split out black-box ignore commands
179
180
        # 'ignore' works when creating the .bzignore file
181
        file('foo.blah', 'wt').write('blah')
1508.1.6 by Robert Collins
Move Branch.unknowns() to WorkingTree.
182
        self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
906 by Martin Pool
- split out black-box ignore commands
183
        self.runbzr('ignore *.blah')
1508.1.6 by Robert Collins
Move Branch.unknowns() to WorkingTree.
184
        self.assertEquals(self.capture('unknowns'), '')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
185
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
906 by Martin Pool
- split out black-box ignore commands
186
187
        # 'ignore' works when then .bzrignore file already exists
188
        file('garh', 'wt').write('garh')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
189
        self.assertEquals(self.capture('unknowns'), 'garh\n')
906 by Martin Pool
- split out black-box ignore commands
190
        self.runbzr('ignore garh')
1508.1.6 by Robert Collins
Move Branch.unknowns() to WorkingTree.
191
        self.assertEquals(self.capture('unknowns'), '')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
192
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
1102 by Martin Pool
- merge test refactoring from robertc
193
194
    def test_revert(self):
195
        self.runbzr('init')
196
197
        file('hello', 'wt').write('foo')
198
        self.runbzr('add hello')
199
        self.runbzr('commit -m setup hello')
200
201
        file('goodbye', 'wt').write('baz')
202
        self.runbzr('add goodbye')
203
        self.runbzr('commit -m setup goodbye')
1092.2.18 by Robert Collins
merge from symlink branch
204
1102 by Martin Pool
- merge test refactoring from robertc
205
        file('hello', 'wt').write('bar')
206
        file('goodbye', 'wt').write('qux')
207
        self.runbzr('revert hello')
208
        self.check_file_contents('hello', 'foo')
209
        self.check_file_contents('goodbye', 'qux')
210
        self.runbzr('revert')
211
        self.check_file_contents('goodbye', 'baz')
212
213
        os.mkdir('revertdir')
214
        self.runbzr('add revertdir')
215
        self.runbzr('commit -m f')
216
        os.rmdir('revertdir')
217
        self.runbzr('revert')
218
1185.31.49 by John Arbash Meinel
Some corrections using the new osutils.rename. **ALL TESTS PASS**
219
        if has_symlinks():
220
            os.symlink('/unlikely/to/exist', 'symlink')
221
            self.runbzr('add symlink')
222
            self.runbzr('commit -m f')
223
            os.unlink('symlink')
224
            self.runbzr('revert')
225
            self.failUnlessExists('symlink')
226
            os.unlink('symlink')
227
            os.symlink('a-different-path', 'symlink')
228
            self.runbzr('revert')
229
            self.assertEqual('/unlikely/to/exist',
230
                             os.readlink('symlink'))
231
        else:
232
            self.log("skipping revert symlink tests")
1092.2.18 by Robert Collins
merge from symlink branch
233
        
1185.5.8 by John Arbash Meinel
Fixed bzr revert with the new RevisionSpec code.
234
        file('hello', 'wt').write('xyz')
235
        self.runbzr('commit -m xyz hello')
236
        self.runbzr('revert -r 1 hello')
237
        self.check_file_contents('hello', 'foo')
238
        self.runbzr('revert hello')
239
        self.check_file_contents('hello', 'xyz')
1185.8.5 by Aaron Bentley
Fixed non-tree-root bug in branch, revert, merge
240
        os.chdir('revertdir')
241
        self.runbzr('revert')
242
        os.chdir('..')
243
1185.34.4 by Jelmer Vernooij
Support -r option to bzr status. The backend code already handled
244
    def test_status(self):
245
        self.runbzr("init")
246
        self.build_tree(['hello.txt'])
247
        result = self.runbzr("status")
248
        self.assert_("unknown:\n  hello.txt\n" in result, result)
249
        self.runbzr("add hello.txt")
250
        result = self.runbzr("status")
251
        self.assert_("added:\n  hello.txt\n" in result, result)
252
        self.runbzr("commit -m added")
253
        result = self.runbzr("status -r 0..1")
254
        self.assert_("added:\n  hello.txt\n" in result, result)
255
        self.build_tree(['world.txt'])
256
        result = self.runbzr("status -r 0")
257
        self.assert_("added:\n  hello.txt\n" \
258
                     "unknown:\n  world.txt\n" in result, result)
1185.5.8 by John Arbash Meinel
Fixed bzr revert with the new RevisionSpec code.
259
1185.1.8 by Robert Collins
David Clymers patch to use rename rather than mv for two argument non-directory target bzr mv calls.
260
    def test_mv_modes(self):
1102 by Martin Pool
- merge test refactoring from robertc
261
        """Test two modes of operation for mv"""
262
        from bzrlib.branch import Branch
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
263
        b = Branch.initialize('.')
1102 by Martin Pool
- merge test refactoring from robertc
264
        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
265
        self.run_bzr_captured(['add', self.test_dir])
266
        self.run_bzr_captured(['mv', 'a', 'b'])
267
        self.run_bzr_captured(['mv', 'b', 'subdir'])
268
        self.run_bzr_captured(['mv', 'subdir/b', 'a'])
269
        self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
270
        self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
1102 by Martin Pool
- merge test refactoring from robertc
271
272
    def test_main_version(self):
273
        """Check output from version command and master option is reasonable"""
274
        # output is intentionally passed through to stdout so that we
275
        # can see the version being tested
276
        output = self.runbzr('version', backtick=1)
277
        self.log('bzr version output:')
278
        self.log(output)
279
        self.assert_(output.startswith('bzr (bazaar-ng) '))
280
        self.assertNotEqual(output.index('Canonical'), -1)
281
        # make sure --version is consistent
282
        tmp_output = self.runbzr('--version', backtick=1)
283
        self.log('bzr --version output:')
284
        self.log(tmp_output)
285
        self.assertEquals(output, tmp_output)
906 by Martin Pool
- split out black-box ignore commands
286
1092.1.39 by Robert Collins
merge from mpool
287
    def example_branch(test):
288
        test.runbzr('init')
289
        file('hello', 'wt').write('foo')
290
        test.runbzr('add hello')
291
        test.runbzr('commit -m setup hello')
292
        file('goodbye', 'wt').write('baz')
293
        test.runbzr('add goodbye')
294
        test.runbzr('commit -m setup goodbye')
295
1185.12.1 by Aaron Bentley
Fixed export
296
    def test_export(self):
297
        os.mkdir('branch')
298
        os.chdir('branch')
299
        self.example_branch()
300
        self.runbzr('export ../latest')
301
        self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
302
        self.runbzr('export ../first -r 1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
303
        self.assert_(not os.path.exists('../first/goodbye'))
1185.12.1 by Aaron Bentley
Fixed export
304
        self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
305
        self.runbzr('export ../first.gz -r 1')
306
        self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
307
        self.runbzr('export ../first.bz2 -r 1')
308
        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.
309
310
        from tarfile import TarFile
1185.12.1 by Aaron Bentley
Fixed export
311
        self.runbzr('export ../first.tar -r 1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
312
        self.assert_(os.path.isfile('../first.tar'))
1185.12.1 by Aaron Bentley
Fixed export
313
        tf = TarFile('../first.tar')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
314
        self.assert_('first/hello' in tf.getnames(), tf.getnames())
1185.12.1 by Aaron Bentley
Fixed export
315
        self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
316
        self.runbzr('export ../first.tar.gz -r 1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
317
        self.assert_(os.path.isfile('../first.tar.gz'))
1185.12.1 by Aaron Bentley
Fixed export
318
        self.runbzr('export ../first.tbz2 -r 1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
319
        self.assert_(os.path.isfile('../first.tbz2'))
1185.12.1 by Aaron Bentley
Fixed export
320
        self.runbzr('export ../first.tar.bz2 -r 1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
321
        self.assert_(os.path.isfile('../first.tar.bz2'))
1185.12.1 by Aaron Bentley
Fixed export
322
        self.runbzr('export ../first.tar.tbz2 -r 1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
323
        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.
324
1185.12.1 by Aaron Bentley
Fixed export
325
        from bz2 import BZ2File
326
        tf = TarFile('../first.tar.tbz2', 
327
                     fileobj=BZ2File('../first.tar.tbz2', 'r'))
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
328
        self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
1185.12.1 by Aaron Bentley
Fixed export
329
        self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
330
        self.runbzr('export ../first2.tar -r 1 --root pizza')
331
        tf = TarFile('../first2.tar')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
332
        self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
1185.12.1 by Aaron Bentley
Fixed export
333
1185.31.13 by John Arbash Meinel
Updated the test to also test zip exports. Fixed some small bugs exposed by test suite.
334
        from zipfile import ZipFile
335
        self.runbzr('export ../first.zip -r 1')
336
        self.failUnlessExists('../first.zip')
337
        zf = ZipFile('../first.zip')
338
        self.assert_('first/hello' in zf.namelist(), zf.namelist())
339
        self.assertEqual(zf.read('first/hello'), 'foo')
340
341
        self.runbzr('export ../first2.zip -r 1 --root pizza')
342
        zf = ZipFile('../first2.zip')
343
        self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
344
        
345
        self.runbzr('export ../first-zip --format=zip -r 1')
346
        zf = ZipFile('../first-zip')
347
        self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
348
1185.4.1 by Lalo Martins
blackbox tests for diff
349
    def test_diff(self):
350
        self.example_branch()
351
        file('hello', 'wt').write('hello world!')
352
        self.runbzr('commit -m fixing hello')
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
353
        output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
1185.4.1 by Lalo Martins
blackbox tests for diff
354
        self.assert_('\n+hello world!' in output)
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
355
        output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
1185.4.1 by Lalo Martins
blackbox tests for diff
356
        self.assert_('\n+baz' in output)
1185.35.26 by Aaron Bentley
Fixed diff and status on newly-added, newly-deleted files
357
        file('moo', 'wb').write('moo')
358
        self.runbzr('add moo')
359
        os.unlink('moo')
360
        self.runbzr('diff')
1185.4.1 by Lalo Martins
blackbox tests for diff
361
1432 by Robert Collins
branch: namespace
362
    def test_diff_branches(self):
1185.38.7 by John Arbash Meinel
Updated build_tree to use fixed line-endings for tests which read the file contents and compare
363
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
1432 by Robert Collins
branch: namespace
364
        branch = Branch.initialize('branch1')
1508.1.5 by Robert Collins
Move add from Branch to WorkingTree.
365
        branch.working_tree().add(['file'])
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
366
        branch.working_tree().commit('add file')
1432 by Robert Collins
branch: namespace
367
        copy_branch(branch, 'branch2')
1185.38.7 by John Arbash Meinel
Updated build_tree to use fixed line-endings for tests which read the file contents and compare
368
        print >> open('branch2/file', 'wb'), 'new content'
1432 by Robert Collins
branch: namespace
369
        branch2 = Branch.open('branch2')
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
370
        branch2.working_tree().commit('update file')
1432 by Robert Collins
branch: namespace
371
        # should open branch1 and diff against branch2, 
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
372
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
373
                                        'branch1'],
374
                                       retcode=1)
1432 by Robert Collins
branch: namespace
375
        self.assertEquals(("=== modified file 'file'\n"
1185.35.29 by Aaron Bentley
Support whitespace in diff filenames
376
                           "--- file\t\n"
377
                           "+++ file\t\n"
1432 by Robert Collins
branch: namespace
378
                           "@@ -1,1 +1,1 @@\n"
379
                           "-new content\n"
380
                           "+contents of branch1/file\n"
381
                           "\n", ''), output)
1185.35.28 by Aaron Bentley
Support diff with two branches as input.
382
        output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
383
                                       retcode=1)
384
        self.assertEqualDiff(("=== modified file 'file'\n"
1185.35.29 by Aaron Bentley
Support whitespace in diff filenames
385
                              "--- file\t\n"
386
                              "+++ file\t\n"
1185.35.28 by Aaron Bentley
Support diff with two branches as input.
387
                              "@@ -1,1 +1,1 @@\n"
388
                              "-new content\n"
389
                              "+contents of branch1/file\n"
390
                              "\n", ''), output)
391
1432 by Robert Collins
branch: namespace
392
1185.8.4 by Aaron Bentley
Fixed branch -r
393
    def test_branch(self):
394
        """Branch from one branch to another."""
395
        os.mkdir('a')
396
        os.chdir('a')
397
        self.example_branch()
398
        os.chdir('..')
399
        self.runbzr('branch a b')
1442.1.71 by Robert Collins
'bzr branch' sets the branch-name,
400
        self.assertFileEqual('b\n', 'b/.bzr/branch-name')
1185.8.4 by Aaron Bentley
Fixed branch -r
401
        self.runbzr('branch a c -r 1')
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
402
        os.chdir('b')
403
        self.runbzr('commit -m foo --unchanged')
404
        os.chdir('..')
1391 by Robert Collins
merge from integration
405
        # naughty - abstraction violations RBC 20050928  
1393 by Robert Collins
reenable remotebranch tests
406
        print "test_branch used to delete the stores, how is this meant to work ?"
407
        #shutil.rmtree('a/.bzr/revision-store')
408
        #shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
409
        #shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
410
        self.runbzr('branch a d --basis b')
1185.8.4 by Aaron Bentley
Fixed branch -r
411
1092.1.39 by Robert Collins
merge from mpool
412
    def test_merge(self):
413
        from bzrlib.branch import Branch
1139 by Martin Pool
- merge in merge improvements and additional tests
414
        
1092.1.39 by Robert Collins
merge from mpool
415
        os.mkdir('a')
416
        os.chdir('a')
417
        self.example_branch()
418
        os.chdir('..')
419
        self.runbzr('branch a b')
420
        os.chdir('b')
421
        file('goodbye', 'wt').write('quux')
422
        self.runbzr(['commit',  '-m',  "more u's are always good"])
423
424
        os.chdir('../a')
425
        file('hello', 'wt').write('quuux')
426
        # We can't merge when there are in-tree changes
1185.35.21 by Aaron Bentley
Changed error status to 3
427
        self.runbzr('merge ../b', retcode=3)
1092.1.39 by Robert Collins
merge from mpool
428
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
1185.12.84 by Aaron Bentley
got merge type selection under test
429
        self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
1185.35.21 by Aaron Bentley
Changed error status to 3
430
                    retcode=3)
1185.12.84 by Aaron Bentley
got merge type selection under test
431
        self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
432
        self.runbzr('revert --no-backup')
433
        self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
1185.12.46 by Aaron Bentley
Fixed -r brokenness in merge
434
        self.runbzr('revert --no-backup')
1185.24.3 by Aaron Bentley
Integrated reprocessing into the rest of the merge stuff
435
        self.runbzr('merge ../b -r last:1..last:1 --reprocess')
436
        self.runbzr('revert --no-backup')
1185.12.46 by Aaron Bentley
Fixed -r brokenness in merge
437
        self.runbzr('merge ../b -r last:1')
1092.1.39 by Robert Collins
merge from mpool
438
        self.check_file_contents('goodbye', 'quux')
439
        # Merging a branch pulls its revision into the tree
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
440
        a = Branch.open('.')
441
        b = Branch.open('../b')
1241 by Martin Pool
- rename last_patch to last_revision
442
        a.get_revision_xml(b.last_revision())
1457.1.14 by Robert Collins
Move pending_merges() to WorkingTree.
443
        self.log('pending merges: %s', a.working_tree().pending_merges())
444
        self.assertEquals(a.working_tree().pending_merges(),
445
                          [b.last_revision()])
1185.12.77 by Aaron Bentley
Prevented all ancestors from being marked as pending merges
446
        self.runbzr('commit -m merged')
447
        self.runbzr('merge ../b -r last:1')
1457.1.14 by Robert Collins
Move pending_merges() to WorkingTree.
448
        self.assertEqual(Branch.open('.').working_tree().pending_merges(), [])
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
449
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
450
    def test_merge_with_missing_file(self):
451
        """Merge handles missing file conflicts"""
452
        os.mkdir('a')
453
        os.chdir('a')
454
        os.mkdir('sub')
455
        print >> file('sub/a.txt', 'wb'), "hello"
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
456
        print >> file('b.txt', 'wb'), "hello"
457
        print >> file('sub/c.txt', 'wb'), "hello"
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
458
        self.runbzr('init')
459
        self.runbzr('add')
460
        self.runbzr(('commit', '-m', 'added a'))
461
        self.runbzr('branch . ../b')
462
        print >> file('sub/a.txt', 'ab'), "there"
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
463
        print >> file('b.txt', 'ab'), "there"
464
        print >> file('sub/c.txt', 'ab'), "there"
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
465
        self.runbzr(('commit', '-m', 'Added there'))
466
        os.unlink('sub/a.txt')
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
467
        os.unlink('sub/c.txt')
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
468
        os.rmdir('sub')
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
469
        os.unlink('b.txt')
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
470
        self.runbzr(('commit', '-m', 'Removed a.txt'))
471
        os.chdir('../b')
472
        print >> file('sub/a.txt', 'ab'), "something"
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
473
        print >> file('b.txt', 'ab'), "something"
474
        print >> file('sub/c.txt', 'ab'), "something"
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
475
        self.runbzr(('commit', '-m', 'Modified a.txt'))
1476 by Robert Collins
Merge now has a retcode of 1 when conflicts occur. (Robert Collins)
476
        self.runbzr('merge ../a/', retcode=1)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
477
        self.assert_(os.path.exists('sub/a.txt.THIS'))
478
        self.assert_(os.path.exists('sub/a.txt.BASE'))
1185.10.10 by Aaron Bentley
Handled modified files missing from THIS
479
        os.chdir('../a')
1476 by Robert Collins
Merge now has a retcode of 1 when conflicts occur. (Robert Collins)
480
        self.runbzr('merge ../b/', retcode=1)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
481
        self.assert_(os.path.exists('sub/a.txt.OTHER'))
482
        self.assert_(os.path.exists('sub/a.txt.BASE'))
1185.10.8 by Aaron Bentley
Conflict handling where OTHER is deleted
483
1185.33.33 by Martin Pool
[patch] add 'bzr inventory --kind directory'; remove 'bzr directories'
484
    def test_inventory(self):
485
        bzr = self.runbzr
486
        def output_equals(value, *args):
487
            out = self.runbzr(['inventory'] + list(args), backtick=True)
488
            self.assertEquals(out, value)
489
490
        bzr('init')
491
        open('a', 'wb').write('hello\n')
492
        os.mkdir('b')
493
494
        bzr('add a b')
495
        bzr('commit -m add')
496
497
        output_equals('a\n', '--kind', 'file')
498
        output_equals('b\n', '--kind', 'directory')        
499
1185.26.1 by John Arbash Meinel
Made ls work again, and take extra arguments.
500
    def test_ls(self):
501
        """Test the abilities of 'bzr ls'"""
502
        bzr = self.runbzr
503
        def bzrout(*args, **kwargs):
504
            kwargs['backtick'] = True
505
            return self.runbzr(*args, **kwargs)
506
507
        def ls_equals(value, *args):
508
            out = self.runbzr(['ls'] + list(args), backtick=True)
509
            self.assertEquals(out, value)
510
511
        bzr('init')
512
        open('a', 'wb').write('hello\n')
513
514
        # Can't supply both
1185.35.21 by Aaron Bentley
Changed error status to 3
515
        bzr('ls --verbose --null', retcode=3)
1185.26.1 by John Arbash Meinel
Made ls work again, and take extra arguments.
516
517
        ls_equals('a\n')
518
        ls_equals('?        a\n', '--verbose')
519
        ls_equals('a\n', '--unknown')
520
        ls_equals('', '--ignored')
521
        ls_equals('', '--versioned')
522
        ls_equals('a\n', '--unknown', '--ignored', '--versioned')
523
        ls_equals('', '--ignored', '--versioned')
524
        ls_equals('a\0', '--null')
525
526
        bzr('add a')
527
        ls_equals('V        a\n', '--verbose')
528
        bzr('commit -m add')
529
        
530
        os.mkdir('subdir')
531
        ls_equals('V        a\n'
532
                  '?        subdir/\n'
533
                  , '--verbose')
534
        open('subdir/b', 'wb').write('b\n')
535
        bzr('add')
536
        ls_equals('V        a\n'
537
                  'V        subdir/\n'
538
                  'V        subdir/b\n'
539
                  , '--verbose')
540
        bzr('commit -m subdir')
541
542
        ls_equals('a\n'
543
                  'subdir\n'
544
                  , '--non-recursive')
545
546
        ls_equals('V        a\n'
547
                  'V        subdir/\n'
548
                  , '--verbose', '--non-recursive')
549
550
        # Check what happens in a sub-directory
551
        os.chdir('subdir')
552
        ls_equals('b\n')
553
        ls_equals('b\0'
554
                  , '--null')
555
        ls_equals('a\n'
556
                  'subdir\n'
557
                  'subdir/b\n'
558
                  , '--from-root')
559
        ls_equals('a\0'
560
                  'subdir\0'
561
                  'subdir/b\0'
562
                  , '--from-root', '--null')
563
        ls_equals('a\n'
564
                  'subdir\n'
565
                  , '--from-root', '--non-recursive')
566
567
        os.chdir('..')
568
569
        # Check what happens when we supply a specific revision
570
        ls_equals('a\n', '--revision', '1')
571
        ls_equals('V        a\n'
572
                  , '--verbose', '--revision', '1')
573
574
        os.chdir('subdir')
575
        ls_equals('', '--revision', '1')
576
1185.26.2 by John Arbash Meinel
Added more tests.
577
        # Now try to do ignored files.
578
        os.chdir('..')
579
        open('blah.py', 'wb').write('unknown\n')
580
        open('blah.pyo', 'wb').write('ignored\n')
581
        ls_equals('a\n'
582
                  'blah.py\n'
583
                  'blah.pyo\n'
584
                  'subdir\n'
585
                  'subdir/b\n')
586
        ls_equals('V        a\n'
587
                  '?        blah.py\n'
588
                  'I        blah.pyo\n'
589
                  'V        subdir/\n'
590
                  'V        subdir/b\n'
591
                  , '--verbose')
592
        ls_equals('blah.pyo\n'
593
                  , '--ignored')
594
        ls_equals('blah.py\n'
595
                  , '--unknown')
596
        ls_equals('a\n'
597
                  'subdir\n'
598
                  'subdir/b\n'
599
                  , '--versioned')
600
1185.32.2 by John Arbash Meinel
Refactor pull --verbose into a log.py function, add tests.
601
    def test_pull_verbose(self):
602
        """Pull changes from one branch to another and watch the output."""
603
604
        os.mkdir('a')
605
        os.chdir('a')
606
607
        bzr = self.runbzr
608
        self.example_branch()
609
610
        os.chdir('..')
611
        bzr('branch a b')
612
        os.chdir('b')
613
        open('b', 'wb').write('else\n')
614
        bzr('add b')
615
        bzr(['commit', '-m', 'added b'])
616
617
        os.chdir('../a')
618
        out = bzr('pull --verbose ../b', backtick=True)
619
        self.failIfEqual(out.find('Added Revisions:'), -1)
620
        self.failIfEqual(out.find('message:\n  added b'), -1)
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
621
        self.failIfEqual(out.find('added b'), -1)
1185.32.2 by John Arbash Meinel
Refactor pull --verbose into a log.py function, add tests.
622
1185.32.4 by John Arbash Meinel
[merge] up-to-date against bzr.dev
623
        # 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.
624
        bzr('commit -m foo --unchanged')
625
        os.chdir('../b')
626
        bzr('commit -m baz --unchanged')
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
627
        bzr('pull ../a', retcode=3)
1185.32.4 by John Arbash Meinel
[merge] up-to-date against bzr.dev
628
        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.
629
630
        remove_loc = out.find('Removed Revisions:')
631
        self.failIfEqual(remove_loc, -1)
632
        added_loc = out.find('Added Revisions:')
633
        self.failIfEqual(added_loc, -1)
634
635
        removed_message = out.find('message:\n  baz')
636
        self.failIfEqual(removed_message, -1)
637
        self.failUnless(remove_loc < removed_message < added_loc)
638
639
        added_message = out.find('message:\n  foo')
640
        self.failIfEqual(added_message, -1)
641
        self.failUnless(added_loc < added_message)
642
        
1185.12.11 by Aaron Bentley
Made pull only save the parent location if it is unset, or on --remember
643
    def test_locations(self):
644
        """Using and remembering different locations"""
645
        os.mkdir('a')
646
        os.chdir('a')
647
        self.runbzr('init')
648
        self.runbzr('commit -m unchanged --unchanged')
1185.35.21 by Aaron Bentley
Changed error status to 3
649
        self.runbzr('pull', retcode=3)
650
        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
651
        self.runbzr('branch . ../b')
652
        os.chdir('../b')
653
        self.runbzr('pull')
654
        self.runbzr('branch . ../c')
655
        self.runbzr('pull ../c')
1185.12.12 by Aaron Bentley
Made merge use pull location or die if no branch specified.
656
        self.runbzr('merge')
1185.12.11 by Aaron Bentley
Made pull only save the parent location if it is unset, or on --remember
657
        os.chdir('../a')
658
        self.runbzr('pull ../b')
659
        self.runbzr('pull')
660
        self.runbzr('pull ../c')
661
        self.runbzr('branch ../c ../d')
662
        shutil.rmtree('../c')
663
        self.runbzr('pull')
664
        os.chdir('../b')
665
        self.runbzr('pull')
666
        os.chdir('../d')
1185.35.21 by Aaron Bentley
Changed error status to 3
667
        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
668
        self.runbzr('pull ../a --remember')
669
        self.runbzr('pull')
974.1.74 by Aaron Bentley
Made pull work after remote branch has merged latest revision
670
        
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
671
    def test_add_reports(self):
672
        """add command prints the names of added files."""
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
673
        b = Branch.initialize('.')
1185.46.8 by Aaron Bentley
bzr add reports ignored patterns.
674
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
675
        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
676
        # 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
677
        results = sorted(out.rstrip('\n').split('\n'))
1185.46.8 by Aaron Bentley
bzr add reports ignored patterns.
678
        self.assertEquals(['If you wish to add some of these files, please'\
679
                           ' add them by name.',
680
                           'added dir',
1185.31.34 by John Arbash Meinel
Removing instances of os.sep
681
                           'added dir/sub.txt',
1185.46.8 by Aaron Bentley
bzr add reports ignored patterns.
682
                           'added top.txt',
683
                           'ignored 1 file(s) matching "CVS"'],
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
684
                          results)
1185.46.9 by Aaron Bentley
Added verbose option to bzr add, to list all ignored files.
685
        out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
686
        results = sorted(out.rstrip('\n').split('\n'))
687
        self.assertEquals(['If you wish to add some of these files, please'\
688
                           ' add them by name.',
689
                           'ignored CVS matching "CVS"'],
690
                          results)
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
691
1446 by Robert Collins
fixup the verbose-does-nothing for add - add a --quiet instead
692
    def test_add_quiet_is(self):
693
        """add -q does not print the names of added files."""
694
        b = Branch.initialize('.')
695
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
696
        out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
1446 by Robert Collins
fixup the verbose-does-nothing for add - add a --quiet instead
697
        # the ordering is not defined at the moment
698
        results = sorted(out.rstrip('\n').split('\n'))
699
        self.assertEquals([''], results)
700
1508.1.6 by Robert Collins
Move Branch.unknowns() to WorkingTree.
701
    def test_add_in_unversioned(self):
702
        """Try to add a file in an unversioned directory.
703
704
        "bzr add" should add the parent(s) as necessary.
705
        """
706
        from bzrlib.branch import Branch
707
        Branch.initialize('.')
708
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
709
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
710
        self.run_bzr('add', 'inertiatic/esp')
711
        self.assertEquals(self.capture('unknowns'), '')
712
713
        # Multiple unversioned parents
714
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
715
        self.assertEquals(self.capture('unknowns'), 'veil\n')
716
        self.run_bzr('add', 'veil/cerpin/taxt')
717
        self.assertEquals(self.capture('unknowns'), '')
718
719
        # Check whacky paths work
720
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
721
        self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
722
        self.run_bzr('add', 'inertiatic/../cicatriz/esp')
723
        self.assertEquals(self.capture('unknowns'), '')
724
725
    def test_add_in_versioned(self):
726
        """Try to add a file in a versioned directory.
727
728
        "bzr add" should do this happily.
729
        """
730
        from bzrlib.branch import Branch
731
        Branch.initialize('.')
732
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
733
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
734
        self.run_bzr('add', '--no-recurse', 'inertiatic')
1185.31.34 by John Arbash Meinel
Removing instances of os.sep
735
        self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
1508.1.6 by Robert Collins
Move Branch.unknowns() to WorkingTree.
736
        self.run_bzr('add', 'inertiatic/esp')
737
        self.assertEquals(self.capture('unknowns'), '')
738
739
    def test_subdir_add(self):
740
        """Add in subdirectory should add only things from there down"""
741
        from bzrlib.branch import Branch
742
        
743
        eq = self.assertEqual
744
        ass = self.assert_
745
        chdir = os.chdir
746
        
747
        b = Branch.initialize('.')
748
        t = b.working_tree()
749
        self.build_tree(['src/', 'README'])
750
        
751
        eq(sorted(t.unknowns()),
752
           ['README', 'src'])
753
        
754
        self.run_bzr('add', 'src')
755
        
756
        self.build_tree(['src/foo.c'])
757
        
758
        chdir('src')
759
        self.run_bzr('add')
760
        
761
        self.assertEquals(self.capture('unknowns'), 'README\n')
762
        eq(len(t.read_working_inventory()), 3)
763
                
764
        chdir('..')
765
        self.run_bzr('add')
766
        self.assertEquals(self.capture('unknowns'), '')
767
        self.run_bzr('check')
768
1185.3.20 by Martin Pool
- run_bzr_captured also includes logged errors in
769
    def test_unknown_command(self):
770
        """Handling of unknown command."""
771
        out, err = self.run_bzr_captured(['fluffy-badger'],
1185.35.21 by Aaron Bentley
Changed error status to 3
772
                                         retcode=3)
1185.3.20 by Martin Pool
- run_bzr_captured also includes logged errors in
773
        self.assertEquals(out, '')
774
        err.index('unknown command')
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
775
1185.35.4 by Aaron Bentley
Implemented remerge
776
    def create_conflicts(self):
777
        """Create a conflicted tree"""
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
778
        os.mkdir('base')
779
        os.chdir('base')
780
        file('hello', 'wb').write("hi world")
781
        file('answer', 'wb').write("42")
782
        self.runbzr('init')
783
        self.runbzr('add')
784
        self.runbzr('commit -m base')
785
        self.runbzr('branch . ../other')
786
        self.runbzr('branch . ../this')
787
        os.chdir('../other')
788
        file('hello', 'wb').write("Hello.")
789
        file('answer', 'wb').write("Is anyone there?")
790
        self.runbzr('commit -m other')
791
        os.chdir('../this')
792
        file('hello', 'wb').write("Hello, world")
793
        self.runbzr('mv answer question')
794
        file('question', 'wb').write("What do you get when you multiply six"
795
                                   "times nine?")
796
        self.runbzr('commit -m this')
1185.35.4 by Aaron Bentley
Implemented remerge
797
798
    def test_remerge(self):
799
        """Remerge command works as expected"""
800
        self.create_conflicts()
801
        self.runbzr('merge ../other --show-base', retcode=1)
802
        conflict_text = file('hello').read()
803
        assert '|||||||' in conflict_text
804
        assert 'hi world' in conflict_text
805
        self.runbzr('remerge', retcode=1)
806
        conflict_text = file('hello').read()
807
        assert '|||||||' not in conflict_text
808
        assert 'hi world' not in conflict_text
809
        os.unlink('hello.OTHER')
810
        self.runbzr('remerge hello --merge-type weave', retcode=1)
1185.35.6 by Aaron Bentley
Removed todo, restored test
811
        assert os.path.exists('hello.OTHER')
1185.35.7 by Aaron Bentley
Fixed weave conflict handling
812
        file_id = self.runbzr('file-id hello')
1185.35.21 by Aaron Bentley
Changed error status to 3
813
        file_id = self.runbzr('file-id hello.THIS', retcode=3)
1185.35.4 by Aaron Bentley
Implemented remerge
814
        self.runbzr('remerge --merge-type weave', retcode=1)
815
        assert os.path.exists('hello.OTHER')
816
        assert not os.path.exists('hello.BASE')
817
        assert '|||||||' not in conflict_text
818
        assert 'hi world' not in conflict_text
1185.35.21 by Aaron Bentley
Changed error status to 3
819
        self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
820
        self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
821
        self.runbzr('remerge . --show-base --reprocess', retcode=3)
1185.35.4 by Aaron Bentley
Implemented remerge
822
        self.runbzr('remerge hello --show-base', retcode=1)
823
        self.runbzr('remerge hello --reprocess', retcode=1)
824
        self.runbzr('resolve --all')
825
        self.runbzr('commit -m done',)
1185.35.21 by Aaron Bentley
Changed error status to 3
826
        self.runbzr('remerge', retcode=3)
1185.35.4 by Aaron Bentley
Implemented remerge
827
828
829
    def test_conflicts(self):
830
        """Handling of merge conflicts"""
831
        self.create_conflicts()
1476 by Robert Collins
Merge now has a retcode of 1 when conflicts occur. (Robert Collins)
832
        self.runbzr('merge ../other --show-base', retcode=1)
1185.18.1 by Aaron Bentley
Added --show-base to merge
833
        conflict_text = file('hello').read()
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
834
        self.assert_('<<<<<<<' in conflict_text)
835
        self.assert_('>>>>>>>' in conflict_text)
836
        self.assert_('=======' in conflict_text)
837
        self.assert_('|||||||' in conflict_text)
838
        self.assert_('hi world' in conflict_text)
1185.18.1 by Aaron Bentley
Added --show-base to merge
839
        self.runbzr('revert')
840
        self.runbzr('resolve --all')
1476 by Robert Collins
Merge now has a retcode of 1 when conflicts occur. (Robert Collins)
841
        self.runbzr('merge ../other', retcode=1)
1185.18.1 by Aaron Bentley
Added --show-base to merge
842
        conflict_text = file('hello').read()
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
843
        self.assert_('|||||||' not in conflict_text)
844
        self.assert_('hi world' not in conflict_text)
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
845
        result = self.runbzr('conflicts', backtick=1)
846
        self.assertEquals(result, "hello\nquestion\n")
1185.14.11 by Aaron Bentley
moved conflict listing into status and stopped monkey-patching
847
        result = self.runbzr('status', backtick=1)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
848
        self.assert_("conflicts:\n  hello\n  question\n" in result, result)
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
849
        self.runbzr('resolve hello')
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
850
        result = self.runbzr('conflicts', backtick=1)
851
        self.assertEquals(result, "question\n")
1185.35.21 by Aaron Bentley
Changed error status to 3
852
        self.runbzr('commit -m conflicts', retcode=3)
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
853
        self.runbzr('resolve --all')
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
854
        result = self.runbzr('conflicts', backtick=1)
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
855
        self.runbzr('commit -m conflicts')
1185.14.9 by Aaron Bentley
Added tests for 'bzr conflicts', 'bzr resolve'
856
        self.assertEquals(result, "")
1185.3.20 by Martin Pool
- run_bzr_captured also includes logged errors in
857
1442.1.59 by Robert Collins
Add re-sign command to generate a digital signature on a single revision.
858
    def test_resign(self):
859
        """Test re signing of data."""
860
        import bzrlib.gpg
861
        oldstrategy = bzrlib.gpg.GPGStrategy
862
        branch = Branch.initialize('.')
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
863
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
1442.1.59 by Robert Collins
Add re-sign command to generate a digital signature on a single revision.
864
        try:
865
            # monkey patch gpg signing mechanism
866
            from bzrlib.testament import Testament
867
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
868
            self.runbzr('re-sign -r revid:A')
869
            self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
870
                             branch.revision_store.get('A', 'sig').read())
871
        finally:
872
            bzrlib.gpg.GPGStrategy = oldstrategy
1483 by Robert Collins
BUGFIX: re-sign should accept ranges
873
            
874
    def test_resign_range(self):
875
        import bzrlib.gpg
876
        oldstrategy = bzrlib.gpg.GPGStrategy
877
        branch = Branch.initialize('.')
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
878
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
879
        branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
880
        branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
1483 by Robert Collins
BUGFIX: re-sign should accept ranges
881
        try:
882
            # monkey patch gpg signing mechanism
883
            from bzrlib.testament import Testament
884
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
885
            self.runbzr('re-sign -r 1..')
886
            self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
887
                             branch.revision_store.get('A', 'sig').read())
888
            self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
889
                             branch.revision_store.get('B', 'sig').read())
890
            self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
891
                             branch.revision_store.get('C', 'sig').read())
892
        finally:
893
            bzrlib.gpg.GPGStrategy = oldstrategy
894
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
895
    def test_push(self):
896
        # create a source branch
897
        os.mkdir('my-branch')
898
        os.chdir('my-branch')
899
        self.example_branch()
900
901
        # with no push target, fail
1185.35.21 by Aaron Bentley
Changed error status to 3
902
        self.runbzr('push', retcode=3)
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
903
        # with an explicit target work
904
        self.runbzr('push ../output-branch')
905
        # with an implicit target work
906
        self.runbzr('push')
907
        # nothing missing
908
        self.runbzr('missing ../output-branch')
909
        # advance this branch
910
        self.runbzr('commit --unchanged -m unchanged')
911
912
        os.chdir('../output-branch')
1185.50.6 by John Arbash Meinel
Fixed a broken test from my 'push updates local working tree' fix
913
        # There is no longer a difference as long as we have
914
        # access to the working tree
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
915
        self.runbzr('diff')
1185.50.6 by John Arbash Meinel
Fixed a broken test from my 'push updates local working tree' fix
916
917
        # But we should be missing a revision
918
        self.runbzr('missing ../my-branch', retcode=1)
919
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
920
        # diverge the branches
921
        self.runbzr('commit --unchanged -m unchanged')
922
        os.chdir('../my-branch')
923
        # cannot push now
1185.35.21 by Aaron Bentley
Changed error status to 3
924
        self.runbzr('push', retcode=3)
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
925
        # and there are difference
926
        self.runbzr('missing ../output-branch', retcode=1)
1185.35.30 by Aaron Bentley
Fixed missing --verbose
927
        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.
928
        # but we can force a push
929
        self.runbzr('push --overwrite')
930
        # nothing missing
931
        self.runbzr('missing ../output-branch')
1495 by Robert Collins
Add a --create-prefix to the new push command.
932
        
933
        # pushing to a new dir with no parent should fail
1185.35.21 by Aaron Bentley
Changed error status to 3
934
        self.runbzr('push ../missing/new-branch', retcode=3)
1495 by Robert Collins
Add a --create-prefix to the new push command.
935
        # unless we provide --create-prefix
936
        self.runbzr('push --create-prefix ../missing/new-branch')
937
        # nothing missing
938
        self.runbzr('missing ../missing/new-branch')
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
939
1185.31.3 by John Arbash Meinel
Fix ExternalCommand to not run random files in the current directory, unless it is truly in BZRPATH
940
    def test_external_command(self):
941
        """test that external commands can be run by setting the path"""
942
        cmd_name = 'test-command'
943
        output = 'Hello from test-command'
944
        if sys.platform == 'win32':
945
            cmd_name += '.bat'
946
            output += '\r\n'
947
        else:
948
            output += '\n'
949
950
        oldpath = os.environ.get('BZRPATH', None)
951
952
        bzr = self.capture
953
954
        try:
955
            if os.environ.has_key('BZRPATH'):
956
                del os.environ['BZRPATH']
957
958
            f = file(cmd_name, 'wb')
959
            if sys.platform == 'win32':
960
                f.write('@echo off\n')
961
            else:
962
                f.write('#!/bin/sh\n')
963
            f.write('echo Hello from test-command')
964
            f.close()
965
            os.chmod(cmd_name, 0755)
966
967
            # It should not find the command in the local 
968
            # directory by default, since it is not in my path
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
969
            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
970
971
            # Now put it into my path
972
            os.environ['BZRPATH'] = '.'
973
974
            bzr(cmd_name)
975
            # The test suite does not capture stdout for external commands
976
            # this is because you have to have a real file object
977
            # to pass to Popen(stdout=FOO), and StringIO is not one of those.
978
            # (just replacing sys.stdout does not change a spawned objects stdout)
979
            #self.assertEquals(bzr(cmd_name), output)
980
981
            # Make sure empty path elements are ignored
982
            os.environ['BZRPATH'] = os.pathsep
983
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
984
            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
985
986
        finally:
987
            if oldpath:
988
                os.environ['BZRPATH'] = oldpath
989
990
1092.2.6 by Robert Collins
symlink support updated to work
991
def listdir_sorted(dir):
992
    L = os.listdir(dir)
993
    L.sort()
994
    return L
1185.3.20 by Martin Pool
- run_bzr_captured also includes logged errors in
995
1092.2.12 by Robert Collins
merge from HEAD
996
904 by Martin Pool
- more selftest external-command fixes
997
class OldTests(ExternalBase):
1092.1.39 by Robert Collins
merge from mpool
998
    """old tests moved from ./testbzr."""
999
1102 by Martin Pool
- merge test refactoring from robertc
1000
    def test_bzr(self):
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1001
        from os import chdir, mkdir
1002
        from os.path import exists
1003
904 by Martin Pool
- more selftest external-command fixes
1004
        runbzr = self.runbzr
1185.3.26 by Martin Pool
- remove remaining external executions of bzr
1005
        capture = self.capture
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1006
        progress = self.log
1007
1008
        progress("basic branch creation")
904 by Martin Pool
- more selftest external-command fixes
1009
        mkdir('branch1')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1010
        chdir('branch1')
898 by Martin Pool
- add new runbzr method for external tests
1011
        runbzr('init')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1012
1185.3.25 by Martin Pool
- run blackbox tests in-process
1013
        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 \
1014
                          pathjoin(self.test_dir, 'branch1'))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1015
1016
        progress("status of new file")
1017
1018
        f = file('test.txt', 'wt')
1019
        f.write('hello world!\n')
1020
        f.close()
1021
1185.3.25 by Martin Pool
- run blackbox tests in-process
1022
        self.assertEquals(capture('unknowns'), 'test.txt\n')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1023
1185.3.25 by Martin Pool
- run blackbox tests in-process
1024
        out = capture("status")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1025
        self.assertEquals(out, 'unknown:\n  test.txt\n')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1026
1185.3.25 by Martin Pool
- run blackbox tests in-process
1027
        out = capture("status --all")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1028
        self.assertEquals(out, "unknown:\n  test.txt\n")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1029
1185.3.25 by Martin Pool
- run blackbox tests in-process
1030
        out = capture("status test.txt --all")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1031
        self.assertEquals(out, "unknown:\n  test.txt\n")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1032
1033
        f = file('test2.txt', 'wt')
1034
        f.write('goodbye cruel world...\n')
1035
        f.close()
1036
1185.3.25 by Martin Pool
- run blackbox tests in-process
1037
        out = capture("status test.txt")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1038
        self.assertEquals(out, "unknown:\n  test.txt\n")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1039
1185.3.25 by Martin Pool
- run blackbox tests in-process
1040
        out = capture("status")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1041
        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
1042
1043
        os.unlink('test2.txt')
1044
1045
        progress("command aliases")
1185.3.25 by Martin Pool
- run blackbox tests in-process
1046
        out = capture("st --all")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1047
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1048
1185.3.25 by Martin Pool
- run blackbox tests in-process
1049
        out = capture("stat")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1050
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1051
1052
        progress("command help")
898 by Martin Pool
- add new runbzr method for external tests
1053
        runbzr("help st")
1054
        runbzr("help")
1055
        runbzr("help commands")
1185.35.21 by Aaron Bentley
Changed error status to 3
1056
        runbzr("help slartibartfast", 3)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1057
1185.3.25 by Martin Pool
- run blackbox tests in-process
1058
        out = capture("help ci")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1059
        out.index('aliases: ')
1060
1061
        progress("can't rename unversioned file")
1185.35.21 by Aaron Bentley
Changed error status to 3
1062
        runbzr("rename test.txt new-test.txt", 3)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1063
1064
        progress("adding a file")
1065
898 by Martin Pool
- add new runbzr method for external tests
1066
        runbzr("add test.txt")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1067
        self.assertEquals(capture("unknowns"), '')
1068
        self.assertEquals(capture("status --all"), ("added:\n" "  test.txt\n"))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1069
1070
        progress("rename newly-added file")
898 by Martin Pool
- add new runbzr method for external tests
1071
        runbzr("rename test.txt hello.txt")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1072
        self.assert_(os.path.exists("hello.txt"))
1073
        self.assert_(not os.path.exists("test.txt"))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1074
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1075
        self.assertEquals(capture("revno"), '0\n')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1076
1077
        progress("add first revision")
904 by Martin Pool
- more selftest external-command fixes
1078
        runbzr(['commit', '-m', 'add first revision'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1079
1080
        progress("more complex renames")
1081
        os.mkdir("sub1")
1185.35.21 by Aaron Bentley
Changed error status to 3
1082
        runbzr("rename hello.txt sub1", 3)
1083
        runbzr("rename hello.txt sub1/hello.txt", 3)
1084
        runbzr("move hello.txt sub1", 3)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1085
898 by Martin Pool
- add new runbzr method for external tests
1086
        runbzr("add sub1")
1087
        runbzr("rename sub1 sub2")
1088
        runbzr("move hello.txt sub2")
1457.1.4 by Robert Collins
Branch.relpath has been moved to WorkingTree.relpath.
1089
        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 \
1090
                         pathjoin("sub2", "hello.txt\n"))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1091
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1092
        self.assert_(exists("sub2"))
1093
        self.assert_(exists("sub2/hello.txt"))
1094
        self.assert_(not exists("sub1"))
1095
        self.assert_(not exists("hello.txt"))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1096
898 by Martin Pool
- add new runbzr method for external tests
1097
        runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1098
1099
        mkdir("sub1")
898 by Martin Pool
- add new runbzr method for external tests
1100
        runbzr('add sub1')
1101
        runbzr('move sub2/hello.txt sub1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1102
        self.assert_(not exists('sub2/hello.txt'))
1103
        self.assert_(exists('sub1/hello.txt'))
898 by Martin Pool
- add new runbzr method for external tests
1104
        runbzr('move sub2 sub1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1105
        self.assert_(not exists('sub2'))
1106
        self.assert_(exists('sub1/sub2'))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1107
898 by Martin Pool
- add new runbzr method for external tests
1108
        runbzr(['commit', '-m', 'rename nested subdirectories'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1109
1110
        chdir('sub1/sub2')
1185.3.25 by Martin Pool
- run blackbox tests in-process
1111
        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 \
1112
                          pathjoin(self.test_dir, 'branch1'))
898 by Martin Pool
- add new runbzr method for external tests
1113
        runbzr('move ../hello.txt .')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1114
        self.assert_(exists('./hello.txt'))
1185.3.25 by Martin Pool
- run blackbox tests in-process
1115
        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 \
1116
                          pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
1117
        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
1118
        runbzr(['commit', '-m', 'move to parent directory'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1119
        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 \
1120
        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
1121
898 by Martin Pool
- add new runbzr method for external tests
1122
        runbzr('move sub2/hello.txt .')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1123
        self.assert_(exists('hello.txt'))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1124
1125
        f = file('hello.txt', 'wt')
1126
        f.write('some nice new content\n')
1127
        f.close()
1128
1129
        f = file('msg.tmp', 'wt')
1185.12.25 by Aaron Bentley
Added one-line log format
1130
        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
1131
        f.close()
1132
898 by Martin Pool
- add new runbzr method for external tests
1133
        runbzr('commit -F msg.tmp')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1134
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1135
        self.assertEquals(capture('revno'), '5\n')
898 by Martin Pool
- add new runbzr method for external tests
1136
        runbzr('export -r 5 export-5.tmp')
1137
        runbzr('export export.tmp')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1138
898 by Martin Pool
- add new runbzr method for external tests
1139
        runbzr('log')
1140
        runbzr('log -v')
909.1.5 by Aaron Bentley
Fixed log -v (mostly)
1141
        runbzr('log -v --forward')
1185.35.21 by Aaron Bentley
Changed error status to 3
1142
        runbzr('log -m', retcode=3)
1185.3.25 by Martin Pool
- run blackbox tests in-process
1143
        log_out = capture('log -m commit')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1144
        self.assert_("this is my new commit\n  and" in log_out)
1145
        self.assert_("rename nested" not in log_out)
1146
        self.assert_('revision-id' not in log_out)
1147
        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
1148
1185.12.25 by Aaron Bentley
Added one-line log format
1149
        log_out = capture('log --line')
1150
        for line in log_out.splitlines():
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1151
            self.assert_(len(line) <= 79, len(line))
1152
        self.assert_("this is my new commit and" in log_out)
1185.12.25 by Aaron Bentley
Added one-line log format
1153
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
1154
1155
        progress("file with spaces in name")
1156
        mkdir('sub directory')
1157
        file('sub directory/file with spaces ', 'wt').write('see how this works\n')
898 by Martin Pool
- add new runbzr method for external tests
1158
        runbzr('add .')
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
1159
        runbzr('diff', retcode=1)
898 by Martin Pool
- add new runbzr method for external tests
1160
        runbzr('commit -m add-spaces')
1161
        runbzr('check')
1162
1163
        runbzr('log')
1164
        runbzr('log --forward')
1165
1166
        runbzr('info')
1092.1.35 by Robert Collins
merge from mpool up to rev 1110
1167
1092.2.6 by Robert Collins
symlink support updated to work
1168
        if has_symlinks():
1169
            progress("symlinks")
1170
            mkdir('symlinks')
1171
            chdir('symlinks')
1172
            runbzr('init')
1173
            os.symlink("NOWHERE1", "link1")
1174
            runbzr('add link1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1175
            self.assertEquals(self.capture('unknowns'), '')
1092.2.6 by Robert Collins
symlink support updated to work
1176
            runbzr(['commit', '-m', '1: added symlink link1'])
1177
    
1178
            mkdir('d1')
1179
            runbzr('add d1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1180
            self.assertEquals(self.capture('unknowns'), '')
1092.2.6 by Robert Collins
symlink support updated to work
1181
            os.symlink("NOWHERE2", "d1/link2")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1182
            self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
1092.2.6 by Robert Collins
symlink support updated to work
1183
            # is d1/link2 found when adding d1
1184
            runbzr('add d1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1185
            self.assertEquals(self.capture('unknowns'), '')
1092.2.6 by Robert Collins
symlink support updated to work
1186
            os.symlink("NOWHERE3", "d1/link3")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1187
            self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
1092.2.6 by Robert Collins
symlink support updated to work
1188
            runbzr(['commit', '-m', '2: added dir, symlink'])
1189
    
1190
            runbzr('rename d1 d2')
1191
            runbzr('move d2/link2 .')
1192
            runbzr('move link1 d2')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1193
            self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1194
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1092.2.6 by Robert Collins
symlink support updated to work
1195
            runbzr('add d2/link3')
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
1196
            runbzr('diff', retcode=1)
1092.2.6 by Robert Collins
symlink support updated to work
1197
            runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1198
    
1199
            os.unlink("link2")
1200
            os.symlink("TARGET 2", "link2")
1201
            os.unlink("d2/link1")
1202
            os.symlink("TARGET 1", "d2/link1")
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
1203
            runbzr('diff', retcode=1)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1204
            self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
1092.2.6 by Robert Collins
symlink support updated to work
1205
            runbzr(['commit', '-m', '4: retarget of two links'])
1206
    
1207
            runbzr('remove d2/link1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1208
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1092.2.20 by Robert Collins
symlink and weaves, whaddya know
1209
            runbzr(['commit', '-m', '5: remove d2/link1'])
1424 by Robert Collins
add rm alias to remove
1210
            # try with the rm alias
1211
            runbzr('add d2/link1')
1212
            runbzr(['commit', '-m', '6: add d2/link1'])
1213
            runbzr('rm d2/link1')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1214
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1424 by Robert Collins
add rm alias to remove
1215
            runbzr(['commit', '-m', '7: remove d2/link1'])
1092.2.6 by Robert Collins
symlink support updated to work
1216
    
1217
            os.mkdir("d1")
1218
            runbzr('add d1')
1219
            runbzr('rename d2/link3 d1/link3new')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1220
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1424 by Robert Collins
add rm alias to remove
1221
            runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1092.2.6 by Robert Collins
symlink support updated to work
1222
            
1223
            runbzr(['check'])
1224
            
1225
            runbzr(['export', '-r', '1', 'exp1.tmp'])
1226
            chdir("exp1.tmp")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1227
            self.assertEquals(listdir_sorted("."), [ "link1" ])
1228
            self.assertEquals(os.readlink("link1"), "NOWHERE1")
1092.2.6 by Robert Collins
symlink support updated to work
1229
            chdir("..")
1230
            
1231
            runbzr(['export', '-r', '2', 'exp2.tmp'])
1232
            chdir("exp2.tmp")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1233
            self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
1092.2.6 by Robert Collins
symlink support updated to work
1234
            chdir("..")
1235
            
1236
            runbzr(['export', '-r', '3', 'exp3.tmp'])
1237
            chdir("exp3.tmp")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1238
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1239
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1240
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1241
            self.assertEquals(os.readlink("link2")   , "NOWHERE2")
1092.2.6 by Robert Collins
symlink support updated to work
1242
            chdir("..")
1243
            
1244
            runbzr(['export', '-r', '4', 'exp4.tmp'])
1245
            chdir("exp4.tmp")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1246
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1247
            self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1248
            self.assertEquals(os.readlink("link2")   , "TARGET 2")
1249
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1092.2.6 by Robert Collins
symlink support updated to work
1250
            chdir("..")
1251
            
1252
            runbzr(['export', '-r', '5', 'exp5.tmp'])
1253
            chdir("exp5.tmp")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1254
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1255
            self.assert_(os.path.islink("link2"))
1256
            self.assert_(listdir_sorted("d2")== [ "link3" ])
1092.2.6 by Robert Collins
symlink support updated to work
1257
            chdir("..")
1258
            
1424 by Robert Collins
add rm alias to remove
1259
            runbzr(['export', '-r', '8', 'exp6.tmp'])
1092.2.6 by Robert Collins
symlink support updated to work
1260
            chdir("exp6.tmp")
1424 by Robert Collins
add rm alias to remove
1261
            self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
1262
            self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1263
            self.assertEquals(listdir_sorted("d2"), [])
1264
            self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
1092.2.6 by Robert Collins
symlink support updated to work
1265
            chdir("..")
1266
        else:
1267
            progress("skipping symlink tests")
1400.1.1 by Robert Collins
implement a basic test for the ui branch command from http servers
1268
1269
1524.1.1 by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir
1270
class RemoteTests(object):
1400.1.1 by Robert Collins
implement a basic test for the ui branch command from http servers
1271
    """Test bzr ui commands against remote branches."""
1272
1273
    def test_branch(self):
1274
        os.mkdir('from')
1275
        branch = Branch.initialize('from')
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
1276
        branch.working_tree().commit('empty commit for nonsense', allow_pointless=True)
1400.1.1 by Robert Collins
implement a basic test for the ui branch command from http servers
1277
        url = self.get_remote_url('from')
1278
        self.run_bzr('branch', url, 'to')
1279
        branch = Branch.open('to')
1280
        self.assertEqual(1, len(branch.revision_history()))
1185.16.48 by mbp at sourcefrog
- more refactoring of and tests for option parsing
1281
1442.1.64 by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path).
1282
    def test_log(self):
1283
        self.build_tree(['branch/', 'branch/file'])
1284
        branch = Branch.initialize('branch')
1508.1.5 by Robert Collins
Move add from Branch to WorkingTree.
1285
        branch.working_tree().add(['file'])
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
1286
        branch.working_tree().commit('add file', rev_id='A')
1442.1.64 by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path).
1287
        url = self.get_remote_url('branch/file')
1288
        output = self.capture('log %s' % url)
1185.35.17 by Aaron Bentley
Added branch nicks to long-format logs
1289
        self.assertEqual(8, len(output.split('\n')))
1442.1.64 by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path).
1290
        
1510 by Robert Collins
Merge from mpool, adjusting check to retain HTTP support.
1291
    def test_check(self):
1292
        self.build_tree(['branch/', 'branch/file'])
1293
        branch = Branch.initialize('branch')
1512 by Robert Collins
Merge from Martin. Adjust check to work with HTTP again.
1294
        branch.working_tree().add(['file'])
1510 by Robert Collins
Merge from mpool, adjusting check to retain HTTP support.
1295
        branch.working_tree().commit('add file', rev_id='A')
1512 by Robert Collins
Merge from Martin. Adjust check to work with HTTP again.
1296
        url = self.get_remote_url('branch/')
1510 by Robert Collins
Merge from mpool, adjusting check to retain HTTP support.
1297
        self.run_bzr('check', url)
1524.1.1 by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir
1298
    
1299
    
1300
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1301
    """Test various commands against a HTTP server."""
1302
    
1303
    
1304
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
1305
    """Test various commands against a SFTP server using abs paths."""
1306
1307
    
1308
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
1309
    """Test various commands against a SFTP server using abs paths."""
1310
1311
    def setUp(self):
1312
        super(SFTPTestsAbsoluteSibling, self).setUp()
1313
        self._override_home = '/dev/noone/runs/tests/here'
1314
1315
    
1316
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
1317
    """Test various commands against a SFTP server using homedir rel paths."""
1318
1319
    def setUp(self):
1320
        super(SFTPTestsRelative, self).setUp()
1321
        self._get_remote_is_absolute = False