~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

  • Committer: Aaron Bentley
  • Date: 2005-09-19 02:52:24 UTC
  • mto: (1185.1.29)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: aaron.bentley@utoronto.ca-20050919025224-1cc3c70640086e09
TODO re tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
"""
28
28
 
29
29
import sys
 
30
import os
30
31
 
31
32
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
32
33
from bzrlib.branch import Branch
34
35
 
35
36
 
36
37
class ExternalBase(TestCaseInTempDir):
37
 
    def runbzr(self, args, retcode=0,backtick=False):
 
38
    def runbzr(self, args, retcode=0, backtick=False):
38
39
        if isinstance(args, basestring):
39
40
            args = args.split()
40
41
 
41
42
        if backtick:
42
 
            return self.backtick(['python', self.BZRPATH,] + args,
43
 
                           retcode=retcode)
 
43
            return self.run_bzr_captured(args, retcode=retcode)[0]
44
44
        else:
45
 
            return self.runcmd(['python', self.BZRPATH,] + args,
46
 
                           retcode=retcode)
 
45
            return self.run_bzr_captured(args, retcode=retcode)
47
46
 
48
47
 
49
48
class TestCommands(ExternalBase):
92
91
    def test_ignore_patterns(self):
93
92
        from bzrlib.branch import Branch
94
93
        
95
 
        b = Branch('.', init=True)
 
94
        b = Branch.initialize('.')
96
95
        self.assertEquals(list(b.unknowns()), [])
97
96
 
98
97
        file('foo.tmp', 'wt').write('tmp files are ignored')
99
98
        self.assertEquals(list(b.unknowns()), [])
100
 
        assert self.backtick('bzr unknowns') == ''
 
99
        assert self.capture('unknowns') == ''
101
100
 
102
101
        file('foo.c', 'wt').write('int main() {}')
103
102
        self.assertEquals(list(b.unknowns()), ['foo.c'])
104
 
        assert self.backtick('bzr unknowns') == 'foo.c\n'
 
103
        assert self.capture('unknowns') == 'foo.c\n'
105
104
 
106
105
        self.runbzr(['add', 'foo.c'])
107
 
        assert self.backtick('bzr unknowns') == ''
 
106
        assert self.capture('unknowns') == ''
108
107
 
109
108
        # 'ignore' works when creating the .bzignore file
110
109
        file('foo.blah', 'wt').write('blah')
116
115
        # 'ignore' works when then .bzrignore file already exists
117
116
        file('garh', 'wt').write('garh')
118
117
        self.assertEquals(list(b.unknowns()), ['garh'])
119
 
        assert self.backtick('bzr unknowns') == 'garh\n'
 
118
        assert self.capture('unknowns') == 'garh\n'
120
119
        self.runbzr('ignore garh')
121
120
        self.assertEquals(list(b.unknowns()), [])
122
121
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
123
122
 
124
123
    def test_revert(self):
125
 
        import os
126
124
        self.runbzr('init')
127
125
 
128
126
        file('hello', 'wt').write('foo')
147
145
        os.rmdir('revertdir')
148
146
        self.runbzr('revert')
149
147
 
150
 
    def skipped_test_mv_modes(self):
 
148
    def test_mv_modes(self):
151
149
        """Test two modes of operation for mv"""
152
150
        from bzrlib.branch import Branch
153
 
        b = Branch('.', init=True)
 
151
        b = Branch.initialize('.')
154
152
        self.build_tree(['a', 'c', 'subdir/'])
 
153
        self.run_bzr('add', self.test_dir)
155
154
        self.run_bzr('mv', 'a', 'b')
156
155
        self.run_bzr('mv', 'b', 'subdir')
157
156
        self.run_bzr('mv', 'subdir/b', 'a')
158
 
        self.run_bzr('mv', 'a', 'b', 'subdir')
 
157
        self.run_bzr('mv', 'a', 'c', 'subdir')
159
158
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
160
159
 
 
160
 
161
161
    def test_main_version(self):
162
162
        """Check output from version command and master option is reasonable"""
163
163
        # output is intentionally passed through to stdout so that we
194
194
 
195
195
    def test_merge(self):
196
196
        from bzrlib.branch import Branch
197
 
        import os
198
197
        
199
198
        os.mkdir('a')
200
199
        os.chdir('a')
201
 
 
202
200
        self.example_branch()
203
201
        os.chdir('..')
204
202
        self.runbzr('branch a b')
214
212
        self.runbzr('merge ../b')
215
213
        self.check_file_contents('goodbye', 'quux')
216
214
        # Merging a branch pulls its revision into the tree
217
 
        a = Branch('.')
218
 
        b = Branch('../b')
 
215
        a = Branch.open('.')
 
216
        b = Branch.open('../b')
219
217
        a.get_revision_xml(b.last_patch())
220
 
 
221
218
        self.log('pending merges: %s', a.pending_merges())
222
219
        #        assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
223
220
        #        % (a.pending_merges(), b.last_patch())
224
221
 
 
222
    def test_pull(self):
 
223
        """Pull changes from one branch to another."""
 
224
        os.mkdir('a')
 
225
        os.chdir('a')
 
226
 
 
227
        self.example_branch()
 
228
        self.runbzr('pull', retcode=1)
 
229
        self.runbzr('missing', retcode=1)
 
230
        self.runbzr('missing .')
 
231
        self.runbzr('missing')
 
232
        self.runbzr('pull')
 
233
        self.runbzr('pull /', retcode=1)
 
234
        self.runbzr('pull')
 
235
 
 
236
        os.chdir('..')
 
237
        self.runbzr('branch a b')
 
238
        os.chdir('b')
 
239
        self.runbzr('pull')
 
240
        self.runbzr('commit -m blah --unchanged')
 
241
        os.chdir('../a')
 
242
        a = Branch.open('.')
 
243
        b = Branch.open('../b')
 
244
        assert a.revision_history() == b.revision_history()[:-1]
 
245
        self.runbzr('pull ../b')
 
246
        assert a.revision_history() == b.revision_history()
 
247
        self.runbzr('commit -m blah2 --unchanged')
 
248
        os.chdir('../b')
 
249
        self.runbzr('commit -m blah3 --unchanged')
 
250
        self.runbzr('pull ../a', retcode=1)
 
251
        os.chdir('../a')
 
252
        self.runbzr('merge ../b')
 
253
        self.runbzr('commit -m blah4 --unchanged')
 
254
        os.chdir('../b')
 
255
        self.runbzr('pull ../a')
 
256
        assert a.revision_history()[-1] == b.revision_history()[-1]
 
257
        
225
258
 
226
259
    def test_add_reports(self):
227
260
        """add command prints the names of added files."""
228
 
        b = Branch('.', init=True)
 
261
        b = Branch.initialize('.')
229
262
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
230
263
 
231
264
        from cStringIO import StringIO
243
276
                           'added top.txt',],
244
277
                          results)
245
278
 
 
279
    def test_unknown_command(self):
 
280
        """Handling of unknown command."""
 
281
        out, err = self.run_bzr_captured(['fluffy-badger'],
 
282
                                         retcode=1)
 
283
        self.assertEquals(out, '')
 
284
        err.index('unknown command')
 
285
        
 
286
 
246
287
 
247
288
class OldTests(ExternalBase):
248
289
    """old tests moved from ./testbzr."""
250
291
    def test_bzr(self):
251
292
        from os import chdir, mkdir
252
293
        from os.path import exists
253
 
        import os
254
294
 
255
295
        runbzr = self.runbzr
256
 
        backtick = self.backtick
 
296
        capture = self.capture
257
297
        progress = self.log
258
298
 
259
299
        progress("basic branch creation")
261
301
        chdir('branch1')
262
302
        runbzr('init')
263
303
 
264
 
        self.assertEquals(backtick('bzr root').rstrip(),
 
304
        self.assertEquals(capture('root').rstrip(),
265
305
                          os.path.join(self.test_dir, 'branch1'))
266
306
 
267
307
        progress("status of new file")
270
310
        f.write('hello world!\n')
271
311
        f.close()
272
312
 
273
 
        out = backtick("bzr unknowns")
274
 
        self.assertEquals(out, 'test.txt\n')
 
313
        self.assertEquals(capture('unknowns'), 'test.txt\n')
275
314
 
276
 
        out = backtick("bzr status")
 
315
        out = capture("status")
277
316
        assert out == 'unknown:\n  test.txt\n'
278
317
 
279
 
        out = backtick("bzr status --all")
 
318
        out = capture("status --all")
280
319
        assert out == "unknown:\n  test.txt\n"
281
320
 
282
 
        out = backtick("bzr status test.txt --all")
 
321
        out = capture("status test.txt --all")
283
322
        assert out == "unknown:\n  test.txt\n"
284
323
 
285
324
        f = file('test2.txt', 'wt')
286
325
        f.write('goodbye cruel world...\n')
287
326
        f.close()
288
327
 
289
 
        out = backtick("bzr status test.txt")
 
328
        out = capture("status test.txt")
290
329
        assert out == "unknown:\n  test.txt\n"
291
330
 
292
 
        out = backtick("bzr status")
 
331
        out = capture("status")
293
332
        assert out == ("unknown:\n"
294
333
                       "  test.txt\n"
295
334
                       "  test2.txt\n")
297
336
        os.unlink('test2.txt')
298
337
 
299
338
        progress("command aliases")
300
 
        out = backtick("bzr st --all")
 
339
        out = capture("st --all")
301
340
        assert out == ("unknown:\n"
302
341
                       "  test.txt\n")
303
342
 
304
 
        out = backtick("bzr stat")
 
343
        out = capture("stat")
305
344
        assert out == ("unknown:\n"
306
345
                       "  test.txt\n")
307
346
 
311
350
        runbzr("help commands")
312
351
        runbzr("help slartibartfast", 1)
313
352
 
314
 
        out = backtick("bzr help ci")
 
353
        out = capture("help ci")
315
354
        out.index('aliases: ')
316
355
 
317
356
        progress("can't rename unversioned file")
320
359
        progress("adding a file")
321
360
 
322
361
        runbzr("add test.txt")
323
 
        assert backtick("bzr unknowns") == ''
324
 
        assert backtick("bzr status --all") == ("added:\n"
 
362
        assert capture("unknowns") == ''
 
363
        assert capture("status --all") == ("added:\n"
325
364
                                                "  test.txt\n")
326
365
 
327
366
        progress("rename newly-added file")
329
368
        assert os.path.exists("hello.txt")
330
369
        assert not os.path.exists("test.txt")
331
370
 
332
 
        assert backtick("bzr revno") == '0\n'
 
371
        assert capture("revno") == '0\n'
333
372
 
334
373
        progress("add first revision")
335
374
        runbzr(['commit', '-m', 'add first revision'])
343
382
        runbzr("add sub1")
344
383
        runbzr("rename sub1 sub2")
345
384
        runbzr("move hello.txt sub2")
346
 
        assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
 
385
        assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
347
386
 
348
387
        assert exists("sub2")
349
388
        assert exists("sub2/hello.txt")
364
403
        runbzr(['commit', '-m', 'rename nested subdirectories'])
365
404
 
366
405
        chdir('sub1/sub2')
367
 
        self.assertEquals(backtick('bzr root')[:-1],
 
406
        self.assertEquals(capture('root')[:-1],
368
407
                          os.path.join(self.test_dir, 'branch1'))
369
408
        runbzr('move ../hello.txt .')
370
409
        assert exists('./hello.txt')
371
 
        assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
372
 
        assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
410
        self.assertEquals(capture('relpath hello.txt'),
 
411
                          os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
 
412
        assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
373
413
        runbzr(['commit', '-m', 'move to parent directory'])
374
414
        chdir('..')
375
 
        assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
415
        assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
376
416
 
377
417
        runbzr('move sub2/hello.txt .')
378
418
        assert exists('hello.txt')
387
427
 
388
428
        runbzr('commit -F msg.tmp')
389
429
 
390
 
        assert backtick('bzr revno') == '5\n'
 
430
        assert capture('revno') == '5\n'
391
431
        runbzr('export -r 5 export-5.tmp')
392
432
        runbzr('export export.tmp')
393
433
 
395
435
        runbzr('log -v')
396
436
        runbzr('log -v --forward')
397
437
        runbzr('log -m', retcode=1)
398
 
        log_out = backtick('bzr log -m commit')
 
438
        log_out = capture('log -m commit')
399
439
        assert "this is my new commit" in log_out
400
440
        assert "rename nested" not in log_out
401
441
        assert 'revision-id' not in log_out
402
 
        assert 'revision-id' in backtick('bzr log --show-ids -m commit')
 
442
        assert 'revision-id' in capture('log --show-ids -m commit')
403
443
 
404
444
 
405
445
        progress("file with spaces in name")