/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/tests/blackbox/test_aliases.py

Got uncommit working properly with checkouts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
1
"""Black-box tests for bzr aliases.
17
2
"""
18
3
 
19
4
import os
20
5
 
21
6
from bzrlib.branch import Branch
22
 
from bzrlib.tests.blackbox import ExternalBase
 
7
from bzrlib.tests import TestCaseInTempDir
23
8
from bzrlib.trace import mutter
24
 
from bzrlib.config import (ensure_config_dir_exists, config_filename)
25
 
 
26
 
 
27
 
class TestAliases(ExternalBase):
 
9
from bzrlib.config import (config_dir, config_filename)
 
10
 
 
11
 
 
12
class TestAliases(TestCaseInTempDir):
28
13
 
29
14
    def test_aliases(self):
30
15
 
31
 
        def bzr(args, **kwargs):
32
 
            return self.run_bzr(args, **kwargs)[0]
33
 
 
34
 
        def bzr_catch_error(args, **kwargs):
35
 
            return self.run_bzr(args, **kwargs)[1]
36
 
 
 
16
        def bzr(*args, **kwargs):
 
17
            return self.run_bzr(*args, **kwargs)[0]
37
18
 
38
19
        if os.path.isfile(config_filename()):
39
 
            # Something is wrong in environment,
40
 
            # we risk overwriting users config
 
20
            # Something is wrong in environment, 
 
21
            # we risk overwriting users config 
41
22
            self.assert_(config_filename() + "exists, abort")
42
 
 
43
 
        ensure_config_dir_exists()
 
23
            
 
24
        os.mkdir(config_dir())
44
25
        CONFIG=("[ALIASES]\n"
45
26
                "c=cat\n"
46
27
                "c1=cat -r 1\n"
48
29
 
49
30
        open(config_filename(),'wb').write(CONFIG)
50
31
 
 
32
 
51
33
        str1 = 'foo\n'
52
34
        str2 = 'bar\n'
53
35
 
54
 
        tree = self.make_branch_and_tree('.')
55
 
        self.build_tree_contents([('a', str1)])
56
 
        tree.add('a')
57
 
        tree.commit(message='1')
58
 
 
59
 
        self.assertEquals(bzr('c a'), str1)
60
 
 
61
 
        self.build_tree_contents([('a', str2)])
62
 
        tree.commit(message='2')
63
 
 
64
 
        self.assertEquals(bzr('c a'), str2)
65
 
        self.assertEquals(bzr('c1 a'), str1)
66
 
        self.assertEquals(bzr('c1 --revision 2 a'), str2)
67
 
 
68
 
        # If --no-aliases isn't working, we will not get retcode=3
69
 
        bzr('--no-aliases c a', retcode=3)
70
 
 
71
 
        # If --no-aliases breaks all of bzr, we also get retcode=3
72
 
        # So we need to catch the output as well
73
 
        self.assertEquals(bzr_catch_error('--no-aliases c a',
74
 
                                          retcode=None),
75
 
                          'bzr: ERROR: unknown command "c"\n')
76
 
 
77
 
        bzr('c -r1 -r2', retcode=3)
78
 
        bzr('c1 -r1 -r2', retcode=3)
 
36
        bzr('init')
 
37
        open('a', 'wb').write(str1)
 
38
        bzr('add', 'a')
 
39
 
 
40
        bzr('commit', '-m', '1')
 
41
 
 
42
        self.assertEquals(bzr('c', 'a'), str1)
 
43
 
 
44
        open('a', 'wb').write(str2)
 
45
        bzr('commit', '-m', '2')
 
46
 
 
47
        self.assertEquals(bzr('c', 'a'), str2)
 
48
        self.assertEquals(bzr('c1', 'a'), str1)
 
49
        self.assertEquals(bzr('c1', '--revision', '2', 'a'), str2)
 
50
 
 
51
        # If --no-alias isn't working, we will not get retcode=3
 
52
        bzr('--no-aliases', 'c', 'a', retcode=3)
 
53
 
 
54
        bzr('c', '-r1', '-r2', retcode=3)
 
55
        bzr('c1', '-r1', '-r2', retcode=3)
79
56
        bzr('c2', retcode=3)
80
 
        bzr('c2 -r1', retcode=3)
 
57
        bzr('c2', '-r1', retcode=3)