/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
22
command-line interface.
725 by Martin Pool
doc
23
24
This always reinvokes bzr through a new Python interpreter, which is a
25
bit inefficient but arguably tests in a way more representative of how
26
it's normally invoked.
720 by Martin Pool
- start moving external tests into the testsuite framework
27
"""
28
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
29
import sys
974.1.71 by Aaron Bentley
Added test for pull
30
import os
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
31
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
32
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
33
from bzrlib.branch import Branch
34
from bzrlib.commands import run_bzr
35
898 by Martin Pool
- add new runbzr method for external tests
36
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
37
class ExternalBase(TestCaseInTempDir):
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
38
    def runbzr(self, args, retcode=0,backtick=False):
898 by Martin Pool
- add new runbzr method for external tests
39
        if isinstance(args, basestring):
40
            args = args.split()
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
41
42
        if backtick:
43
            return self.backtick(['python', self.BZRPATH,] + args,
44
                           retcode=retcode)
45
        else:
46
            return self.runcmd(['python', self.BZRPATH,] + args,
904 by Martin Pool
- more selftest external-command fixes
47
                           retcode=retcode)
48
1142 by Martin Pool
- remove dead code from blackbox tests (pychecker)
49
1102 by Martin Pool
- merge test refactoring from robertc
50
class TestCommands(ExternalBase):
51
52
    def test_help_commands(self):
898 by Martin Pool
- add new runbzr method for external tests
53
        self.runbzr('--help')
54
        self.runbzr('help')
55
        self.runbzr('help commands')
56
        self.runbzr('help help')
57
        self.runbzr('commit -h')
727 by Martin Pool
- move more code to run external commands from testbzr to selftest
58
1102 by Martin Pool
- merge test refactoring from robertc
59
    def test_init_branch(self):
898 by Martin Pool
- add new runbzr method for external tests
60
        self.runbzr(['init'])
732 by Martin Pool
- move more tests into bzr selftest
61
1102 by Martin Pool
- merge test refactoring from robertc
62
    def test_whoami(self):
732 by Martin Pool
- move more tests into bzr selftest
63
        # this should always identify something, if only "john@localhost"
898 by Martin Pool
- add new runbzr method for external tests
64
        self.runbzr("whoami")
65
        self.runbzr("whoami --email")
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
66
67
        self.assertEquals(self.runbzr("whoami --email",
68
                                      backtick=True).count('@'), 1)
69
        
1102 by Martin Pool
- merge test refactoring from robertc
70
    def test_whoami_branch(self):
71
        """branch specific user identity works."""
1074 by Martin Pool
- check for email address in BRANCH_ROOT/.bzr/email, so you can
72
        self.runbzr('init')
73
        f = file('.bzr/email', 'wt')
74
        f.write('Branch Identity <branch@identi.ty>')
75
        f.close()
76
        whoami = self.runbzr("whoami",backtick=True)
77
        whoami_email = self.runbzr("whoami --email",backtick=True)
78
        self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
79
        self.assertTrue(whoami_email.startswith('branch@identi.ty'))
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
80
1102 by Martin Pool
- merge test refactoring from robertc
81
    def test_invalid_commands(self):
898 by Martin Pool
- add new runbzr method for external tests
82
        self.runbzr("pants", retcode=1)
83
        self.runbzr("--pants off", retcode=1)
84
        self.runbzr("diff --message foo", retcode=1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
85
1102 by Martin Pool
- merge test refactoring from robertc
86
    def test_empty_commit(self):
898 by Martin Pool
- add new runbzr method for external tests
87
        self.runbzr("init")
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
88
        self.build_tree(['hello.txt'])
898 by Martin Pool
- add new runbzr method for external tests
89
        self.runbzr("commit -m empty", retcode=1)
90
        self.runbzr("add hello.txt")
91
        self.runbzr("commit -m added")
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
92
1102 by Martin Pool
- merge test refactoring from robertc
93
    def test_ignore_patterns(self):
906 by Martin Pool
- split out black-box ignore commands
94
        from bzrlib.branch import Branch
95
        
96
        b = Branch('.', init=True)
97
        self.assertEquals(list(b.unknowns()), [])
98
99
        file('foo.tmp', 'wt').write('tmp files are ignored')
100
        self.assertEquals(list(b.unknowns()), [])
101
        assert self.backtick('bzr unknowns') == ''
102
103
        file('foo.c', 'wt').write('int main() {}')
104
        self.assertEquals(list(b.unknowns()), ['foo.c'])
105
        assert self.backtick('bzr unknowns') == 'foo.c\n'
106
107
        self.runbzr(['add', 'foo.c'])
108
        assert self.backtick('bzr unknowns') == ''
109
110
        # 'ignore' works when creating the .bzignore file
111
        file('foo.blah', 'wt').write('blah')
112
        self.assertEquals(list(b.unknowns()), ['foo.blah'])
113
        self.runbzr('ignore *.blah')
114
        self.assertEquals(list(b.unknowns()), [])
115
        assert file('.bzrignore', 'rb').read() == '*.blah\n'
116
117
        # 'ignore' works when then .bzrignore file already exists
118
        file('garh', 'wt').write('garh')
119
        self.assertEquals(list(b.unknowns()), ['garh'])
120
        assert self.backtick('bzr unknowns') == 'garh\n'
121
        self.runbzr('ignore garh')
122
        self.assertEquals(list(b.unknowns()), [])
123
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
1102 by Martin Pool
- merge test refactoring from robertc
124
125
    def test_revert(self):
126
        self.runbzr('init')
127
128
        file('hello', 'wt').write('foo')
129
        self.runbzr('add hello')
130
        self.runbzr('commit -m setup hello')
131
132
        file('goodbye', 'wt').write('baz')
133
        self.runbzr('add goodbye')
134
        self.runbzr('commit -m setup goodbye')
1092.1.14 by Robert Collins
relace runTest with test_foo in blackbox tests
135
        
1102 by Martin Pool
- merge test refactoring from robertc
136
        file('hello', 'wt').write('bar')
137
        file('goodbye', 'wt').write('qux')
138
        self.runbzr('revert hello')
139
        self.check_file_contents('hello', 'foo')
140
        self.check_file_contents('goodbye', 'qux')
141
        self.runbzr('revert')
142
        self.check_file_contents('goodbye', 'baz')
143
144
        os.mkdir('revertdir')
145
        self.runbzr('add revertdir')
146
        self.runbzr('commit -m f')
147
        os.rmdir('revertdir')
148
        self.runbzr('revert')
149
150
    def skipped_test_mv_modes(self):
151
        """Test two modes of operation for mv"""
152
        from bzrlib.branch import Branch
153
        b = Branch('.', init=True)
154
        self.build_tree(['a', 'c', 'subdir/'])
155
        self.run_bzr('mv', 'a', 'b')
156
        self.run_bzr('mv', 'b', 'subdir')
157
        self.run_bzr('mv', 'subdir/b', 'a')
158
        self.run_bzr('mv', 'a', 'b', 'subdir')
159
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
160
161
    def test_main_version(self):
162
        """Check output from version command and master option is reasonable"""
163
        # output is intentionally passed through to stdout so that we
164
        # can see the version being tested
165
        output = self.runbzr('version', backtick=1)
166
        self.log('bzr version output:')
167
        self.log(output)
168
        self.assert_(output.startswith('bzr (bazaar-ng) '))
169
        self.assertNotEqual(output.index('Canonical'), -1)
170
        # make sure --version is consistent
171
        tmp_output = self.runbzr('--version', backtick=1)
172
        self.log('bzr --version output:')
173
        self.log(tmp_output)
174
        self.assertEquals(output, tmp_output)
906 by Martin Pool
- split out black-box ignore commands
175
1092.1.39 by Robert Collins
merge from mpool
176
    def example_branch(test):
177
        test.runbzr('init')
178
        file('hello', 'wt').write('foo')
179
        test.runbzr('add hello')
180
        test.runbzr('commit -m setup hello')
181
        file('goodbye', 'wt').write('baz')
182
        test.runbzr('add goodbye')
183
        test.runbzr('commit -m setup goodbye')
184
185
    def test_revert(self):
186
        self.example_branch()
187
        file('hello', 'wt').write('bar')
188
        file('goodbye', 'wt').write('qux')
189
        self.runbzr('revert hello')
190
        self.check_file_contents('hello', 'foo')
191
        self.check_file_contents('goodbye', 'qux')
192
        self.runbzr('revert')
193
        self.check_file_contents('goodbye', 'baz')
194
195
    def test_merge(self):
196
        from bzrlib.branch import Branch
1139 by Martin Pool
- merge in merge improvements and additional tests
197
        
1092.1.39 by Robert Collins
merge from mpool
198
        os.mkdir('a')
199
        os.chdir('a')
1139 by Martin Pool
- merge in merge improvements and additional tests
200
1092.1.39 by Robert Collins
merge from mpool
201
        self.example_branch()
202
        os.chdir('..')
203
        self.runbzr('branch a b')
204
        os.chdir('b')
205
        file('goodbye', 'wt').write('quux')
206
        self.runbzr(['commit',  '-m',  "more u's are always good"])
207
208
        os.chdir('../a')
209
        file('hello', 'wt').write('quuux')
210
        # We can't merge when there are in-tree changes
211
        self.runbzr('merge ../b', retcode=1)
212
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
213
        self.runbzr('merge ../b')
214
        self.check_file_contents('goodbye', 'quux')
215
        # Merging a branch pulls its revision into the tree
216
        a = Branch('.')
217
        b = Branch('../b')
218
        a.get_revision_xml(b.last_patch())
1139 by Martin Pool
- merge in merge improvements and additional tests
219
220
        self.log('pending merges: %s', a.pending_merges())
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
221
        #        assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
222
        #        % (a.pending_merges(), b.last_patch())
223
974.1.71 by Aaron Bentley
Added test for pull
224
    def test_pull(self):
225
        """Pull changes from one branch to another."""
226
        os.mkdir('a')
227
        os.chdir('a')
228
229
        self.example_branch()
230
        os.chdir('..')
231
        self.runbzr('branch a b')
232
        os.chdir('b')
233
        self.runbzr('commit -m blah --unchanged')
234
        os.chdir('../a')
235
        a = Branch('.')
236
        b = Branch('../b')
237
        assert a.revision_history() == b.revision_history()[:-1]
238
        self.runbzr('pull ../b')
239
        assert a.revision_history() == b.revision_history()
240
        self.runbzr('commit -m blah2 --unchanged')
241
        os.chdir('../b')
242
        self.runbzr('commit -m blah3 --unchanged')
243
        self.runbzr('pull ../a', retcode=1)
974.1.74 by Aaron Bentley
Made pull work after remote branch has merged latest revision
244
        os.chdir('../a')
245
        self.runbzr('merge ../b')
246
        self.runbzr('commit -m blah4 --unchanged')
247
        os.chdir('../b')
248
        self.runbzr('pull ../a')
249
        assert a.revision_history()[-1] == b.revision_history()[-1]
250
        
1161 by Martin Pool
- add test that 'bzr add' reports the files as they're added
251
252
    def test_add_reports(self):
253
        """add command prints the names of added files."""
254
        b = Branch('.', init=True)
255
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
256
257
        from cStringIO import StringIO
258
        out = StringIO()
259
260
        ret = self.apply_redirected(None, out, None,
261
                                    run_bzr,
262
                                    ['add'])
263
        self.assertEquals(ret, 0)
264
265
        # the ordering is not defined at the moment
266
        results = sorted(out.getvalue().rstrip('\n').split('\n'))
267
        self.assertEquals(['added dir',
268
                           'added dir/sub.txt',
269
                           'added top.txt',],
270
                          results)
271
1092.1.39 by Robert Collins
merge from mpool
272
904 by Martin Pool
- more selftest external-command fixes
273
class OldTests(ExternalBase):
1092.1.39 by Robert Collins
merge from mpool
274
    """old tests moved from ./testbzr."""
275
1102 by Martin Pool
- merge test refactoring from robertc
276
    def test_bzr(self):
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
277
        from os import chdir, mkdir
278
        from os.path import exists
279
904 by Martin Pool
- more selftest external-command fixes
280
        runbzr = self.runbzr
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
281
        backtick = self.backtick
282
        progress = self.log
283
284
        progress("basic branch creation")
904 by Martin Pool
- more selftest external-command fixes
285
        mkdir('branch1')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
286
        chdir('branch1')
898 by Martin Pool
- add new runbzr method for external tests
287
        runbzr('init')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
288
289
        self.assertEquals(backtick('bzr root').rstrip(),
290
                          os.path.join(self.test_dir, 'branch1'))
291
292
        progress("status of new file")
293
294
        f = file('test.txt', 'wt')
295
        f.write('hello world!\n')
296
        f.close()
297
298
        out = backtick("bzr unknowns")
780 by Martin Pool
- test message improvement
299
        self.assertEquals(out, 'test.txt\n')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
300
301
        out = backtick("bzr status")
302
        assert out == 'unknown:\n  test.txt\n'
303
304
        out = backtick("bzr status --all")
305
        assert out == "unknown:\n  test.txt\n"
306
307
        out = backtick("bzr status test.txt --all")
308
        assert out == "unknown:\n  test.txt\n"
309
310
        f = file('test2.txt', 'wt')
311
        f.write('goodbye cruel world...\n')
312
        f.close()
313
314
        out = backtick("bzr status test.txt")
315
        assert out == "unknown:\n  test.txt\n"
316
317
        out = backtick("bzr status")
318
        assert out == ("unknown:\n"
319
                       "  test.txt\n"
320
                       "  test2.txt\n")
321
322
        os.unlink('test2.txt')
323
324
        progress("command aliases")
325
        out = backtick("bzr st --all")
326
        assert out == ("unknown:\n"
327
                       "  test.txt\n")
328
329
        out = backtick("bzr stat")
330
        assert out == ("unknown:\n"
331
                       "  test.txt\n")
332
333
        progress("command help")
898 by Martin Pool
- add new runbzr method for external tests
334
        runbzr("help st")
335
        runbzr("help")
336
        runbzr("help commands")
337
        runbzr("help slartibartfast", 1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
338
339
        out = backtick("bzr help ci")
340
        out.index('aliases: ')
341
342
        progress("can't rename unversioned file")
898 by Martin Pool
- add new runbzr method for external tests
343
        runbzr("rename test.txt new-test.txt", 1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
344
345
        progress("adding a file")
346
898 by Martin Pool
- add new runbzr method for external tests
347
        runbzr("add test.txt")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
348
        assert backtick("bzr unknowns") == ''
349
        assert backtick("bzr status --all") == ("added:\n"
350
                                                "  test.txt\n")
351
352
        progress("rename newly-added file")
898 by Martin Pool
- add new runbzr method for external tests
353
        runbzr("rename test.txt hello.txt")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
354
        assert os.path.exists("hello.txt")
355
        assert not os.path.exists("test.txt")
356
357
        assert backtick("bzr revno") == '0\n'
358
359
        progress("add first revision")
904 by Martin Pool
- more selftest external-command fixes
360
        runbzr(['commit', '-m', 'add first revision'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
361
362
        progress("more complex renames")
363
        os.mkdir("sub1")
898 by Martin Pool
- add new runbzr method for external tests
364
        runbzr("rename hello.txt sub1", 1)
365
        runbzr("rename hello.txt sub1/hello.txt", 1)
366
        runbzr("move hello.txt sub1", 1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
367
898 by Martin Pool
- add new runbzr method for external tests
368
        runbzr("add sub1")
369
        runbzr("rename sub1 sub2")
370
        runbzr("move hello.txt sub2")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
371
        assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
372
373
        assert exists("sub2")
374
        assert exists("sub2/hello.txt")
375
        assert not exists("sub1")
376
        assert not exists("hello.txt")
377
898 by Martin Pool
- add new runbzr method for external tests
378
        runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
379
380
        mkdir("sub1")
898 by Martin Pool
- add new runbzr method for external tests
381
        runbzr('add sub1')
382
        runbzr('move sub2/hello.txt sub1')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
383
        assert not exists('sub2/hello.txt')
384
        assert exists('sub1/hello.txt')
898 by Martin Pool
- add new runbzr method for external tests
385
        runbzr('move sub2 sub1')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
386
        assert not exists('sub2')
387
        assert exists('sub1/sub2')
388
898 by Martin Pool
- add new runbzr method for external tests
389
        runbzr(['commit', '-m', 'rename nested subdirectories'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
390
391
        chdir('sub1/sub2')
392
        self.assertEquals(backtick('bzr root')[:-1],
393
                          os.path.join(self.test_dir, 'branch1'))
898 by Martin Pool
- add new runbzr method for external tests
394
        runbzr('move ../hello.txt .')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
395
        assert exists('./hello.txt')
396
        assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
397
        assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
898 by Martin Pool
- add new runbzr method for external tests
398
        runbzr(['commit', '-m', 'move to parent directory'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
399
        chdir('..')
400
        assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
401
898 by Martin Pool
- add new runbzr method for external tests
402
        runbzr('move sub2/hello.txt .')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
403
        assert exists('hello.txt')
404
405
        f = file('hello.txt', 'wt')
406
        f.write('some nice new content\n')
407
        f.close()
408
409
        f = file('msg.tmp', 'wt')
410
        f.write('this is my new commit\n')
411
        f.close()
412
898 by Martin Pool
- add new runbzr method for external tests
413
        runbzr('commit -F msg.tmp')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
414
415
        assert backtick('bzr revno') == '5\n'
898 by Martin Pool
- add new runbzr method for external tests
416
        runbzr('export -r 5 export-5.tmp')
417
        runbzr('export export.tmp')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
418
898 by Martin Pool
- add new runbzr method for external tests
419
        runbzr('log')
420
        runbzr('log -v')
909.1.5 by Aaron Bentley
Fixed log -v (mostly)
421
        runbzr('log -v --forward')
422
        runbzr('log -m', retcode=1)
423
        log_out = backtick('bzr log -m commit')
424
        assert "this is my new commit" in log_out
425
        assert "rename nested" not in log_out
426
        assert 'revision-id' not in log_out
427
        assert 'revision-id' in backtick('bzr log --show-ids -m commit')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
428
429
430
        progress("file with spaces in name")
431
        mkdir('sub directory')
432
        file('sub directory/file with spaces ', 'wt').write('see how this works\n')
898 by Martin Pool
- add new runbzr method for external tests
433
        runbzr('add .')
434
        runbzr('diff')
435
        runbzr('commit -m add-spaces')
436
        runbzr('check')
437
438
        runbzr('log')
439
        runbzr('log --forward')
440
441
        runbzr('info')
1092.1.35 by Robert Collins
merge from mpool up to rev 1110
442