~bzr-pqm/bzr/bzr.dev

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