bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
4665.5.1
by Vincent Ladeuil
 Start some shell-like capability to write tests.  | 
1  | 
# Copyright (C) 2009 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  | 
||
| 
4665.5.5
by Vincent Ladeuil
 Implement 'cd' and 'mkdir'.  | 
17  | 
|
| 
4665.5.1
by Vincent Ladeuil
 Start some shell-like capability to write tests.  | 
18  | 
from bzrlib import (  | 
| 
4665.5.5
by Vincent Ladeuil
 Implement 'cd' and 'mkdir'.  | 
19  | 
osutils,  | 
| 
4665.5.1
by Vincent Ladeuil
 Start some shell-like capability to write tests.  | 
20  | 
tests,  | 
21  | 
    )
 | 
|
22  | 
from bzrlib.tests import script  | 
|
23  | 
||
24  | 
||
| 
4665.5.19
by Vincent Ladeuil
 Implement globbing and enhance cat to accept multiple files.  | 
25  | 
class TestSyntax(tests.TestCase):  | 
| 
4665.5.1
by Vincent Ladeuil
 Start some shell-like capability to write tests.  | 
26  | 
|
27  | 
def test_comment_is_ignored(self):  | 
|
28  | 
self.assertEquals([], script._script_to_commands('#comment\n'))  | 
|
29  | 
||
30  | 
def test_empty_line_is_ignored(self):  | 
|
31  | 
self.assertEquals([], script._script_to_commands('\n'))  | 
|
32  | 
||
33  | 
def test_simple_command(self):  | 
|
| 
4665.5.3
by Vincent Ladeuil
 Separate error from normal output.  | 
34  | 
self.assertEquals([(['cd', 'trunk'], None, None, None)],  | 
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
35  | 
script._script_to_commands('$ cd trunk'))  | 
| 
4665.5.1
by Vincent Ladeuil
 Start some shell-like capability to write tests.  | 
36  | 
|
| 
4665.5.2
by Vincent Ladeuil
 Handle simple, double and back quotes.  | 
37  | 
def test_command_with_single_quoted_param(self):  | 
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
38  | 
story = """$ bzr commit -m 'two words'"""  | 
| 
4665.5.19
by Vincent Ladeuil
 Implement globbing and enhance cat to accept multiple files.  | 
39  | 
self.assertEquals([(['bzr', 'commit', '-m', "'two words'"],  | 
| 
4665.5.3
by Vincent Ladeuil
 Separate error from normal output.  | 
40  | 
None, None, None)],  | 
| 
4665.5.2
by Vincent Ladeuil
 Handle simple, double and back quotes.  | 
41  | 
script._script_to_commands(story))  | 
42  | 
||
43  | 
def test_command_with_double_quoted_param(self):  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
44  | 
story = """$ bzr commit -m "two words" """  | 
| 
4665.5.19
by Vincent Ladeuil
 Implement globbing and enhance cat to accept multiple files.  | 
45  | 
self.assertEquals([(['bzr', 'commit', '-m', '"two words"'],  | 
| 
4665.5.3
by Vincent Ladeuil
 Separate error from normal output.  | 
46  | 
None, None, None)],  | 
| 
4665.5.2
by Vincent Ladeuil
 Handle simple, double and back quotes.  | 
47  | 
script._script_to_commands(story))  | 
48  | 
||
| 
4665.5.1
by Vincent Ladeuil
 Start some shell-like capability to write tests.  | 
49  | 
def test_command_with_input(self):  | 
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
50  | 
self.assertEquals(  | 
51  | 
[(['cat', '>file'], 'content\n', None, None)],  | 
|
52  | 
script._script_to_commands('$ cat >file\n<content\n'))  | 
|
| 
4665.5.1
by Vincent Ladeuil
 Start some shell-like capability to write tests.  | 
