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