~bzr-pqm/bzr/bzr.dev

5273.1.8 by Vincent Ladeuil
Merge bzr.dev into cleanup
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2900.3.6 by Tim Penhey
Added tests.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2900.3.6 by Tim Penhey
Added tests.
16
#
17
18
"""Tests of the 'bzr alias' command."""
5345.1.18 by Vincent Ladeuil
Cleanup bb.test_alias.
19
20
from bzrlib import (
21
    config,
22
    tests,
23
    )
24
25
26
class TestAlias(tests.TestCaseWithTransport):
2900.3.6 by Tim Penhey
Added tests.
27
28
    def test_list_alias_with_none(self):
29
        """Calling alias with no parameters lists existing aliases."""
2900.3.11 by Tim Penhey
Fixed the output in the tests.
30
        out, err = self.run_bzr('alias')
2900.3.6 by Tim Penhey
Added tests.
31
        self.assertEquals('', out)
32
33
    def test_list_unknown_alias(self):
2900.3.11 by Tim Penhey
Fixed the output in the tests.
34
        out, err = self.run_bzr('alias commit')
35
        self.assertEquals('bzr alias: commit: not found\n', out)
2900.3.6 by Tim Penhey
Added tests.
36
37
    def test_add_alias_outputs_nothing(self):
2900.3.11 by Tim Penhey
Fixed the output in the tests.
38
        out, err = self.run_bzr('alias commit="commit --strict"')
2900.3.6 by Tim Penhey
Added tests.
39
        self.assertEquals('', out)
40
41
    def test_add_alias_visible(self):
42
        """Adding an alias makes it ..."""
43
        self.run_bzr('alias commit="commit --strict"')
2900.3.11 by Tim Penhey
Fixed the output in the tests.
44
        out, err = self.run_bzr('alias commit')
45
        self.assertEquals('bzr alias commit="commit --strict"\n', out)
2900.3.6 by Tim Penhey
Added tests.
46
5158.7.1 by Parth Malwankar
added fail case test for unicode alias
47
    def test_unicode_alias(self):
48
        """Unicode aliases should work (Bug #529930)"""
5050.37.1 by Andrew Bennetts
Some fixes for tests that did not cope with LANG=C.
49
        # XXX: strictly speaking, lack of unicode filenames doesn't imply that
50
        # unicode command lines aren't available.
5439.1.1 by Andrew Bennetts
Merge lp:bzr/2.2.
51
        self.requireFeature(tests.UnicodeFilenameFeature)
5158.7.12 by Parth Malwankar
updated test to work on windows
52
        file_name = u'foo\xb6'
5158.7.7 by Parth Malwankar
updated test case to use user_encoding instead of utf-8
53
5158.7.15 by Parth Malwankar
test cleanup.
54
        tree = self.make_branch_and_tree('.')
55
        self.build_tree([file_name])
56
        tree.add(file_name)
57
        tree.commit('added')
5158.7.2 by Parth Malwankar
intermediate checkin of test case
58
5345.1.26 by Vincent Ladeuil
Merge lockable-config-files into remove-gratuitous-ensure-config-dir-exist-calls resolving conflicts
59
        config.GlobalConfig.from_string(
60
            u'[ALIASES]\nust=st %s\n' % (file_name,), save=True)
5158.7.12 by Parth Malwankar
updated test to work on windows
61
62
        out, err = self.run_bzr('ust')
5158.7.5 by Parth Malwankar
unicode aliases work now.
63
        self.assertEquals(err, '')
5158.7.12 by Parth Malwankar
updated test to work on windows
64
        self.assertEquals(out, '')
5158.7.1 by Parth Malwankar
added fail case test for unicode alias
65
2900.3.6 by Tim Penhey
Added tests.
66
    def test_alias_listing_alphabetical(self):
67
        self.run_bzr('alias commit="commit --strict"')
68
        self.run_bzr('alias ll="log --short"')
69
        self.run_bzr('alias add="add -q"')
70
2900.3.11 by Tim Penhey
Fixed the output in the tests.
71
        out, err = self.run_bzr('alias')
2900.3.6 by Tim Penhey
Added tests.
72
        self.assertEquals(
2900.3.11 by Tim Penhey
Fixed the output in the tests.
73
            'bzr alias add="add -q"\n'
74
            'bzr alias commit="commit --strict"\n'
75
            'bzr alias ll="log --short"\n',
76
            out)
2900.3.6 by Tim Penhey
Added tests.
77
78
    def test_remove_unknown_alias(self):
2900.3.11 by Tim Penhey
Fixed the output in the tests.
79
        out, err = self.run_bzr('alias --remove fooix', retcode=3)
80
        self.assertEquals('bzr: ERROR: The alias "fooix" does not exist.\n',
81
                          err)
2900.3.6 by Tim Penhey
Added tests.
82
83
    def test_remove_known_alias(self):
84
        self.run_bzr('alias commit="commit --strict"')
2900.3.11 by Tim Penhey
Fixed the output in the tests.
85
        out, err = self.run_bzr('alias commit')
86
        self.assertEquals('bzr alias commit="commit --strict"\n', out)
2900.3.6 by Tim Penhey
Added tests.
87
        # No output when removing an existing alias.
2900.3.11 by Tim Penhey
Fixed the output in the tests.
88
        out, err = self.run_bzr('alias --remove commit')
2900.3.6 by Tim Penhey
Added tests.
89
        self.assertEquals('', out)
90
        # Now its not.
2900.3.11 by Tim Penhey
Fixed the output in the tests.
91
        out, err = self.run_bzr('alias commit')
92
        self.assertEquals("bzr alias: commit: not found\n", out)