53  | 
|
54  | 
def test_command_with_output(self):  | 
|
55  | 
story = """  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
56  | 
$ bzr add
 | 
57  | 
adding file
 | 
|
58  | 
adding file2
 | 
|
| 
4665.5.1
by Vincent Ladeuil
 Start some shell-like capability to write tests.  | 
59  | 
"""
 | 
| 
4665.5.7
by Vincent Ladeuil
 Simplify output/errors handling.  | 
60  | 
self.assertEquals([(['bzr', 'add'], None,  | 
61  | 
'adding file\nadding file2\n', None)],  | 
|
| 
4665.5.1
by Vincent Ladeuil
 Start some shell-like capability to write tests.  | 
62  | 
script._script_to_commands(story))  | 
63  | 
||
| 
4665.5.3
by Vincent Ladeuil
 Separate error from normal output.  | 
64  | 
def test_command_with_error(self):  | 
65  | 
story = """  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
66  | 
$ bzr branch foo
 | 
| 
4665.5.3
by Vincent Ladeuil
 Separate error from normal output.  | 
67  | 
2>bzr: ERROR: Not a branch: "foo"
 | 
68  | 
"""
 | 
|
69  | 
self.assertEquals([(['bzr', 'branch', 'foo'],  | 
|
| 
4665.5.7
by Vincent Ladeuil
 Simplify output/errors handling.  | 
70  | 
None, None, 'bzr: ERROR: Not a branch: "foo"\n')],  | 
| 
4665.5.3
by Vincent Ladeuil
 Separate error from normal output.  | 
71  | 
script._script_to_commands(story))  | 
| 
4665.5.15
by Vincent Ladeuil
 Catch the retcode for all commands.  | 
72  | 
|
| 
4665.5.1
by Vincent Ladeuil
 Start some shell-like capability to write tests.  | 
73  | 
def test_input_without_command(self):  | 
74  | 
self.assertRaises(SyntaxError, script._script_to_commands, '<input')  | 
|
75  | 
||
76  | 
def test_output_without_command(self):  | 
|
77  | 
self.assertRaises(SyntaxError, script._script_to_commands, '>input')  | 
|
78  | 
||
| 
4665.5.2
by Vincent Ladeuil
 Handle simple, double and back quotes.  | 
79  | 
def test_command_with_backquotes(self):  | 
| 
4665.5.1
by Vincent Ladeuil
 Start some shell-like capability to write tests.  | 
80  | 
story = """  | 
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
81  | 
$ foo = `bzr file-id toto`
 | 
| 
4665.5.1
by Vincent Ladeuil
 Start some shell-like capability to write tests.  | 
82  | 
"""
 | 
| 
4665.5.3
by Vincent Ladeuil
 Separate error from normal output.  | 
83  | 
self.assertEquals([(['foo', '=', '`bzr file-id toto`'],  | 
84  | 
None, None, None)],  | 
|
| 
4665.5.1
by Vincent Ladeuil
 Start some shell-like capability to write tests.  | 
85  | 
script._script_to_commands(story))  | 
86  | 
||
87  | 
||
| 
4665.5.18
by Vincent Ladeuil
 Better redirection handling.  | 
