/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
29
# this code was previously in testbzr
30
31
from unittest import TestCase
732 by Martin Pool
- move more tests into bzr selftest
32
from bzrlib.selftest import TestBase, InTempDir
721 by Martin Pool
- framework for running external commands from unittest suite
33
898 by Martin Pool
- add new runbzr method for external tests
34
35
36
class ExternalBase(TestBase):
37
    def runbzr(self, args):
38
        try:
39
            import shutil
40
            from subprocess import call
41
        except ImportError, e:
42
            _need_subprocess()
43
            raise
44
45
        if isinstance(args, basestring):
46
            args = args.split()
47
            
48
        return self.runcmd(['python', self.BZRPATH,] + args)
49
50
51
721 by Martin Pool
- framework for running external commands from unittest suite
52
class TestVersion(TestBase):
720 by Martin Pool
- start moving external tests into the testsuite framework
53
    def runTest(self):
721 by Martin Pool
- framework for running external commands from unittest suite
54
        # output is intentionally passed through to stdout so that we
55
        # can see the version being tested
898 by Martin Pool
- add new runbzr method for external tests
56
        self.runbzr(['version'])
726 by Martin Pool
- more rearrangement of blackbox tests
57
58
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
59
727 by Martin Pool
- move more code to run external commands from testbzr to selftest
60
class HelpCommands(TestBase):
61
    def runTest(self):
898 by Martin Pool
- add new runbzr method for external tests
62
        self.runbzr('--help')
63
        self.runbzr('help')
64
        self.runbzr('help commands')
65
        self.runbzr('help help')
66
        self.runbzr('commit -h')
727 by Martin Pool
- move more code to run external commands from testbzr to selftest
67
68
732 by Martin Pool
- move more tests into bzr selftest
69
class InitBranch(InTempDir):
726 by Martin Pool
- more rearrangement of blackbox tests
70
    def runTest(self):
71
        import os
898 by Martin Pool
- add new runbzr method for external tests
72
        self.runbzr(['init'])
732 by Martin Pool
- move more tests into bzr selftest
73
74
75
76
class UserIdentity(InTempDir):
77
    def runTest(self):
78
        # this should always identify something, if only "john@localhost"
898 by Martin Pool
- add new runbzr method for external tests
79
        self.runbzr("whoami")
80
        self.runbzr("whoami --email")
732 by Martin Pool
- move more tests into bzr selftest
81
        self.assertEquals(self.backtick("bzr whoami --email").count('@'),
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
82
                          1)
83
84
85
class InvalidCommands(InTempDir):
86
    def runTest(self):
898 by Martin Pool
- add new runbzr method for external tests
87
        self.runbzr("pants", retcode=1)
88
        self.runbzr("--pants off", retcode=1)
