~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

  • Committer: John Arbash Meinel
  • Date: 2005-09-18 16:09:41 UTC
  • mto: (1185.1.32)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: john@arbash-meinel.com-20050918160940-ab133a1f31616576
Added test cases for handling bogus files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
 
37
37
class ExternalBase(TestCaseInTempDir):
38
 
    def runbzr(self, args, retcode=0,backtick=False):
 
38
    def runbzr(self, args, retcode=0, backtick=False):
39
39
        if isinstance(args, basestring):
40
40
            args = args.split()
41
41
 
42
42
        if backtick:
43
 
            return self.backtick(['python', self.BZRPATH,] + args,
44
 
                           retcode=retcode)
 
43
            return self.run_bzr_captured(args, retcode=retcode)[0]
45
44
        else:
46
 
            return self.runcmd(['python', self.BZRPATH,] + args,
47
 
                           retcode=retcode)
 
45
            return self.run_bzr_captured(args, retcode=retcode)
48
46
 
49
47
 
50
48
class TestCommands(ExternalBase):
93
91
    def test_ignore_patterns(self):
94
92
        from bzrlib.branch import Branch
95
93
        
96
 
        b = Branch('.', init=True)
 
94
        b = Branch.initialize('.')
97
95
        self.assertEquals(list(b.unknowns()), [])
98
96
 
99
97
        file('foo.tmp', 'wt').write('tmp files are ignored')
100
98
        self.assertEquals(list(b.unknowns()), [])
101
 
        assert self.backtick('bzr unknowns') == ''
 
99
        assert self.capture('unknowns') == ''
102
100
 
103
101
        file('foo.c', 'wt').write('int main() {}')
104
102
        self.assertEquals(list(b.unknowns()), ['foo.c'])
105
 
        assert self.backtick('bzr unknowns') == 'foo.c\n'
 
103
        assert self.capture('unknowns') == 'foo.c\n'
106
104
 
107
105
        self.runbzr(['add', 'foo.c'])
108
 
        assert self.backtick('bzr unknowns') == ''
 
106
        assert self.capture('unknowns') == ''
109
107
 
110
108
        # 'ignore' works when creating the .bzignore file
111
109
        file('foo.blah', 'wt').write('blah')
117
115
        # 'ignore' works when then .bzrignore file already exists
118
116
        file('garh', 'wt').write('garh')
119
117
        self.assertEquals(list(b.unknowns()), ['garh'])
120
 
        assert self.backtick('bzr unknowns') == 'garh\n'
 
118
        assert self.capture('unknowns') == 'garh\n'
121
119
        self.runbzr('ignore garh')
122
120
        self.assertEquals(list(b.unknowns()), [])
123
121
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
150
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/'])
155
153
        self.run_bzr('add', self.test_dir)
156
154
        self.run_bzr('mv', '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
218
        self.log('pending merges: %s', a.pending_merges())
221
219
        #        assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
241
239
        self.runbzr('pull')
242
240
        self.runbzr('commit -m blah --unchanged')
243
241
        os.chdir('../a')
244
 
        a = Branch('.')
245
 
        b = Branch('../b')
 
242
        a = Branch.open('.')
 
243
        b = Branch.open('../b')
246
244
        assert a.revision_history() == b.revision_history()[:-1]
247
245
        self.runbzr('pull ../b')
248
246
        assert a.revision_history() == b.revision_history()
260
258
 
261
259
    def test_add_reports(self):
262
260
        """add command prints the names of added files."""
263
 
        b = Branch('.', init=True)
 
261
        b = Branch.initialize('.')
264
262
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
265
263
 
266
264
        from cStringIO import StringIO
278
276
                           'added top.txt',],
279
277
                          results)
280
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
 
281
287
 
282
288
class OldTests(ExternalBase):
283
289
    """old tests moved from ./testbzr."""
287
293
        from os.path import exists
288
294
 
289
295
        runbzr = self.runbzr
290
 
        backtick = self.backtick
 
296
        capture = self.capture
291
297
        progress = self.log
292
298
 
293
299
        progress("basic branch creation")
295
301
        chdir('branch1')
296
302
        runbzr('init')
297
303
 