88  | 
class TestRedirections(tests.TestCase):  | 
89  | 
||
90  | 
def _check(self, in_name, out_name, out_mode, remaining, args):  | 
|
91  | 
self.assertEqual(script._scan_redirection_options(args),  | 
|
92  | 
(in_name, out_name, out_mode, remaining))  | 
|
93  | 
||
94  | 
def test_no_redirection(self):  | 
|
95  | 
self._check(None, None, None, [], [])  | 
|
96  | 
self._check(None, None, None, ['foo', 'bar'], ['foo', 'bar'])  | 
|
97  | 
||
98  | 
def test_input_redirection(self):  | 
|
99  | 
self._check('foo', None, None, [], ['<foo'])  | 
|
100  | 
self._check('foo', None, None, ['bar'], ['bar', '<foo'])  | 
|
101  | 
self._check('foo', None, None, ['bar'], ['bar', '<', 'foo'])  | 
|
102  | 
self._check('foo', None, None, ['bar'], ['<foo', 'bar'])  | 
|
103  | 
self._check('foo', None, None, ['bar', 'baz'], ['bar', '<foo', 'baz'])  | 
|
104  | 
||
105  | 
def test_output_redirection(self):  | 
|
106  | 
self._check(None, 'foo', 'wb+', [], ['>foo'])  | 
|
107  | 
self._check(None, 'foo', 'wb+', ['bar'], ['bar', '>foo'])  | 
|
108  | 
self._check(None, 'foo', 'wb+', ['bar'], ['bar', '>', 'foo'])  | 
|
109  | 
self._check(None, 'foo', 'ab+', [], ['>>foo'])  | 
|
110  | 
self._check(None, 'foo', 'ab+', ['bar'], ['bar', '>>foo'])  | 
|
111  | 
self._check(None, 'foo', 'ab+', ['bar'], ['bar', '>>', 'foo'])  | 
|
112  | 
||
113  | 
def test_redirection_syntax_errors(self):  | 
|
114  | 
self._check('', None, None, [], ['<'])  | 
|
115  | 
self._check(None, '', 'wb+', [], ['>'])  | 
|
116  | 
self._check(None, '', 'ab+', [], ['>>'])  | 
|
117  | 
self._check('>', '', 'ab+', [], ['<', '>', '>>'])  | 
|
118  | 
||
119  | 
||
120  | 
||
| 
4665.5.19
by Vincent Ladeuil
 Implement globbing and enhance cat to accept multiple files.  | 
121  | 
class TestExecution(script.TestCaseWithTransportAndScript):  | 
| 
4665.5.4
by Vincent Ladeuil
 Implement a 'cat' command.  | 
122  | 
|
123  | 
def test_unknown_command(self):  | 
|
124  | 
self.assertRaises(SyntaxError, self.run_script, 'foo')  | 
|
125  | 
||
| 
4665.5.13
by Vincent Ladeuil
 Script execution must stop on unexpected errors.  | 
126  | 
def test_stops_on_unexpected_output(self):  | 
| 
4665.5.6
by Vincent Ladeuil
 Implement 'bzr' command.  | 
127  | 
story = """  | 
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
128  | 
$ mkdir dir
 | 
129  | 
$ cd dir
 | 
|
130  | 
The cd command ouputs nothing
 | 
|
| 
4665.5.6
by Vincent Ladeuil
 Implement 'bzr' command.  | 
131  | 
"""
 | 
132  | 
self.assertRaises(AssertionError, self.run_script, story)  | 
|
133  | 
||
| 
4665.5.4
by Vincent Ladeuil
 Implement a 'cat' command.  | 
134  | 
|
| 
4665.5.13
by Vincent Ladeuil
 Script execution must stop on unexpected errors.  | 
135  | 
def test_stops_on_unexpected_error(self):  | 
136  | 
story = """  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
137  | 
$ cat
 | 
| 
4665.5.13
by Vincent Ladeuil
 Script execution must stop on unexpected errors.  | 
138  | 
<Hello
 | 
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
139  | 
$ bzr not-a-command
 | 
| 
4665.5.13
by Vincent Ladeuil
 Script execution must stop on unexpected errors.  | 
140  | 
"""
 | 
141  | 
self.assertRaises(AssertionError, self.run_script, story)  | 
|
142  | 
||
143  | 
def test_continue_on_expected_error(self):  | 
|
144  | 
story = """  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
145  | 
$ bzr not-a-command
 | 
| 
4665.5.13
by Vincent Ladeuil
 Script execution must stop on unexpected errors.  | 
146  | 
2>..."not-a-command"
 | 
147  | 
"""
 | 
|
148  | 
self.run_script(story)  | 
|
149  | 
||
| 
4665.5.16
by Vincent Ladeuil
 Continue script execution based on status not error output.  | 
150  | 
def test_continue_on_error_output(self):  | 
151  | 
        # The status matters, not the output
 | 
