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