14
14
# along with this program; if not, write to the Free Software
 
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
17
from cStringIO import StringIO
 
19
20
from bzrlib import (
 
23
26
from bzrlib.commands import display_command
 
24
 
from bzrlib.tests import TestCase, TestSkipped
 
27
 
class TestCommands(TestCase):
 
 
27
from bzrlib.tests import TestSkipped
 
 
30
class TestCommands(tests.TestCase):
 
29
32
    def test_display_command(self):
 
30
33
        """EPIPE message is selectively suppressed"""
 
 
55
58
        self.assertRaises(errors.BzrCommandError,
 
56
59
                          commands.run_bzr, ['log', u'--option\xb5'])
 
 
62
class TestGetAlias(tests.TestCase):
 
 
64
    def _get_config(self, config_text):
 
 
65
        my_config = config.GlobalConfig()
 
 
66
        config_file = StringIO(config_text.encode('utf-8'))
 
 
67
        my_config._parser = my_config._get_parser(file=config_file)
 
 
70
    def test_simple(self):
 
 
71
        my_config = self._get_config("[ALIASES]\n"
 
 
72
            "diff=diff -r -2..-1\n")
 
 
73
        self.assertEqual([u'diff', u'-r', u'-2..-1'],
 
 
74
            commands.get_alias("diff", config=my_config))
 
 
76
    def test_single_quotes(self):
 
 
77
        my_config = self._get_config("[ALIASES]\n"
 
 
78
            "diff=diff -r -2..-1 --diff-options "
 
 
79
            "'--strip-trailing-cr -wp'\n")
 
 
80
        self.assertEqual([u'diff', u'-r', u'-2..-1', u'--diff-options',
 
 
81
                          u'--strip-trailing-cr -wp'],
 
 
82
                          commands.get_alias("diff", config=my_config))
 
 
84
    def test_double_quotes(self):
 
 
85
        my_config = self._get_config("[ALIASES]\n"
 
 
86
            "diff=diff -r -2..-1 --diff-options "
 
 
87
            "\"--strip-trailing-cr -wp\"\n")
 
 
88
        self.assertEqual([u'diff', u'-r', u'-2..-1', u'--diff-options',
 
 
89
                          u'--strip-trailing-cr -wp'],
 
 
90
                          commands.get_alias("diff", config=my_config))
 
 
92
    def test_unicode(self):
 
 
93
        my_config = self._get_config("[ALIASES]\n"
 
 
94
            u"iam=whoami 'Erik B\u00e5gfors <erik@bagfors.nu>'\n")
 
 
95
        self.assertEqual([u'whoami', u'Erik B\u00e5gfors <erik@bagfors.nu>'],
 
 
96
                          commands.get_alias("iam", config=my_config))
 
 
99
class TestSeeAlso(tests.TestCase):
 
 
100
    """Tests for the see also functional of Command."""
 
 
102
    def test_default_subclass_no_see_also(self):
 
 
103
        class ACommand(commands.Command):
 
 
104
            """A sample command."""
 
 
106
        self.assertEqual([], command.get_see_also())
 
 
108
    def test__see_also(self):
 
 
109
        """When _see_also is defined, it sets the result of get_see_also()."""
 
 
110
        class ACommand(commands.Command):
 
 
111
            _see_also = ['bar', 'foo']
 
 
113
        self.assertEqual(['bar', 'foo'], command.get_see_also())
 
 
115
    def test_deduplication(self):
 
 
116
        """Duplicates in _see_also are stripped out."""
 
 
117
        class ACommand(commands.Command):
 
 
118
            _see_also = ['foo', 'foo']
 
 
120
        self.assertEqual(['foo'], command.get_see_also())
 
 
122
    def test_sorted(self):
 
 
123
        """_see_also is sorted by get_see_also."""
 
 
124
        class ACommand(commands.Command):
 
 
125
            _see_also = ['foo', 'bar']
 
 
127
        self.assertEqual(['bar', 'foo'], command.get_see_also())
 
 
129
    def test_additional_terms(self):
 
 
130
        """Additional terms can be supplied and are deduped and sorted."""
 
 
131
        class ACommand(commands.Command):
 
 
132
            _see_also = ['foo', 'bar']
 
 
134
        self.assertEqual(['bar', 'foo', 'gam'],
 
 
135
            command.get_see_also(['gam', 'bar', 'gam']))