|
152  | 
story = """  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
153  | 
$ bzr init
 | 
154  | 
$ cat >file
 | 
|
| 
4665.5.16
by Vincent Ladeuil
 Continue script execution based on status not error output.  | 
155  | 
<Hello
 | 
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
156  | 
$ bzr add file
 | 
157  | 
$ bzr commit -m 'adding file'
 | 
|
| 
4665.5.16
by Vincent Ladeuil
 Continue script execution based on status not error output.  | 
158  | 
"""
 | 
159  | 
self.run_script(story)  | 
|
160  | 
||
| 
4665.5.12
by Vincent Ladeuil
 Support '...' in expected strings.  | 
161  | 
def test_ellipsis_output(self):  | 
162  | 
story = """  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
163  | 
$ cat
 | 
| 
4665.5.12
by Vincent Ladeuil
 Support '...' in expected strings.  | 
164  | 
<first line
 | 
165  | 
<second line
 | 
|
166  | 
<last line
 | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
167  | 
first line
 | 
168  | 
...
 | 
|
169  | 
last line
 | 
|
| 
4665.5.12
by Vincent Ladeuil
 Support '...' in expected strings.  | 
170  | 
"""
 | 
171  | 
self.run_script(story)  | 
|
172  | 
story = """  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
173  | 
$ bzr not-a-command
 | 
| 
4665.5.12
by Vincent Ladeuil
 Support '...' in expected strings.  | 
174  | 
2>..."not-a-command"
 | 
175  | 
"""
 | 
|
176  | 
self.run_script(story)  | 
|
177  | 
||
178  | 
story = """  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
179  | 
$ bzr branch not-a-branch
 | 
| 
4665.5.12
by Vincent Ladeuil
 Support '...' in expected strings.  | 
180  | 
2>bzr: ERROR: Not a branch...not-a-branch/".
 | 
181  | 
"""
 | 
|
182  | 
self.run_script(story)  | 
|
183  | 
||
184  | 
||
| 
4665.5.19
by Vincent Ladeuil
 Implement globbing and enhance cat to accept multiple files.  | 
185  | 
class TestArgumentProcessing(script.TestCaseWithTransportAndScript):  | 
186  | 
||
187  | 
def test_globing(self):  | 
|
188  | 
self.run_script("""  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
189  | 
$ echo cat >cat
 | 
190  | 
$ echo dog >dog
 | 
|
191  | 
$ cat *
 | 
|
192  | 
cat
 | 
|
193  | 
dog
 | 
|
| 
4665.5.19
by Vincent Ladeuil
 Implement globbing and enhance cat to accept multiple files.  | 
194  | 
""")  | 
195  | 
||
196  | 
def test_quoted_globbing(self):  | 
|
197  | 
self.run_script("""  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
198  | 
$ echo cat >cat
 | 
199  | 
$ cat '*'
 | 
|
| 
4665.5.19
by Vincent Ladeuil
 Implement globbing and enhance cat to accept multiple files.  | 
200  | 
2>*: No such file or directory
 | 
201  | 
""")  | 
|
202  | 
||
203  | 
def test_quotes_removal(self):  | 
|
204  | 
self.run_script("""  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
205  | 
$ echo 'cat' "dog" '"chicken"' "'dragon'"
 | 
206  | 
cat dog "chicken" 'dragon'
 | 
|
| 
4665.5.19
by Vincent Ladeuil
 Implement globbing and enhance cat to accept multiple files.  | 
207  | 
""")  | 
208  | 
||
209  | 
||
| 
4665.5.11
by Vincent Ladeuil
 Create a new test case based on TestCaseWithMemoryTransport.  | 
210  | 
class TestCat(script.TestCaseWithTransportAndScript):  | 
| 
4665.5.4
by Vincent Ladeuil
 Implement a 'cat' command.  | 
