~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Alexander Belchenko
  • Date: 2006-07-30 16:43:12 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060730164312-b025fd3ff0cee59e
rename  gpl.txt => COPYING.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009, 2010 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
 
from bzrlib import config
22
6
from bzrlib.branch import Branch
23
 
from bzrlib.tests import TestCaseWithTransport
 
7
from bzrlib.tests import TestCaseInTempDir
24
8
from bzrlib.trace import mutter
25
 
 
26
 
 
27
 
class TestAliases(TestCaseWithTransport):
 
9
from bzrlib.config import (ensure_config_dir_exists, 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
 
 
37
 
 
38
 
        conf = config.GlobalConfig.from_string('''[ALIASES]
39
 
c=cat
40
 
c1=cat -r 1
41
 
c2=cat -r 1 -r2
42
 
''', save=True)
 
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
 
43
36
 
44
37
        str1 = 'foo\n'
45
38
        str2 = 'bar\n'
46
39
 
47
 
        tree = self.make_branch_and_tree('.')
48
 
        self.build_tree_contents([('a', str1)])
49
 
        tree.add('a')
50
 
        tree.commit(message='1')
51
 
 
52
 
        self.assertEquals(bzr('c a'), str1)
53
 
 
54
 
        self.build_tree_contents([('a', str2)])
55
 
        tree.commit(message='2')
56
 
 
57
 
        self.assertEquals(bzr('c a'), str2)
58
 
        self.assertEquals(bzr('c1 a'), str1)
59
 
        self.assertEquals(bzr('c1 --revision 2 a'), str2)
 
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)
60
54
 
61
55
        # If --no-aliases isn't working, we will not get retcode=3
62
 
        bzr('--no-aliases c a', retcode=3)
 
56
        bzr('--no-aliases', 'c', 'a', retcode=3)
63
57
 
64
58
        # If --no-aliases breaks all of bzr, we also get retcode=3
65
59
        # So we need to catch the output as well
66
 
        self.assertEquals(bzr_catch_error('--no-aliases c a',
 
60
        self.assertEquals(bzr_catch_error('--no-aliases', 'c', 'a',
67
61
                                          retcode=None),
68
62
                          'bzr: ERROR: unknown command "c"\n')
69
63
 
70
 
        bzr('c -r1 -r2', retcode=3)
71
 
        bzr('c1 -r1 -r2', retcode=3)
 
64
        bzr('c', '-r1', '-r2', retcode=3)
 
65
        bzr('c1', '-r1', '-r2', retcode=3)
72
66
        bzr('c2', retcode=3)
73
 
        bzr('c2 -r1', retcode=3)
 
67
        bzr('c2', '-r1', retcode=3)