4763.2.4
by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry. |
1 |
# Copyright (C) 2009, 2010 Canonical Ltd
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write 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
|
|
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 |
|
5283.1.2
by Martin Pool
ScriptRunner strips consistent leading indentation from scripts |
54 |
def test_indented(self): |
55 |
# scripts are commonly given indented within the test source code, and
|
|
56 |
# common indentation is stripped off
|
|
57 |
story = """ |
|
58 |
$ bzr add
|
|
59 |
adding file
|
|
60 |
adding file2
|
|
61 |
"""
|
|
62 |
self.assertEquals([(['bzr', 'add'], None, |
|
63 |
'adding file\nadding file2\n', None)], |
|
64 |
script._script_to_commands(story)) |
|
65 |
||
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
66 |
def test_command_with_output(self): |
67 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
68 |
$ bzr add
|
69 |
adding file
|
|
70 |
adding file2
|
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
71 |
"""
|
4665.5.7
by Vincent Ladeuil
Simplify output/errors handling. |
72 |
self.assertEquals([(['bzr', 'add'], None, |
73 |
'adding file\nadding file2\n', None)], |
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
74 |
script._script_to_commands(story)) |
75 |
||
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
76 |
def test_command_with_error(self): |
77 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
78 |
$ bzr branch foo
|
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
79 |
2>bzr: ERROR: Not a branch: "foo"
|
80 |
"""
|
|
81 |
self.assertEquals([(['bzr', 'branch', 'foo'], |
|
4665.5.7
by Vincent Ladeuil
Simplify output/errors handling. |
82 |
None, None, 'bzr: ERROR: Not a branch: "foo"\n')], |
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
83 |
script._script_to_commands(story)) |
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
84 |
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
85 |
def test_input_without_command(self): |
86 |
self.assertRaises(SyntaxError, script._script_to_commands, '<input') |
|
87 |
||
88 |
def test_output_without_command(self): |
|
89 |
self.assertRaises(SyntaxError, script._script_to_commands, '>input') |
|
90 |
||
4665.5.2
by Vincent Ladeuil
Handle simple, double and back quotes. |
91 |
def test_command_with_backquotes(self): |
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
92 |
story = """ |
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
93 |
$ foo = `bzr file-id toto`
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
94 |
"""
|
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
95 |
self.assertEquals([(['foo', '=', '`bzr file-id toto`'], |
96 |
None, None, None)], |
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
97 |
script._script_to_commands(story)) |
98 |
||
99 |
||
4665.5.18
by Vincent Ladeuil
Better redirection handling. |
100 |
class TestRedirections(tests.TestCase): |
101 |
||
102 |
def _check(self, in_name, out_name, out_mode, remaining, args): |
|
103 |
self.assertEqual(script._scan_redirection_options(args), |
|
104 |
(in_name, out_name, out_mode, remaining)) |
|
105 |
||
106 |
def test_no_redirection(self): |
|
107 |
self._check(None, None, None, [], []) |
|
108 |
self._check(None, None, None, ['foo', 'bar'], ['foo', 'bar']) |
|
109 |
||
110 |
def test_input_redirection(self): |
|
111 |
self._check('foo', None, None, [], ['<foo']) |
|
112 |
self._check('foo', None, None, ['bar'], ['bar', '<foo']) |
|
113 |
self._check('foo', None, None, ['bar'], ['bar', '<', 'foo']) |
|
114 |
self._check('foo', None, None, ['bar'], ['<foo', 'bar']) |
|
115 |
self._check('foo', None, None, ['bar', 'baz'], ['bar', '<foo', 'baz']) |
|
116 |
||
117 |
def test_output_redirection(self): |
|
118 |
self._check(None, 'foo', 'wb+', [], ['>foo']) |
|
119 |
self._check(None, 'foo', 'wb+', ['bar'], ['bar', '>foo']) |
|
120 |
self._check(None, 'foo', 'wb+', ['bar'], ['bar', '>', 'foo']) |
|
121 |
self._check(None, 'foo', 'ab+', [], ['>>foo']) |
|
122 |
self._check(None, 'foo', 'ab+', ['bar'], ['bar', '>>foo']) |
|
123 |
self._check(None, 'foo', 'ab+', ['bar'], ['bar', '>>', 'foo']) |
|
124 |
||
125 |
def test_redirection_syntax_errors(self): |
|
126 |
self._check('', None, None, [], ['<']) |
|
127 |
self._check(None, '', 'wb+', [], ['>']) |
|
128 |
self._check(None, '', 'ab+', [], ['>>']) |
|
129 |
self._check('>', '', 'ab+', [], ['<', '>', '>>']) |
|
130 |
||
131 |
||
132 |
||
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
133 |
class TestExecution(script.TestCaseWithTransportAndScript): |
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
134 |
|
135 |
def test_unknown_command(self): |
|
136 |
self.assertRaises(SyntaxError, self.run_script, 'foo') |
|
137 |
||
4665.5.13
by Vincent Ladeuil
Script execution must stop on unexpected errors. |
138 |
def test_stops_on_unexpected_output(self): |
4665.5.6
by Vincent Ladeuil
Implement 'bzr' command. |
139 |
story = """ |
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
140 |
$ mkdir dir
|
141 |
$ cd dir
|
|
142 |
The cd command ouputs nothing
|
|
4665.5.6
by Vincent Ladeuil
Implement 'bzr' command. |
143 |
"""
|
144 |
self.assertRaises(AssertionError, self.run_script, story) |
|
145 |
||
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
146 |
|
4665.5.13
by Vincent Ladeuil
Script execution must stop on unexpected errors. |
147 |
def test_stops_on_unexpected_error(self): |
148 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
149 |
$ cat
|
4665.5.13
by Vincent Ladeuil
Script execution must stop on unexpected errors. |
150 |
<Hello
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
151 |
$ bzr not-a-command
|
4665.5.13
by Vincent Ladeuil
Script execution must stop on unexpected errors. |
152 |
"""
|
153 |
self.assertRaises(AssertionError, self.run_script, story) |
|
154 |
||
155 |
def test_continue_on_expected_error(self): |
|
156 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
157 |
$ bzr not-a-command
|
4665.5.13
by Vincent Ladeuil
Script execution must stop on unexpected errors. |
158 |
2>..."not-a-command"
|
159 |
"""
|
|
160 |
self.run_script(story) |
|
161 |
||
4665.5.16
by Vincent Ladeuil
Continue script execution based on status not error output. |
162 |
def test_continue_on_error_output(self): |
163 |
# The status matters, not the output
|
|
164 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
165 |
$ bzr init
|
166 |
$ cat >file
|
|
4665.5.16
by Vincent Ladeuil
Continue script execution based on status not error output. |
167 |
<Hello
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
168 |
$ bzr add file
|
169 |
$ bzr commit -m 'adding file'
|
|
4665.5.16
by Vincent Ladeuil
Continue script execution based on status not error output. |
170 |
"""
|
171 |
self.run_script(story) |
|
172 |
||
4665.5.12
by Vincent Ladeuil
Support '...' in expected strings. |
173 |
def test_ellipsis_output(self): |
174 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
175 |
$ cat
|
4665.5.12
by Vincent Ladeuil
Support '...' in expected strings. |
176 |
<first line
|
177 |
<second line
|
|
178 |
<last line
|
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
179 |
first line
|
180 |
...
|
|
181 |
last line
|
|
4665.5.12
by Vincent Ladeuil
Support '...' in expected strings. |
182 |
"""
|
183 |
self.run_script(story) |
|
184 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
185 |
$ bzr not-a-command
|
4665.5.12
by Vincent Ladeuil
Support '...' in expected strings. |
186 |
2>..."not-a-command"
|
187 |
"""
|
|
188 |
self.run_script(story) |
|
189 |
||
190 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
191 |
$ bzr branch not-a-branch
|
4665.5.12
by Vincent Ladeuil
Support '...' in expected strings. |
192 |
2>bzr: ERROR: Not a branch...not-a-branch/".
|
193 |
"""
|
|
194 |
self.run_script(story) |
|
195 |
||
196 |
||
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
197 |
class TestArgumentProcessing(script.TestCaseWithTransportAndScript): |
198 |
||
199 |
def test_globing(self): |
|
200 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
201 |
$ echo cat >cat
|
202 |
$ echo dog >dog
|
|
203 |
$ cat *
|
|
204 |
cat
|
|
205 |
dog
|
|
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
206 |
""") |
207 |
||
208 |
def test_quoted_globbing(self): |
|
209 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
210 |
$ echo cat >cat
|
211 |
$ cat '*'
|
|
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
212 |
2>*: No such file or directory
|
213 |
""") |
|
214 |
||
215 |
def test_quotes_removal(self): |
|
216 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
217 |
$ echo 'cat' "dog" '"chicken"' "'dragon'"
|
218 |
cat dog "chicken" 'dragon'
|
|
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
219 |
""") |
220 |
||
221 |
||
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
222 |
class TestCat(script.TestCaseWithTransportAndScript): |
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
223 |
|
224 |
def test_cat_usage(self): |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
225 |
self.assertRaises(SyntaxError, self.run_script, 'cat foo <bar') |
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
226 |
|
227 |
def test_cat_input_to_output(self): |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
228 |
retcode, out, err = self.run_command(['cat'], |
229 |
'content\n', 'content\n', None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
230 |
self.assertEquals('content\n', out) |
231 |
self.assertEquals(None, err) |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
232 |
|
233 |
def test_cat_file_to_output(self): |
|
234 |
self.build_tree_contents([('file', 'content\n')]) |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
235 |
retcode, out, err = self.run_command(['cat', 'file'], |
236 |
None, 'content\n', None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
237 |
self.assertEquals('content\n', out) |
238 |
self.assertEquals(None, err) |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
239 |
|
240 |
def test_cat_input_to_file(self): |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
241 |
retcode, out, err = self.run_command(['cat', '>file'], |
242 |
'content\n', None, None) |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
243 |
self.assertFileEqual('content\n', 'file') |
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
244 |
self.assertEquals(None, out) |
245 |
self.assertEquals(None, err) |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
246 |
retcode, out, err = self.run_command(['cat', '>>file'], |
247 |
'more\n', None, None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
248 |
self.assertFileEqual('content\nmore\n', 'file') |
249 |
self.assertEquals(None, out) |
|
250 |
self.assertEquals(None, err) |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
251 |
|
252 |
def test_cat_file_to_file(self): |
|
253 |
self.build_tree_contents([('file', 'content\n')]) |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
254 |
retcode, out, err = self.run_command(['cat', 'file', '>file2'], |
255 |
None, None, None) |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
256 |
self.assertFileEqual('content\n', 'file2') |
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
257 |
|
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
258 |
def test_cat_files_to_file(self): |
259 |
self.build_tree_contents([('cat', 'cat\n')]) |
|
260 |
self.build_tree_contents([('dog', 'dog\n')]) |
|
261 |
retcode, out, err = self.run_command(['cat', 'cat', 'dog', '>file'], |
|
262 |
None, None, None) |
|
263 |
self.assertFileEqual('cat\ndog\n', 'file') |
|
264 |
||
4665.5.18
by Vincent Ladeuil
Better redirection handling. |
265 |
def test_cat_bogus_input_file(self): |
266 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
267 |
$ cat <file
|
4665.5.18
by Vincent Ladeuil
Better redirection handling. |
268 |
2>file: No such file or directory
|
269 |
""") |
|
270 |
||
271 |
def test_cat_bogus_output_file(self): |
|
272 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
273 |
$ cat >
|
4665.5.18
by Vincent Ladeuil
Better redirection handling. |
274 |
2>: No such file or directory
|
275 |
""") |
|
276 |
||
277 |
def test_echo_bogus_output_file(self): |
|
278 |
# We need a backing file sysytem for that test so it can't be in
|
|
279 |
# TestEcho
|
|
280 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
281 |
$ echo >
|
4665.5.18
by Vincent Ladeuil
Better redirection handling. |
282 |
2>: No such file or directory
|
283 |
""") |
|
284 |
||
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
285 |
|
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
286 |
class TestMkdir(script.TestCaseWithTransportAndScript): |
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
287 |
|
288 |
def test_mkdir_usage(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
289 |
self.assertRaises(SyntaxError, self.run_script, '$ mkdir') |
290 |
self.assertRaises(SyntaxError, self.run_script, '$ mkdir foo bar') |
|
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
291 |
|
292 |
def test_mkdir_jailed(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
293 |
self.assertRaises(ValueError, self.run_script, '$ mkdir /out-of-jail') |
294 |
self.assertRaises(ValueError, self.run_script, '$ mkdir ../out-of-jail') |
|
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
295 |
|
296 |
def test_mkdir_in_jail(self): |
|
297 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
298 |
$ mkdir dir
|
299 |
$ cd dir
|
|
300 |
$ mkdir ../dir2
|
|
301 |
$ cd ..
|
|
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
302 |
""") |
303 |
self.failUnlessExists('dir') |
|
304 |
self.failUnlessExists('dir2') |
|
305 |
||
306 |
||
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
307 |
class TestCd(script.TestCaseWithTransportAndScript): |
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
308 |
|
309 |
def test_cd_usage(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
310 |
self.assertRaises(SyntaxError, self.run_script, '$ cd foo bar') |
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
311 |
|
312 |
def test_cd_out_of_jail(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
313 |
self.assertRaises(ValueError, self.run_script, '$ cd /out-of-jail') |
314 |
self.assertRaises(ValueError, self.run_script, '$ cd ..') |
|
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
315 |
|
316 |
def test_cd_dir_and_back_home(self): |
|
317 |
self.assertEquals(self.test_dir, osutils.getcwd()) |
|
318 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
319 |
$ mkdir dir
|
320 |
$ cd dir
|
|
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
321 |
""") |
322 |
self.assertEquals(osutils.pathjoin(self.test_dir, 'dir'), |
|
323 |
osutils.getcwd()) |
|
324 |
||
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
325 |
self.run_script('$ cd') |
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
326 |
self.assertEquals(self.test_dir, osutils.getcwd()) |
4665.5.6
by Vincent Ladeuil
Implement 'bzr' command. |
327 |
|
328 |
||
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
329 |
class TestBzr(script.TestCaseWithTransportAndScript): |
4665.5.6
by Vincent Ladeuil
Implement 'bzr' command. |
330 |
|
331 |
def test_bzr_smoke(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
332 |
self.run_script('$ bzr init branch') |
4665.5.6
by Vincent Ladeuil
Implement 'bzr' command. |
333 |
self.failUnlessExists('branch') |
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
334 |
|
335 |
||
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
336 |
class TestEcho(script.TestCaseWithMemoryTransportAndScript): |
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
337 |
|
338 |
def test_echo_usage(self): |
|
339 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
340 |
$ echo foo
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
341 |
<bar
|
342 |
"""
|
|
343 |
self.assertRaises(SyntaxError, self.run_script, story) |
|
344 |
||
4789.18.1
by John Arbash Meinel
Rework test_script a little bit. |
345 |
def test_echo_input(self): |
346 |
self.assertRaises(SyntaxError, self.run_script, """ |
|
347 |
$ echo <foo
|
|
348 |
""") |
|
349 |
||
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
350 |
def test_echo_to_output(self): |
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
351 |
retcode, out, err = self.run_command(['echo'], None, '\n', None) |
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
352 |
self.assertEquals('\n', out) |
353 |
self.assertEquals(None, err) |
|
354 |
||
355 |
def test_echo_some_to_output(self): |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
356 |
retcode, out, err = self.run_command(['echo', 'hello'], |
357 |
None, 'hello\n', None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
358 |
self.assertEquals('hello\n', out) |
359 |
self.assertEquals(None, err) |
|
360 |
||
361 |
def test_echo_more_output(self): |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
362 |
retcode, out, err = self.run_command( |
363 |
['echo', 'hello', 'happy', 'world'], |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
364 |
None, 'hello happy world\n', None) |
365 |
self.assertEquals('hello happy world\n', out) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
366 |
self.assertEquals(None, err) |
367 |
||
368 |
def test_echo_appended(self): |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
369 |
retcode, out, err = self.run_command(['echo', 'hello', '>file'], |
370 |
None, None, None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
371 |
self.assertEquals(None, out) |
372 |
self.assertEquals(None, err) |
|
373 |
self.assertFileEqual('hello\n', 'file') |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
374 |
retcode, out, err = self.run_command(['echo', 'happy', '>>file'], |
375 |
None, None, None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
376 |
self.assertEquals(None, out) |
377 |
self.assertEquals(None, err) |
|
378 |
self.assertFileEqual('hello\nhappy\n', 'file') |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
379 |
|
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
380 |
|
381 |
class TestRm(script.TestCaseWithTransportAndScript): |
|
382 |
||
383 |
def test_rm_usage(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
384 |
self.assertRaises(SyntaxError, self.run_script, '$ rm') |
385 |
self.assertRaises(SyntaxError, self.run_script, '$ rm -ff foo') |
|
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
386 |
|
387 |
def test_rm_file(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
388 |
self.run_script('$ echo content >file') |
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
389 |
self.failUnlessExists('file') |
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
390 |
self.run_script('$ rm file') |
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
391 |
self.failIfExists('file') |
392 |
||
393 |
def test_rm_file_force(self): |
|
394 |
self.failIfExists('file') |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
395 |
self.run_script('$ rm -f file') |
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
396 |
self.failIfExists('file') |
397 |
||
398 |
def test_rm_files(self): |
|
399 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
400 |
$ echo content >file
|
401 |
$ echo content >file2
|
|
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
402 |
""") |
403 |
self.failUnlessExists('file2') |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
404 |
self.run_script('$ rm file file2') |
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
405 |
self.failIfExists('file2') |
406 |
||
407 |
def test_rm_dir(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
408 |
self.run_script('$ mkdir dir') |
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
409 |
self.failUnlessExists('dir') |
410 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
411 |
$ rm dir
|
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
412 |
2>rm: cannot remove 'dir': Is a directory
|
413 |
""") |
|
414 |
self.failUnlessExists('dir') |
|
415 |
||
416 |
def test_rm_dir_recursive(self): |
|
417 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
418 |
$ mkdir dir
|
419 |
$ rm -r dir
|
|
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
420 |
""") |
421 |
self.failIfExists('dir') |
|
4953.2.1
by Neil Martinsen-Burrell
add an mv command to shell-like tests |
422 |
|
423 |
||
424 |
class TestMv(script.TestCaseWithTransportAndScript): |
|
425 |
||
426 |
def test_usage(self): |
|
427 |
self.assertRaises(SyntaxError, self.run_script, '$ mv') |
|
428 |
self.assertRaises(SyntaxError, self.run_script, '$ mv f') |
|
429 |
self.assertRaises(SyntaxError, self.run_script, '$ mv f1 f2 f3') |
|
430 |
||
431 |
def test_move_file(self): |
|
432 |
self.run_script('$ echo content >file') |
|
433 |
self.failUnlessExists('file') |
|
434 |
self.run_script('$ mv file new_name') |
|
435 |
self.failIfExists('file') |
|
436 |
self.failUnlessExists('new_name') |
|
437 |
||
4953.2.3
by Vincent Ladeuil
Use os.rename() and fix some typos. |
438 |
def test_move_unknown_file(self): |
439 |
self.assertRaises(AssertionError, |
|
440 |
self.run_script, '$ mv unknown does-not-exist') |
|
441 |
||
4953.2.1
by Neil Martinsen-Burrell
add an mv command to shell-like tests |
442 |
def test_move_dir(self): |
443 |
self.run_script(""" |
|
444 |
$ mkdir dir
|
|
445 |
$ echo content >dir/file
|
|
446 |
""") |
|
447 |
self.run_script('$ mv dir new_name') |
|
448 |
self.failIfExists('dir') |
|
449 |
self.failUnlessExists('new_name') |
|
450 |
self.failUnlessExists('new_name/file') |
|
4953.2.3
by Vincent Ladeuil
Use os.rename() and fix some typos. |
451 |
|
4953.2.2
by Neil Martinsen-Burrell
added a test for "mv file dir" and a NEWS entry |
452 |
def test_move_file_into_dir(self): |
453 |
self.run_script(""" |
|
454 |
$ mkdir dir
|
|
455 |
$ echo content > file
|
|
456 |
""") |
|
457 |
self.run_script('$ mv file dir') |
|
458 |
self.failUnlessExists('dir') |
|
459 |
self.failIfExists('file') |
|
460 |
self.failUnlessExists('dir/file') |
|
461 |