211  | 
|
212  | 
def test_cat_usage(self):  | 
|
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
213  | 
self.assertRaises(SyntaxError, self.run_script, 'cat foo <bar')  | 
| 
4665.5.4
by Vincent Ladeuil
 Implement a 'cat' command.  | 
214  | 
|
215  | 
def test_cat_input_to_output(self):  | 
|
| 
4665.5.15
by Vincent Ladeuil
 Catch the retcode for all commands.  | 
216  | 
retcode, out, err = self.run_command(['cat'],  | 
217  | 
'content\n', 'content\n', None)  | 
|
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
218  | 
self.assertEquals('content\n', out)  | 
219  | 
self.assertEquals(None, err)  | 
|
| 
4665.5.4
by Vincent Ladeuil
 Implement a 'cat' command.  | 
220  | 
|
221  | 
def test_cat_file_to_output(self):  | 
|
222  | 
self.build_tree_contents([('file', 'content\n')])  | 
|
| 
4665.5.15
by Vincent Ladeuil
 Catch the retcode for all commands.  | 
223  | 
retcode, out, err = self.run_command(['cat', 'file'],  | 
224  | 
None, 'content\n', None)  | 
|
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
225  | 
self.assertEquals('content\n', out)  | 
226  | 
self.assertEquals(None, err)  | 
|
| 
4665.5.4
by Vincent Ladeuil
 Implement a 'cat' command.  | 
227  | 
|
228  | 
def test_cat_input_to_file(self):  | 
|
| 
4665.5.15
by Vincent Ladeuil
 Catch the retcode for all commands.  | 
229  | 
retcode, out, err = self.run_command(['cat', '>file'],  | 
230  | 
'content\n', None, None)  | 
|
| 
4665.5.4
by Vincent Ladeuil
 Implement a 'cat' command.  | 
231  | 
self.assertFileEqual('content\n', 'file')  | 
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
232  | 
self.assertEquals(None, out)  | 
233  | 
self.assertEquals(None, err)  | 
|
| 
4665.5.15
by Vincent Ladeuil
 Catch the retcode for all commands.  | 
234  | 
retcode, out, err = self.run_command(['cat', '>>file'],  | 
235  | 
'more\n', None, None)  | 
|
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
236  | 
self.assertFileEqual('content\nmore\n', 'file')  | 
237  | 
self.assertEquals(None, out)  | 
|
238  | 
self.assertEquals(None, err)  | 
|
| 
4665.5.4
by Vincent Ladeuil
 Implement a 'cat' command.  | 
239  | 
|
240  | 
def test_cat_file_to_file(self):  | 
|
241  | 
self.build_tree_contents([('file', 'content\n')])  | 
|
| 
4665.5.15
by Vincent Ladeuil
 Catch the retcode for all commands.  | 
242  | 
retcode, out, err = self.run_command(['cat', 'file', '>file2'],  | 
243  | 
None, None, None)  | 
|
| 
4665.5.4
by Vincent Ladeuil
 Implement a 'cat' command.  | 
244  | 
self.assertFileEqual('content\n', 'file2')  | 
| 
4665.5.5
by Vincent Ladeuil
 Implement 'cd' and 'mkdir'.  | 
245  | 
|
| 
4665.5.19
by Vincent Ladeuil
 Implement globbing and enhance cat to accept multiple files.  | 
246  | 
def test_cat_files_to_file(self):  | 
247  | 
self.build_tree_contents([('cat', 'cat\n')])  | 
|
248  | 
self.build_tree_contents([('dog', 'dog\n')])  | 
|
249  | 
retcode, out, err = self.run_command(['cat', 'cat', 'dog', '>file'],  | 
|
250  | 
None, None, None)  | 
|
251  | 
self.assertFileEqual('cat\ndog\n', 'file')  | 
|
252  | 
||
| 
4665.5.18
by Vincent Ladeuil
 Better redirection handling.  | 
