/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

More work on roundtrip push support.

Show diffs side-by-side

added added

removed removed

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