298
 
        self.assertEquals(backtick('bzr root').rstrip(),
 
304
        self.assertEquals(capture('root').rstrip(),
299
305
                          os.path.join(self.test_dir, 'branch1'))
300
306
 
301
307
        progress("status of new file")
304
310
        f.write('hello world!\n')
305
311
        f.close()
306
312
 
307
 
        out = backtick("bzr unknowns")
308
 
        self.assertEquals(out, 'test.txt\n')
 
313
        self.assertEquals(capture('unknowns'), 'test.txt\n')
309
314
 
310
 
        out = backtick("bzr status")
 
315
        out = capture("status")
311
316
        assert out == 'unknown:\n  test.txt\n'
312
317
 
313
 
        out = backtick("bzr status --all")
 
318
        out = capture("status --all")
314
319
        assert out == "unknown:\n  test.txt\n"
315
320
 
316
 
        out = backtick("bzr status test.txt --all")
 
321
        out = capture("status test.txt --all")
317
322
        assert out == "unknown:\n  test.txt\n"
318
323
 
319
324
        f = file('test2.txt', 'wt')
320
325
        f.write('goodbye cruel world...\n')
321
326
        f.close()
322
327
 
323
 
        out = backtick("bzr status test.txt")
 
328
        out = capture("status test.txt")
324
329
        assert out == "unknown:\n  test.txt\n"
325
330
 
326
 
        out = backtick("bzr status")
 
331
        out = capture("status")
327
332
        assert out == ("unknown:\n"
328
333
                       "  test.txt\n"
329
334
                       "  test2.txt\n")
331
336
        os.unlink('test2.txt')
332
337
 
333
338
        progress("command aliases")
334
 
        out = backtick("bzr st --all")
 
339
        out = capture("st --all")
335
340
        assert out == ("unknown:\n"
336
341
                       "  test.txt\n")
337
342
 
338
 
        out = backtick("bzr stat")
 
343
        out = capture("stat")
339
344
        assert out == ("unknown:\n"
340
345
                       "  test.txt\n")
341
346
 
345
350
        runbzr("help commands")
346
351
        runbzr("help slartibartfast", 1)
347
352
 
348
 
        out = backtick("bzr help ci")
 
353
        out = capture("help ci")
349
354
        out.index('aliases: ')
350
355
 
351
356
        progress("can't rename unversioned file")
354
359
        progress("adding a file")
355
360
 
356
361
        runbzr("add test.txt")
357
 
        assert backtick("bzr unknowns") == ''
358
 
        assert backtick("bzr status --all") == ("added:\n"
 
362
        assert capture("unknowns") == ''
 
363
        assert capture("status --all") == ("added:\n"
359
364
                                                "  test.txt\n")
360
365
 
361
366
        progress("rename newly-added file")
363
368
        assert os.path.exists("hello.txt")
364
369
        assert not os.path.exists("test.txt")
365
370
 
366
 
        assert backtick("bzr revno") == '0\n'
 
371
        assert capture("revno") == '0\n'
367
372
 
368
373
        progress("add first revision")
369
374
        runbzr(['commit', '-m', 'add first revision'])
377
382
        runbzr("add sub1")
378
383
        runbzr("rename sub1 sub2")
379
384
        runbzr("move hello.txt sub2")
380
 
        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")
381
386
 
382
387
        assert exists("sub2")
383
388
        assert exists("sub2/hello.txt")
398
403
        runbzr(['commit', '-m', 'rename nested subdirectories'])
399
404
 
400
405
        chdir('sub1/sub2')
401
 
        self.assertEquals(backtick('bzr root')[:-1],
 
406
        self.assertEquals(capture('root')[:-1],
402
407
                          os.path.join(self.test_dir, 'branch1'))
403
408
        runbzr('move ../hello.txt .')
404
409
        assert exists('./hello.txt')
405
 
        assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
406
 
        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')
407
413
        runbzr(['commit', '-m', 'move to parent directory'])
408
414
        chdir('..')
409
 
        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')
410
416
 
411
417
        runbzr('move sub2/hello.txt .')
412
418
        assert exists('hello.txt')
421
427
 
422
428
        runbzr('commit -F msg.tmp')
423
429
 
424
 
        assert backtick('bzr revno') == '5\n'
 
430
        assert capture('revno') == '5\n'
425
431
        runbzr('export -r 5 export-5.tmp')
426
432
        runbzr('export export.tmp')
427
433
 
429
435
        runbzr('log -v')
430
436
        runbzr('log -v --forward')
431
437
        runbzr('log -m', retcode=1)
432
 
        log_out = backtick('bzr log -m commit')
 
438
        log_out = capture('log -m commit')
433
439
        assert "this is my new commit" in log_out
434
440
        assert "rename nested" not in log_out
435
441
        assert 'revision-id' not in log_out
436
 
        assert 'revision-id' in backtick('bzr log --show-ids -m commit')
 
442
        assert 'revision-id' in capture('log --show-ids -m commit')
437
443
 
438
444
 
439
445
        progress("file with spaces in name")