253  | 
def test_cat_bogus_input_file(self):  | 
254  | 
self.run_script("""  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
255  | 
$ cat <file
 | 
| 
4665.5.18
by Vincent Ladeuil
 Better redirection handling.  | 
256  | 
2>file: No such file or directory
 | 
257  | 
""")  | 
|
258  | 
||
259  | 
def test_cat_bogus_output_file(self):  | 
|
260  | 
self.run_script("""  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
261  | 
$ cat >
 | 
| 
4665.5.18
by Vincent Ladeuil
 Better redirection handling.  | 
262  | 
2>: No such file or directory
 | 
263  | 
""")  | 
|
264  | 
||
265  | 
def test_echo_bogus_output_file(self):  | 
|
266  | 
        # We need a backing file sysytem for that test so it can't be in
 | 
|
267  | 
        # TestEcho
 | 
|
268  | 
self.run_script("""  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
269  | 
$ echo >
 | 
| 
4665.5.18
by Vincent Ladeuil
 Better redirection handling.  | 
270  | 
2>: No such file or directory
 | 
271  | 
""")  | 
|
272  | 
||
| 
4665.5.5
by Vincent Ladeuil
 Implement 'cd' and 'mkdir'.  | 
273  | 
|
| 
4665.5.11
by Vincent Ladeuil
 Create a new test case based on TestCaseWithMemoryTransport.  | 
274  | 
class TestMkdir(script.TestCaseWithTransportAndScript):  | 
| 
4665.5.5
by Vincent Ladeuil
 Implement 'cd' and 'mkdir'.  | 
275  | 
|
276  | 
def test_mkdir_usage(self):  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
277  | 
self.assertRaises(SyntaxError, self.run_script, '$ mkdir')  | 
278  | 
self.assertRaises(SyntaxError, self.run_script, '$ mkdir foo bar')  | 
|
| 
4665.5.5
by Vincent Ladeuil
 Implement 'cd' and 'mkdir'.  | 
279  | 
|
280  | 
def test_mkdir_jailed(self):  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
281  | 
self.assertRaises(ValueError, self.run_script, '$ mkdir /out-of-jail')  | 
282  | 
self.assertRaises(ValueError, self.run_script, '$ mkdir ../out-of-jail')  | 
|
| 
4665.5.5
by Vincent Ladeuil
 Implement 'cd' and 'mkdir'.  | 
283  | 
|
284  | 
def test_mkdir_in_jail(self):  | 
|
285  | 
self.run_script("""  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
286  | 
$ mkdir dir
 | 
287  | 
$ cd dir
 | 
|
288  | 
$ mkdir ../dir2
 | 
|
289  | 
$ cd ..
 | 
|
| 
4665.5.5
by Vincent Ladeuil
 Implement 'cd' and 'mkdir'.  | 
290  | 
""")  | 
291  | 
self.failUnlessExists('dir')  | 
|
292  | 
self.failUnlessExists('dir2')  | 
|
293  | 
||
294  | 
||
| 
4665.5.11
by Vincent Ladeuil
 Create a new test case based on TestCaseWithMemoryTransport.  | 
295  | 
class TestCd(script.TestCaseWithTransportAndScript):  | 
| 
4665.5.5
by Vincent Ladeuil
 Implement 'cd' and 'mkdir'.  | 
296  | 
|
297  | 
def test_cd_usage(self):  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
298  | 
self.assertRaises(SyntaxError, self.run_script, '$ cd foo bar')  | 
| 
4665.5.5
by Vincent Ladeuil
 Implement 'cd' and 'mkdir'.  | 
299  | 
|
300  | 
def test_cd_out_of_jail(self):  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
301  | 
self.assertRaises(ValueError, self.run_script, '$ cd /out-of-jail')  | 
302  | 
self.assertRaises(ValueError, self.run_script, '$ cd ..')  | 
|
| 
4665.5.5
by Vincent Ladeuil
 Implement 'cd' and 'mkdir'.  | 
