~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_aliases.py

  • Committer: Martin Pool
  • Date: 2005-06-02 02:37:54 UTC
  • Revision ID: mbp@sourcefrog.net-20050602023754-fc3d4c02877ba29d
doc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Black-box tests for bzr aliases.
2
 
"""
3
 
 
4
 
import os
5
 
 
6
 
from bzrlib.branch import Branch
7
 
from bzrlib.tests import TestCaseInTempDir
8
 
from bzrlib.trace import mutter
9
 
from bzrlib.config import (ensure_config_dir_exists, config_filename)
10
 
 
11
 
 
12
 
class TestAliases(TestCaseInTempDir):
13
 
 
14
 
    def test_aliases(self):
15
 
 
16
 
        def bzr(*args, **kwargs):
17
 
            return self.run_bzr(*args, **kwargs)[0]
18
 
 
19
 
        def bzr_catch_error(*args, **kwargs):
20
 
            return self.run_bzr(*args, **kwargs)[1]
21
 
 
22
 
 
23
 
        if os.path.isfile(config_filename()):
24
 
            # Something is wrong in environment, 
25
 
            # we risk overwriting users config 
26
 
            self.assert_(config_filename() + "exists, abort")
27
 
        
28
 
        ensure_config_dir_exists()
29
 
        CONFIG=("[ALIASES]\n"
30
 
                "c=cat\n"
31
 
                "c1=cat -r 1\n"
32
 
                "c2=cat -r 1 -r2\n")
33
 
 
34
 
        open(config_filename(),'wb').write(CONFIG)
35
 
 
36
 
 
37
 
        str1 = 'foo\n'
38
 
        str2 = 'bar\n'
39
 
 
40
 
        bzr('init')
41
 
        open('a', 'wb').write(str1)
42
 
        bzr('add', 'a')
43
 
 
44
 
        bzr('commit', '-m', '1')
45
 
 
46
 
        self.assertEquals(bzr('c', 'a'), str1)
47
 
 
48
 
        open('a', 'wb').write(str2)
49
 
        bzr('commit', '-m', '2')
50
 
 
51
 
        self.assertEquals(bzr('c', 'a'), str2)
52
 
        self.assertEquals(bzr('c1', 'a'), str1)
53
 
        self.assertEquals(bzr('c1', '--revision', '2', 'a'), str2)
54
 
 
55
 
        # If --no-aliases isn't working, we will not get retcode=3
56
 
        bzr('--no-aliases', 'c', 'a', retcode=3)
57
 
 
58
 
        # If --no-aliases breaks all of bzr, we also get retcode=3
59
 
        # So we need to catch the output as well
60
 
        self.assertEquals(bzr_catch_error('--no-aliases', 'c', 'a',
61
 
                                          retcode=None),
62
 
                          'bzr: ERROR: unknown command "c"\n')
63
 
 
64
 
        bzr('c', '-r1', '-r2', retcode=3)
65
 
        bzr('c1', '-r1', '-r2', retcode=3)
66
 
        bzr('c2', retcode=3)
67
 
        bzr('c2', '-r1', retcode=3)