/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_cmdline.py

Rework test_script a little bit.


Don't allow someone to request a stdin request to echo.
Echo never reads from stdin, it just echos its arguments.
You use 'cat' if you want to read from stdin.

A few other fixes because the tests were using filenames
that are actually illegal on Windows, rather than just
nonexistant.


Change the exception handling for commands so that
unknown errors don't get silently squashed and then
turn into hard-to-debug errors later.

test_script now passes on Windows.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 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
 
 
17
 
 
18
 
from bzrlib import (
19
 
    cmdline,
20
 
    tests)
21
 
 
22
 
class TestSplitter(tests.TestCase):
23
 
 
24
 
    def assertAsTokens(self, expected, line, single_quotes_allowed=False):
25
 
        s = cmdline.Splitter(line, single_quotes_allowed=single_quotes_allowed)
26
 
        self.assertEqual(expected, list(s))
27
 
 
28
 
    def test_simple(self):
29
 
        self.assertAsTokens([(False, u'foo'), (False, u'bar'), (False, u'baz')],
30
 
                            u'foo bar baz')
31
 
 
32
 
    def test_ignore_multiple_spaces(self):
33
 
        self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo  bar')
34
 
 
35
 
    def test_ignore_leading_space(self):
36
 
        self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'  foo bar')
37
 
 
38
 
    def test_ignore_trailing_space(self):
39
 
        self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo bar  ')
40
 
 
41
 
    def test_posix_quotations(self):
42
 
        self.assertAsTokens([(True, u'foo bar')], u"'foo bar'",
43
 
            single_quotes_allowed=True)
44
 
        self.assertAsTokens([(True, u'foo bar')], u"'fo''o b''ar'",
45
 
            single_quotes_allowed=True)
46
 
        self.assertAsTokens([(True, u'foo bar')], u'"fo""o b""ar"',
47
 
            single_quotes_allowed=True)
48
 
        self.assertAsTokens([(True, u'foo bar')], u'"fo"\'o b\'"ar"',
49
 
            single_quotes_allowed=True)
50
 
 
51
 
    def test_nested_quotations(self):
52
 
        self.assertAsTokens([(True, u'foo"" bar')], u"\"foo\\\"\\\" bar\"")
53
 
        self.assertAsTokens([(True, u'foo\'\' bar')], u"\"foo'' bar\"")
54
 
        self.assertAsTokens([(True, u'foo\'\' bar')], u"\"foo'' bar\"",
55
 
            single_quotes_allowed=True)
56
 
        self.assertAsTokens([(True, u'foo"" bar')], u"'foo\"\" bar'",
57
 
            single_quotes_allowed=True)
58
 
 
59
 
    def test_empty_result(self):
60
 
        self.assertAsTokens([], u'')
61
 
        self.assertAsTokens([], u'    ')
62
 
 
63
 
    def test_quoted_empty(self):
64
 
        self.assertAsTokens([(True, '')], u'""')
65
 
        self.assertAsTokens([(False, u"''")], u"''")
66
 
        self.assertAsTokens([(True, '')], u"''", single_quotes_allowed=True)
67
 
 
68
 
    def test_unicode_chars(self):
69
 
        self.assertAsTokens([(False, u'f\xb5\xee'), (False, u'\u1234\u3456')],
70
 
                             u'f\xb5\xee \u1234\u3456')
71
 
 
72
 
    def test_newline_in_quoted_section(self):
73
 
        self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u'"foo\nbar\nbaz\n"')
74
 
        self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u"'foo\nbar\nbaz\n'",
75
 
            single_quotes_allowed=True)
76
 
 
77
 
    def test_escape_chars(self):
78
 
        self.assertAsTokens([(False, u'foo\\bar')], u'foo\\bar')
79
 
 
80
 
    def test_escape_quote(self):
81
 
        self.assertAsTokens([(True, u'foo"bar')], u'"foo\\"bar"')
82
 
        self.assertAsTokens([(True, u'foo\\"bar')], u'"foo\\\\\\"bar"')
83
 
        self.assertAsTokens([(True, u'foo\\bar')], u'"foo\\\\"bar"')
84
 
 
85
 
    def test_double_escape(self):
86
 
        self.assertAsTokens([(True, u'foo\\\\bar')], u'"foo\\\\bar"')
87
 
        self.assertAsTokens([(False, u'foo\\\\bar')], u"foo\\\\bar")
88
 
 
89
 
    def test_multiple_quoted_args(self):
90
 
        self.assertAsTokens([(True, u'x x'), (True, u'y y')],
91
 
            u'"x x" "y y"')
92
 
        self.assertAsTokens([(True, u'x x'), (True, u'y y')],
93
 
            u'"x x" \'y y\'', single_quotes_allowed=True)