303  | 
|
304  | 
def test_cd_dir_and_back_home(self):  | 
|
305  | 
self.assertEquals(self.test_dir, osutils.getcwd())  | 
|
306  | 
self.run_script("""  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
307  | 
$ mkdir dir
 | 
308  | 
$ cd dir
 | 
|
| 
4665.5.5
by Vincent Ladeuil
 Implement 'cd' and 'mkdir'.  | 
309  | 
""")  | 
310  | 
self.assertEquals(osutils.pathjoin(self.test_dir, 'dir'),  | 
|
311  | 
osutils.getcwd())  | 
|
312  | 
||
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
313  | 
self.run_script('$ cd')  | 
| 
4665.5.5
by Vincent Ladeuil
 Implement 'cd' and 'mkdir'.  | 
314  | 
self.assertEquals(self.test_dir, osutils.getcwd())  | 
| 
4665.5.6
by Vincent Ladeuil
 Implement 'bzr' command.  | 
315  | 
|
316  | 
||
| 
4665.5.11
by Vincent Ladeuil
 Create a new test case based on TestCaseWithMemoryTransport.  | 
317  | 
class TestBzr(script.TestCaseWithTransportAndScript):  | 
| 
4665.5.6
by Vincent Ladeuil
 Implement 'bzr' command.  | 
318  | 
|
319  | 
def test_bzr_smoke(self):  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
320  | 
self.run_script('$ bzr init branch')  | 
| 
4665.5.6
by Vincent Ladeuil
 Implement 'bzr' command.  | 
321  | 
self.failUnlessExists('branch')  | 
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
322  | 
|
323  | 
||
| 
4665.5.11
by Vincent Ladeuil
 Create a new test case based on TestCaseWithMemoryTransport.  | 
324  | 
class TestEcho(script.TestCaseWithMemoryTransportAndScript):  | 
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
325  | 
|
326  | 
def test_echo_usage(self):  | 
|
327  | 
story = """  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
328  | 
$ echo foo
 | 
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
329  | 
<bar
 | 
330  | 
"""
 | 
|
331  | 
self.assertRaises(SyntaxError, self.run_script, story)  | 
|
332  | 
||
| 
4789.18.1
by John Arbash Meinel
 Rework test_script a little bit.  | 
333  | 
def test_echo_input(self):  | 
334  | 
self.assertRaises(SyntaxError, self.run_script, """  | 
|
335  | 
            $ echo <foo
 | 
|
336  | 
""")  | 
|
337  | 
||
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
338  | 
def test_echo_to_output(self):  | 
| 
4665.5.15
by Vincent Ladeuil
 Catch the retcode for all commands.  | 
339  | 
retcode, out, err = self.run_command(['echo'], None, '\n', None)  | 
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
340  | 
self.assertEquals('\n', out)  | 
341  | 
self.assertEquals(None, err)  | 
|
342  | 
||
343  | 
def test_echo_some_to_output(self):  | 
|
| 
4665.5.15
by Vincent Ladeuil
 Catch the retcode for all commands.  | 
344  | 
retcode, out, err = self.run_command(['echo', 'hello'],  | 
345  | 
None, 'hello\n', None)  | 
|
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
346  | 
self.assertEquals('hello\n', out)  | 
347  | 
self.assertEquals(None, err)  | 
|
348  | 
||
349  | 
def test_echo_more_output(self):  | 
|
| 
4665.5.15
by Vincent Ladeuil
 Catch the retcode for all commands.  | 
350  | 
retcode, out, err = self.run_command(  | 
351  | 
['echo', 'hello', 'happy', 'world'],  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
352  | 
None, 'hello happy world\n', None)  | 
353  | 
self.assertEquals('hello happy world\n', out)  | 
|
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
354  | 
self.assertEquals(None, err)  | 
355  | 
||
356  | 
def test_echo_appended(self):  | 
|
| 
4665.5.15
by Vincent Ladeuil
 Catch the retcode for all commands.  | 
