1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1
# Copyright (C) 2008-2011, 2016 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Tests of the 'bzr alias' command."""
22
from bzrlib.tests.blackbox import ExternalBase
23
from bzrlib.config import (ensure_config_dir_exists, config_filename)
26
class TestAlias(ExternalBase):
18
"""Tests of the 'brz alias' command."""
24
from breezy.tests import (
29
class TestAlias(tests.TestCaseWithTransport):
28
31
def test_list_alias_with_none(self):
29
32
"""Calling alias with no parameters lists existing aliases."""
30
33
out, err = self.run_bzr('alias')
31
self.assertEquals('', out)
34
self.assertEqual('', out)
33
36
def test_list_unknown_alias(self):
34
37
out, err = self.run_bzr('alias commit')
35
self.assertEquals('bzr alias: commit: not found\n', out)
38
self.assertEqual('brz alias: commit: not found\n', out)
37
40
def test_add_alias_outputs_nothing(self):
38
41
out, err = self.run_bzr('alias commit="commit --strict"')
39
self.assertEquals('', out)
42
self.assertEqual('', out)
41
44
def test_add_alias_visible(self):
42
45
"""Adding an alias makes it ..."""
43
46
self.run_bzr('alias commit="commit --strict"')
44
47
out, err = self.run_bzr('alias commit')
45
self.assertEquals('bzr alias commit="commit --strict"\n', out)
48
self.assertEqual('brz alias commit="commit --strict"\n', out)
47
50
def test_unicode_alias(self):
48
51
"""Unicode aliases should work (Bug #529930)"""
52
# XXX: strictly speaking, lack of unicode filenames doesn't imply that
53
# unicode command lines aren't available.
54
self.requireFeature(features.UnicodeFilenameFeature)
50
55
file_name = u'foo\xb6'
52
57
tree = self.make_branch_and_tree('.')
54
59
tree.add(file_name)
55
60
tree.commit('added')
57
ensure_config_dir_exists()
58
CONFIG=(u'[ALIASES]\n'
61
codecs.open(config_filename(),'w', config_enc).write(CONFIG)
62
config.GlobalConfig.from_string(
63
u'[ALIASES]\nust=st %s\n' % (file_name,), save=True)
63
65
out, err = self.run_bzr('ust')
64
self.assertEquals(err, '')
65
self.assertEquals(out, '')
66
self.assertEqual(err, '')
67
self.assertEqual(out, '')
67
69
def test_alias_listing_alphabetical(self):
68
70
self.run_bzr('alias commit="commit --strict"')
70
72
self.run_bzr('alias add="add -q"')
72
74
out, err = self.run_bzr('alias')
74
'bzr alias add="add -q"\n'
75
'bzr alias commit="commit --strict"\n'
76
'bzr alias ll="log --short"\n',
76
'brz alias add="add -q"\n'
77
'brz alias commit="commit --strict"\n'
78
'brz alias ll="log --short"\n',
79
81
def test_remove_unknown_alias(self):
80
82
out, err = self.run_bzr('alias --remove fooix', retcode=3)
81
self.assertEquals('bzr: ERROR: The alias "fooix" does not exist.\n',
83
self.assertEqual('brz: ERROR: The alias "fooix" does not exist.\n',
84
86
def test_remove_known_alias(self):
85
87
self.run_bzr('alias commit="commit --strict"')
86
88
out, err = self.run_bzr('alias commit')
87
self.assertEquals('bzr alias commit="commit --strict"\n', out)
89
self.assertEqual('brz alias commit="commit --strict"\n', out)
88
90
# No output when removing an existing alias.
89
91
out, err = self.run_bzr('alias --remove commit')
90
self.assertEquals('', out)
92
self.assertEqual('', out)
92
94
out, err = self.run_bzr('alias commit')
93
self.assertEquals("bzr alias: commit: not found\n", out)
95
self.assertEqual("brz alias: commit: not found\n", out)