89
        self.runbzr("diff --message foo", retcode=1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
90
91
92
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
93
class EmptyCommit(InTempDir):
94
    def runTest(self):
898 by Martin Pool
- add new runbzr method for external tests
95
        self.runbzr("init")
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
96
        self.build_tree(['hello.txt'])
898 by Martin Pool
- add new runbzr method for external tests
97
        self.runbzr("commit -m empty", retcode=1)
98
        self.runbzr("add hello.txt")
99
        self.runbzr("commit -m added")
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
100
101
102
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
103
class OldTests(InTempDir):
104
    # old tests moved from ./testbzr
105
    def runTest(self):
106
        from os import chdir, mkdir
107
        from os.path import exists
108
        import os
109
110
        runcmd = self.runcmd
111
        backtick = self.backtick
112
        progress = self.log
113
114
        progress("basic branch creation")
115
        runcmd(['mkdir', 'branch1'])
116
        chdir('branch1')
898 by Martin Pool
- add new runbzr method for external tests
117
        runbzr('init')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
118
119
        self.assertEquals(backtick('bzr root').rstrip(),
120
                          os.path.join(self.test_dir, 'branch1'))
121
122
        progress("status of new file")
123
124
        f = file('test.txt', 'wt')
125
        f.write('hello world!\n')
126
        f.close()
127
128
        out = backtick("bzr unknowns")
780 by Martin Pool
- test message improvement
129
        self.assertEquals(out, 'test.txt\n')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
130
131
        out = backtick("bzr status")
132
        assert out == 'unknown:\n  test.txt\n'
133
134
        out = backtick("bzr status --all")
135
        assert out == "unknown:\n  test.txt\n"
136
137
        out = backtick("bzr status test.txt --all")
138
        assert out == "unknown:\n  test.txt\n"
139
140
        f = file('test2.txt', 'wt')
141
        f.write('goodbye cruel world...\n')
142
        f.close()
143
144
        out = backtick("bzr status test.txt")
145
        assert out == "unknown:\n  test.txt\n"
146
147
        out = backtick("bzr status")
148
        assert out == ("unknown:\n"
149
                       "  test.txt\n"
150
                       "  test2.txt\n")
151
152
        os.unlink('test2.txt')
153
154
        progress("command aliases")
155
        out = backtick("bzr st --all")
156
        assert out == ("unknown:\n"
157
                       "  test.txt\n")
158
159
        out = backtick("bzr stat")
160
        assert out == ("unknown:\n"
161
                       "  test.txt\n")
162
163
        progress("command help")
898 by Martin Pool
- add new runbzr method for external tests
164
        runbzr("help st")
165
        runbzr("help")
166
        runbzr("help commands")
167
        runbzr("help slartibartfast", 1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
168
169
        out = backtick("bzr help ci")
170
        out.index('aliases: ')
171
172
        progress("can't rename unversioned file")
898 by Martin Pool
- add new runbzr method for external tests
173
        runbzr("rename test.txt new-test.txt", 1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
174
175
        progress("adding a file")
176
898 by Martin Pool
- add new runbzr method for external tests
177
        runbzr("add test.txt")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
178
        assert backtick("bzr unknowns") == ''
179
        assert backtick("bzr status --all") == ("added:\n"
180
                                                "  test.txt\n")
181
182
        progress("rename newly-added file")
898 by Martin Pool
- add new runbzr method for external tests
183
        runbzr("rename test.txt hello.txt")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
184
        assert os.path.exists("hello.txt")
185
        assert not os.path.exists("test.txt")
186
187
        assert backtick("bzr revno") == '0\n'
188
189
        progress("add first revision")
190
        runcmd(["bzr", "commit", "-m", 'add first revision'])
191
192
        progress("more complex renames")
193
        os.mkdir("sub1")
898 by Martin Pool
- add new runbzr method for external tests
194
        runbzr("rename hello.txt sub1", 1)
195
        runbzr("rename hello.txt sub1/hello.txt", 1)
196
        runbzr("move hello.txt sub1", 1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
197
898 by Martin Pool
- add new runbzr method for external tests
198
        runbzr("add sub1")
199
        runbzr("rename sub1 sub2")
200
        runbzr("move hello.txt sub2")
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
201
        assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
202
203
        assert exists("sub2")
204
        assert exists("sub2/hello.txt")
205
        assert not exists("sub1")
206
        assert not exists("hello.txt")
207
898 by Martin Pool
- add new runbzr method for external tests
208
        runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
209
210
        mkdir("sub1")
898 by Martin Pool
- add new runbzr method for external tests
211
        runbzr('add sub1')
212
        runbzr('move sub2/hello.txt sub1')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
213
        assert not exists('sub2/hello.txt')
214
        assert exists('sub1/hello.txt')
898 by Martin Pool
- add new runbzr method for external tests
215
        runbzr('move sub2 sub1')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
216
        assert not exists('sub2')
217
        assert exists('sub1/sub2')
218
898 by Martin Pool
- add new runbzr method for external tests
219
        runbzr(['commit', '-m', 'rename nested subdirectories'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
220
221
        chdir('sub1/sub2')
222
        self.assertEquals(backtick('bzr root')[:-1],
223
                          os.path.join(self.test_dir, 'branch1'))
898 by Martin Pool
- add new runbzr method for external tests
224
        runbzr('move ../hello.txt .')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
225
        assert exists('./hello.txt')
226
        assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
227
        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
228
        runbzr(['commit', '-m', 'move to parent directory'])
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
229
        chdir('..')
230
        assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
231
898 by Martin Pool
- add new runbzr method for external tests
232
        runbzr('move sub2/hello.txt .')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
233
        assert exists('hello.txt')
234
235
        f = file('hello.txt', 'wt')
236
        f.write('some nice new content\n')
237
        f.close()
238
239
        f = file('msg.tmp', 'wt')
240
        f.write('this is my new commit\n')
241
        f.close()
242
898 by Martin Pool
- add new runbzr method for external tests
243
        runbzr('commit -F msg.tmp')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
244
245
        assert backtick('bzr revno') == '5\n'
898 by Martin Pool
- add new runbzr method for external tests
246
        runbzr('export -r 5 export-5.tmp')
247
        runbzr('export export.tmp')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
248
898 by Martin Pool
- add new runbzr method for external tests
249
        runbzr('log')
250
        runbzr('log -v')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
251
252
253
254
        progress("file with spaces in name")
255
        mkdir('sub directory')
256
        file('sub directory/file with spaces ', 'wt').write('see how this works\n')
898 by Martin Pool
- add new runbzr method for external tests
257
        runbzr('add .')
258
        runbzr('diff')
259
        runbzr('commit -m add-spaces')
260
        runbzr('check')
261
262
        runbzr('log')
263
        runbzr('log --forward')
264
265
        runbzr('info')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
266
267
268
269
270
271
272
        chdir('..')
273
        chdir('..')
274
        progress('branch')
275
        # Can't create a branch if it already exists
898 by Martin Pool
- add new runbzr method for external tests
276
        runbzr('branch branch1', retcode=1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
277
        # Can't create a branch if its parent doesn't exist
898 by Martin Pool
- add new runbzr method for external tests
278
        runbzr('branch /unlikely/to/exist', retcode=1)
279
        runbzr('branch branch1 branch2')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
280
281
        progress("pull")
282
        chdir('branch1')
898 by Martin Pool
- add new runbzr method for external tests
283
        runbzr('pull', retcode=1)
284
        runbzr('pull ../branch2')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
285
        chdir('.bzr')
898 by Martin Pool
- add new runbzr method for external tests
286
        runbzr('pull')
287
        runbzr('commit --unchanged -m empty')
288
        runbzr('pull')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
289
        chdir('../../branch2')
898 by Martin Pool
- add new runbzr method for external tests
290
        runbzr('pull')
291
        runbzr('commit --unchanged -m empty')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
292
        chdir('../branch1')
898 by Martin Pool
- add new runbzr method for external tests
293
        runbzr('commit --unchanged -m empty')
294
        runbzr('pull', retcode=1)
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
295
        chdir ('..')
296
297
        progress('status after remove')
298
        mkdir('status-after-remove')
299
        # see mail from William Dodé, 2005-05-25
300
        # $ bzr init; touch a; bzr add a; bzr commit -m "add a"
301
        #     * looking for changes...
302
        #     added a
303
        #     * commited r1
304
        #     $ bzr remove a
305
        #     $ bzr status
306
        #     bzr: local variable 'kind' referenced before assignment
307
        #     at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
308
        #     see ~/.bzr.log for debug information
309
        chdir('status-after-remove')
898 by Martin Pool
- add new runbzr method for external tests
310
        runbzr('init')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
311
        file('a', 'w').write('foo')
898 by Martin Pool
- add new runbzr method for external tests
312
        runbzr('add a')
313
        runbzr(['commit', '-m', 'add a'])
314
        runbzr('remove a')
315
        runbzr('status')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
316
317
        chdir('..')
318
319
        progress('ignore patterns')
320
        mkdir('ignorebranch')
321
        chdir('ignorebranch')
898 by Martin Pool
- add new runbzr method for external tests
322
        runbzr('init')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
323
        assert backtick('bzr unknowns') == ''
324
325
        file('foo.tmp', 'wt').write('tmp files are ignored')
326
        assert backtick('bzr unknowns') == ''
327
328
        file('foo.c', 'wt').write('int main() {}')
329
        assert backtick('bzr unknowns') == 'foo.c\n'
898 by Martin Pool
- add new runbzr method for external tests
330
        runbzr('add foo.c')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
331
        assert backtick('bzr unknowns') == ''
332
333
        # 'ignore' works when creating the .bzignore file
334
        file('foo.blah', 'wt').write('blah')
335
        assert backtick('bzr unknowns') == 'foo.blah\n'
898 by Martin Pool
- add new runbzr method for external tests
336
        runbzr('ignore *.blah')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
337
        assert backtick('bzr unknowns') == ''
338
        assert file('.bzrignore', 'rb').read() == '*.blah\n'
339
340
        # 'ignore' works when then .bzrignore file already exists
341
        file('garh', 'wt').write('garh')
342
        assert backtick('bzr unknowns') == 'garh\n'
898 by Martin Pool
- add new runbzr method for external tests
343
        runbzr('ignore garh')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
344
        assert backtick('bzr unknowns') == ''
345
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
346
347
        chdir('..')
348
349
350
351
352
        progress("recursive and non-recursive add")
353
        mkdir('no-recurse')
354
        chdir('no-recurse')
898 by Martin Pool
- add new runbzr method for external tests
355
        runbzr('init')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
356
        mkdir('foo')
357
        fp = os.path.join('foo', 'test.txt')
358
        f = file(fp, 'w')
359
        f.write('hello!\n')
360
        f.close()
898 by Martin Pool
- add new runbzr method for external tests
361
        runbzr('add --no-recurse foo')
362
        runbzr('file-id foo')
363
        runbzr('file-id ' + fp, 1)      # not versioned yet
364
        runbzr('commit -m add-dir-only')
365
366
        runbzr('file-id ' + fp, 1)      # still not versioned 
367
368
        runbzr('add foo')
369
        runbzr('file-id ' + fp)
370
        runbzr('commit -m add-sub-file')
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
371
372
        chdir('..')
373
374
375
785 by Martin Pool
- add test for external revert command
376
class RevertCommand(InTempDir):
377
    def runTest(self):
898 by Martin Pool
- add new runbzr method for external tests
378
        self.runbzr('init')
785 by Martin Pool
- add test for external revert command
379
380
        file('hello', 'wt').write('foo')
898 by Martin Pool
- add new runbzr method for external tests
381
        self.runbzr('add hello')
382
        self.runbzr('commit -m setup hello')
785 by Martin Pool
- add test for external revert command
383
        
384
        file('hello', 'wt').write('bar')
898 by Martin Pool
- add new runbzr method for external tests
385
        self.runbzr('revert hello')
785 by Martin Pool
- add test for external revert command
386
        self.check_file_contents('hello', 'foo')
387
736 by Martin Pool
- move old blackbox code from testbzr into bzrlib.selftest.blackbox
388
    
726 by Martin Pool
- more rearrangement of blackbox tests
389
        
390
391
392
# lists all tests from this module in the best order to run them.  we
393
# do it this way rather than just discovering them all because it
394
# allows us to test more basic functions first where failures will be
395
# easiest to understand.
843 by Martin Pool
- workaround for flaky TestLoader in python2.3
396
TEST_CLASSES = [TestVersion,
397
                InitBranch,
398
                HelpCommands,
399
                UserIdentity,
400
                InvalidCommands,
401
                RevertCommand,
402
                OldTests,
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
403
                EmptyCommit,
843 by Martin Pool
- workaround for flaky TestLoader in python2.3
404
                ]