357  | 
retcode, out, err = self.run_command(['echo', 'hello', '>file'],  | 
358  | 
None, None, None)  | 
|
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
359  | 
self.assertEquals(None, out)  | 
360  | 
self.assertEquals(None, err)  | 
|
361  | 
self.assertFileEqual('hello\n', 'file')  | 
|
| 
4665.5.15
by Vincent Ladeuil
 Catch the retcode for all commands.  | 
362  | 
retcode, out, err = self.run_command(['echo', 'happy', '>>file'],  | 
363  | 
None, None, None)  | 
|
| 
4665.5.8
by Vincent Ladeuil
 Implement 'echo' command.  | 
364  | 
self.assertEquals(None, out)  | 
365  | 
self.assertEquals(None, err)  | 
|
366  | 
self.assertFileEqual('hello\nhappy\n', 'file')  | 
|
| 
4665.5.15
by Vincent Ladeuil
 Catch the retcode for all commands.  | 
367  | 
|
| 
4665.5.17
by Vincent Ladeuil
 Implement 'rm' command.  | 
368  | 
|
369  | 
class TestRm(script.TestCaseWithTransportAndScript):  | 
|
370  | 
||
371  | 
def test_rm_usage(self):  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
372  | 
self.assertRaises(SyntaxError, self.run_script, '$ rm')  | 
373  | 
self.assertRaises(SyntaxError, self.run_script, '$ rm -ff foo')  | 
|
| 
4665.5.17
by Vincent Ladeuil
 Implement 'rm' command.  | 
374  | 
|
375  | 
def test_rm_file(self):  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
376  | 
self.run_script('$ echo content >file')  | 
| 
4665.5.17
by Vincent Ladeuil
 Implement 'rm' command.  | 
377  | 
self.failUnlessExists('file')  | 
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
378  | 
self.run_script('$ rm file')  | 
| 
4665.5.17
by Vincent Ladeuil
 Implement 'rm' command.  | 
379  | 
self.failIfExists('file')  | 
380  | 
||
381  | 
def test_rm_file_force(self):  | 
|
382  | 
self.failIfExists('file')  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
383  | 
self.run_script('$ rm -f file')  | 
| 
4665.5.17
by Vincent Ladeuil
 Implement 'rm' command.  | 
384  | 
self.failIfExists('file')  | 
385  | 
||
386  | 
def test_rm_files(self):  | 
|
387  | 
self.run_script("""  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
388  | 
$ echo content >file
 | 
389  | 
$ echo content >file2
 | 
|
| 
4665.5.17
by Vincent Ladeuil
 Implement 'rm' command.  | 
390  | 
""")  | 
391  | 
self.failUnlessExists('file2')  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
392  | 
self.run_script('$ rm file file2')  | 
| 
4665.5.17
by Vincent Ladeuil
 Implement 'rm' command.  | 
393  | 
self.failIfExists('file2')  | 
394  | 
||
395  | 
def test_rm_dir(self):  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
396  | 
self.run_script('$ mkdir dir')  | 
| 
4665.5.17
by Vincent Ladeuil
 Implement 'rm' command.  | 
397  | 
self.failUnlessExists('dir')  | 
398  | 
self.run_script("""  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
399  | 
$ rm dir
 | 
| 
4665.5.17
by Vincent Ladeuil
 Implement 'rm' command.  | 
400  | 
2>rm: cannot remove 'dir': Is a directory
 | 
401  | 
""")  | 
|
402  | 
self.failUnlessExists('dir')  | 
|
403  | 
||
404  | 
def test_rm_dir_recursive(self):  | 
|
405  | 
self.run_script("""  | 
|
| 
4665.5.20
by Vincent Ladeuil
 Fixed as per Martin's review.  | 
406  | 
$ mkdir dir
 | 
407  | 
$ rm -r dir
 | 
|
| 
4665.5.17
by Vincent Ladeuil
 Implement 'rm' command.  | 
408  | 
""")  | 
409  | 
self.failIfExists('dir')  |