1
# Copyright (C) 2005, 2006 Canonical Ltd
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1
16
"""Black-box tests for bzr aliases.
6
21
from bzrlib.branch import Branch
7
22
from bzrlib.tests import TestCaseInTempDir
8
23
from bzrlib.trace import mutter
9
from bzrlib.config import (config_dir, config_filename)
24
from bzrlib.config import (ensure_config_dir_exists, config_filename)
12
27
class TestAliases(TestCaseInTempDir):
14
29
def test_aliases(self):
16
def bzr(*args, **kwargs):
17
return self.run_bzr(*args, **kwargs)[0]
31
def bzr(args, **kwargs):
32
return self.run_bzr(args, **kwargs)[0]
34
def bzr_catch_error(args, **kwargs):
35
return self.run_bzr(args, **kwargs)[1]
19
38
if os.path.isfile(config_filename()):
20
39
# Something is wrong in environment,
21
40
# we risk overwriting users config
22
41
self.assert_(config_filename() + "exists, abort")
24
os.mkdir(config_dir())
43
ensure_config_dir_exists()
25
44
CONFIG=("[ALIASES]\n"
37
56
open('a', 'wb').write(str1)
40
bzr('commit', '-m', '1')
42
self.assertEquals(bzr('c', 'a'), str1)
61
self.assertEquals(bzr('c a'), str1)
44
63
open('a', 'wb').write(str2)
45
bzr('commit', '-m', '2')
47
self.assertEquals(bzr('c', 'a'), str2)
48
self.assertEquals(bzr('c1', 'a'), str1)
49
self.assertEquals(bzr('c1', '--revision', '2', 'a'), str2)
51
# If --no-alias isn't working, we will not get retcode=3
52
bzr('--no-aliases', 'c', 'a', retcode=3)
54
bzr('c', '-r1', '-r2', retcode=3)
55
bzr('c1', '-r1', '-r2', retcode=3)
66
self.assertEquals(bzr('c a'), str2)
67
self.assertEquals(bzr('c1 a'), str1)
68
self.assertEquals(bzr('c1 --revision 2 a'), str2)
70
# If --no-aliases isn't working, we will not get retcode=3
71
bzr('--no-aliases c a', retcode=3)
73
# If --no-aliases breaks all of bzr, we also get retcode=3
74
# So we need to catch the output as well
75
self.assertEquals(bzr_catch_error('--no-aliases c a',
77
'bzr: ERROR: unknown command "c"\n')
79
bzr('c -r1 -r2', retcode=3)
80
bzr('c1 -r1 -r2', retcode=3)
56
81
bzr('c2', retcode=3)
57
bzr('c2', '-r1', retcode=3)
82
bzr('c2 -r1', retcode=3)