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