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 ( |
5417.1.1
by Martin Pool
ScriptRunner can now cope with commands that prompt for input. |
19 |
commands, |
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
20 |
osutils, |
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
21 |
tests, |
5417.1.1
by Martin Pool
ScriptRunner can now cope with commands that prompt for input. |
22 |
ui, |
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
23 |
)
|
24 |
from bzrlib.tests import script |
|
25 |
||
26 |
||
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
27 |
class TestSyntax(tests.TestCase): |
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
28 |
|
29 |
def test_comment_is_ignored(self): |
|
30 |
self.assertEquals([], script._script_to_commands('#comment\n')) |
|
31 |
||
5417.1.5
by Martin Pool
Better handling of blank lines in test scripts |
32 |
def test_trim_blank_lines(self): |
33 |
"""Blank lines are respected, but trimmed at the start and end.
|
|
34 |
||
35 |
Python triple-quoted syntax is going to give stubby/empty blank lines
|
|
36 |
right at the start and the end. These are cut off so that callers don't
|
|
37 |
need special syntax to avoid them.
|
|
38 |
||
39 |
However we do want to be able to match commands that emit blank lines.
|
|
40 |
"""
|
|
41 |
self.assertEquals([ |
|
42 |
(['bar'], None, '\n', None), |
|
43 |
],
|
|
44 |
script._script_to_commands(""" |
|
45 |
$bar
|
|
46 |
||
47 |
""")) |
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
48 |
|
49 |
def test_simple_command(self): |
|
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
50 |
self.assertEquals([(['cd', 'trunk'], None, None, None)], |
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
51 |
script._script_to_commands('$ cd trunk')) |
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
52 |
|
4665.5.2
by Vincent Ladeuil
Handle simple, double and back quotes. |
53 |
def test_command_with_single_quoted_param(self): |
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
54 |
story = """$ bzr commit -m 'two words'""" |
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
55 |
self.assertEquals([(['bzr', 'commit', '-m', "'two words'"], |
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
56 |
None, None, None)], |
4665.5.2
by Vincent Ladeuil
Handle simple, double and back quotes. |
57 |
script._script_to_commands(story)) |
58 |
||
59 |
def test_command_with_double_quoted_param(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
60 |
story = """$ bzr commit -m "two words" """ |
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
61 |
self.assertEquals([(['bzr', 'commit', '-m', '"two words"'], |
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
62 |
None, None, None)], |
4665.5.2
by Vincent Ladeuil
Handle simple, double and back quotes. |
63 |
script._script_to_commands(story)) |
64 |
||
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
65 |
def test_command_with_input(self): |
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
66 |
self.assertEquals( |
67 |
[(['cat', '>file'], 'content\n', None, None)], |
|
68 |
script._script_to_commands('$ cat >file\n<content\n')) |
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
69 |
|
5283.1.2
by Martin Pool
ScriptRunner strips consistent leading indentation from scripts |
70 |
def test_indented(self): |
71 |
# scripts are commonly given indented within the test source code, and
|
|
72 |
# common indentation is stripped off
|
|
73 |
story = """ |
|
74 |
$ bzr add
|
|
75 |
adding file
|
|
76 |
adding file2
|
|
77 |
"""
|
|
78 |
self.assertEquals([(['bzr', 'add'], None, |
|
79 |
'adding file\nadding file2\n', None)], |
|
80 |
script._script_to_commands(story)) |
|
81 |
||
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
82 |
def test_command_with_output(self): |
83 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
84 |
$ bzr add
|
85 |
adding file
|
|
86 |
adding file2
|
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
87 |
"""
|
4665.5.7
by Vincent Ladeuil
Simplify output/errors handling. |
88 |
self.assertEquals([(['bzr', 'add'], None, |
89 |
'adding file\nadding file2\n', None)], |
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
90 |
script._script_to_commands(story)) |
91 |
||
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
92 |
def test_command_with_error(self): |
93 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
94 |
$ bzr branch foo
|
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
95 |
2>bzr: ERROR: Not a branch: "foo"
|
96 |
"""
|
|
97 |
self.assertEquals([(['bzr', 'branch', 'foo'], |
|
4665.5.7
by Vincent Ladeuil
Simplify output/errors handling. |
98 |
None, None, 'bzr: ERROR: Not a branch: "foo"\n')], |
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
99 |
script._script_to_commands(story)) |
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
100 |
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
101 |
def test_input_without_command(self): |
102 |
self.assertRaises(SyntaxError, script._script_to_commands, '<input') |
|
103 |
||
104 |
def test_output_without_command(self): |
|
105 |
self.assertRaises(SyntaxError, script._script_to_commands, '>input') |
|
106 |
||
4665.5.2
by Vincent Ladeuil
Handle simple, double and back quotes. |
107 |
def test_command_with_backquotes(self): |
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
108 |
story = """ |
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
109 |
$ foo = `bzr file-id toto`
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
110 |
"""
|
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
111 |
self.assertEquals([(['foo', '=', '`bzr file-id toto`'], |
112 |
None, None, None)], |
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
113 |
script._script_to_commands(story)) |
114 |
||
115 |
||
4665.5.18
by Vincent Ladeuil
Better redirection handling. |
116 |
class TestRedirections(tests.TestCase): |
117 |
||
118 |
def _check(self, in_name, out_name, out_mode, remaining, args): |
|
119 |
self.assertEqual(script._scan_redirection_options(args), |
|
120 |
(in_name, out_name, out_mode, remaining)) |
|
121 |
||
122 |
def test_no_redirection(self): |
|
123 |
self._check(None, None, None, [], []) |
|
124 |
self._check(None, None, None, ['foo', 'bar'], ['foo', 'bar']) |
|
125 |
||
126 |
def test_input_redirection(self): |
|
127 |
self._check('foo', None, None, [], ['<foo']) |
|
128 |
self._check('foo', None, None, ['bar'], ['bar', '<foo']) |
|
129 |
self._check('foo', None, None, ['bar'], ['bar', '<', 'foo']) |
|
130 |
self._check('foo', None, None, ['bar'], ['<foo', 'bar']) |
|
131 |
self._check('foo', None, None, ['bar', 'baz'], ['bar', '<foo', 'baz']) |
|
132 |
||
133 |
def test_output_redirection(self): |
|
134 |
self._check(None, 'foo', 'wb+', [], ['>foo']) |
|
135 |
self._check(None, 'foo', 'wb+', ['bar'], ['bar', '>foo']) |
|
136 |
self._check(None, 'foo', 'wb+', ['bar'], ['bar', '>', 'foo']) |
|
137 |
self._check(None, 'foo', 'ab+', [], ['>>foo']) |
|
138 |
self._check(None, 'foo', 'ab+', ['bar'], ['bar', '>>foo']) |
|
139 |
self._check(None, 'foo', 'ab+', ['bar'], ['bar', '>>', 'foo']) |
|
140 |
||
141 |
def test_redirection_syntax_errors(self): |
|
142 |
self._check('', None, None, [], ['<']) |
|
143 |
self._check(None, '', 'wb+', [], ['>']) |
|
144 |
self._check(None, '', 'ab+', [], ['>>']) |
|
145 |
self._check('>', '', 'ab+', [], ['<', '>', '>>']) |
|
146 |
||
147 |
||
148 |
||
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
149 |
class TestExecution(script.TestCaseWithTransportAndScript): |
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
150 |
|
151 |
def test_unknown_command(self): |
|
152 |
self.assertRaises(SyntaxError, self.run_script, 'foo') |
|
153 |
||
4665.5.13
by Vincent Ladeuil
Script execution must stop on unexpected errors. |
154 |
def test_stops_on_unexpected_output(self): |
4665.5.6
by Vincent Ladeuil
Implement 'bzr' command. |
155 |
story = """ |
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
156 |
$ mkdir dir
|
157 |
$ cd dir
|
|
158 |
The cd command ouputs nothing
|
|
4665.5.6
by Vincent Ladeuil
Implement 'bzr' command. |
159 |
"""
|
160 |
self.assertRaises(AssertionError, self.run_script, story) |
|
161 |
||
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
162 |
|
4665.5.13
by Vincent Ladeuil
Script execution must stop on unexpected errors. |
163 |
def test_stops_on_unexpected_error(self): |
164 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
165 |
$ cat
|
4665.5.13
by Vincent Ladeuil
Script execution must stop on unexpected errors. |
166 |
<Hello
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
167 |
$ bzr not-a-command
|
4665.5.13
by Vincent Ladeuil
Script execution must stop on unexpected errors. |
168 |
"""
|
169 |
self.assertRaises(AssertionError, self.run_script, story) |
|
170 |
||
171 |
def test_continue_on_expected_error(self): |
|
172 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
173 |
$ bzr not-a-command
|
4665.5.13
by Vincent Ladeuil
Script execution must stop on unexpected errors. |
174 |
2>..."not-a-command"
|
175 |
"""
|
|
176 |
self.run_script(story) |
|
177 |
||
4665.5.16
by Vincent Ladeuil
Continue script execution based on status not error output. |
178 |
def test_continue_on_error_output(self): |
179 |
# The status matters, not the output
|
|
180 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
181 |
$ bzr init
|
182 |
$ cat >file
|
|
4665.5.16
by Vincent Ladeuil
Continue script execution based on status not error output. |
183 |
<Hello
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
184 |
$ bzr add file
|
185 |
$ bzr commit -m 'adding file'
|
|
4665.5.16
by Vincent Ladeuil
Continue script execution based on status not error output. |
186 |
"""
|
187 |
self.run_script(story) |
|
188 |
||
4665.5.12
by Vincent Ladeuil
Support '...' in expected strings. |
189 |
def test_ellipsis_output(self): |
190 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
191 |
$ cat
|
4665.5.12
by Vincent Ladeuil
Support '...' in expected strings. |
192 |
<first line
|
193 |
<second line
|
|
194 |
<last line
|
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
195 |
first line
|
196 |
...
|
|
197 |
last line
|
|
4665.5.12
by Vincent Ladeuil
Support '...' in expected strings. |
198 |
"""
|
199 |
self.run_script(story) |
|
200 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
201 |
$ bzr not-a-command
|
4665.5.12
by Vincent Ladeuil
Support '...' in expected strings. |
202 |
2>..."not-a-command"
|
203 |
"""
|
|
204 |
self.run_script(story) |
|
205 |
||
206 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
207 |
$ bzr branch not-a-branch
|
4665.5.12
by Vincent Ladeuil
Support '...' in expected strings. |
208 |
2>bzr: ERROR: Not a branch...not-a-branch/".
|
209 |
"""
|
|
210 |
self.run_script(story) |
|
211 |
||
212 |
||
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
213 |
class TestArgumentProcessing(script.TestCaseWithTransportAndScript): |
214 |
||
215 |
def test_globing(self): |
|
216 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
217 |
$ echo cat >cat
|
218 |
$ echo dog >dog
|
|
219 |
$ cat *
|
|
220 |
cat
|
|
221 |
dog
|
|
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
222 |
""") |
223 |
||
224 |
def test_quoted_globbing(self): |
|
225 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
226 |
$ echo cat >cat
|
227 |
$ cat '*'
|
|
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
228 |
2>*: No such file or directory
|
229 |
""") |
|
230 |
||
231 |
def test_quotes_removal(self): |
|
232 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
233 |
$ echo 'cat' "dog" '"chicken"' "'dragon'"
|
234 |
cat dog "chicken" 'dragon'
|
|
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
235 |
""") |
236 |
||
237 |
||
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
238 |
class TestCat(script.TestCaseWithTransportAndScript): |
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
239 |
|
240 |
def test_cat_usage(self): |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
241 |
self.assertRaises(SyntaxError, self.run_script, 'cat foo <bar') |
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
242 |
|
243 |
def test_cat_input_to_output(self): |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
244 |
retcode, out, err = self.run_command(['cat'], |
245 |
'content\n', 'content\n', None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
246 |
self.assertEquals('content\n', out) |
247 |
self.assertEquals(None, err) |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
248 |
|
249 |
def test_cat_file_to_output(self): |
|
250 |
self.build_tree_contents([('file', 'content\n')]) |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
251 |
retcode, out, err = self.run_command(['cat', 'file'], |
252 |
None, 'content\n', None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
253 |
self.assertEquals('content\n', out) |
254 |
self.assertEquals(None, err) |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
255 |
|
256 |
def test_cat_input_to_file(self): |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
257 |
retcode, out, err = self.run_command(['cat', '>file'], |
258 |
'content\n', None, None) |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
259 |
self.assertFileEqual('content\n', 'file') |
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
260 |
self.assertEquals(None, out) |
261 |
self.assertEquals(None, err) |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
262 |
retcode, out, err = self.run_command(['cat', '>>file'], |
263 |
'more\n', None, None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
264 |
self.assertFileEqual('content\nmore\n', 'file') |
265 |
self.assertEquals(None, out) |
|
266 |
self.assertEquals(None, err) |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
267 |
|
268 |
def test_cat_file_to_file(self): |
|
269 |
self.build_tree_contents([('file', 'content\n')]) |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
270 |
retcode, out, err = self.run_command(['cat', 'file', '>file2'], |
271 |
None, None, None) |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
272 |
self.assertFileEqual('content\n', 'file2') |
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
273 |
|
4665.5.19
by Vincent Ladeuil
Implement globbing and enhance cat to accept multiple files. |
274 |
def test_cat_files_to_file(self): |
275 |
self.build_tree_contents([('cat', 'cat\n')]) |
|
276 |
self.build_tree_contents([('dog', 'dog\n')]) |
|
277 |
retcode, out, err = self.run_command(['cat', 'cat', 'dog', '>file'], |
|
278 |
None, None, None) |
|
279 |
self.assertFileEqual('cat\ndog\n', 'file') |
|
280 |
||
4665.5.18
by Vincent Ladeuil
Better redirection handling. |
281 |
def test_cat_bogus_input_file(self): |
282 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
283 |
$ cat <file
|
4665.5.18
by Vincent Ladeuil
Better redirection handling. |
284 |
2>file: No such file or directory
|
285 |
""") |
|
286 |
||
287 |
def test_cat_bogus_output_file(self): |
|
288 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
289 |
$ cat >
|
4665.5.18
by Vincent Ladeuil
Better redirection handling. |
290 |
2>: No such file or directory
|
291 |
""") |
|
292 |
||
293 |
def test_echo_bogus_output_file(self): |
|
294 |
# We need a backing file sysytem for that test so it can't be in
|
|
295 |
# TestEcho
|
|
296 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
297 |
$ echo >
|
4665.5.18
by Vincent Ladeuil
Better redirection handling. |
298 |
2>: No such file or directory
|
299 |
""") |
|
300 |
||
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
301 |
|
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
302 |
class TestMkdir(script.TestCaseWithTransportAndScript): |
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
303 |
|
304 |
def test_mkdir_usage(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
305 |
self.assertRaises(SyntaxError, self.run_script, '$ mkdir') |
306 |
self.assertRaises(SyntaxError, self.run_script, '$ mkdir foo bar') |
|
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
307 |
|
308 |
def test_mkdir_jailed(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
309 |
self.assertRaises(ValueError, self.run_script, '$ mkdir /out-of-jail') |
310 |
self.assertRaises(ValueError, self.run_script, '$ mkdir ../out-of-jail') |
|
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
311 |
|
312 |
def test_mkdir_in_jail(self): |
|
313 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
314 |
$ mkdir dir
|
315 |
$ cd dir
|
|
316 |
$ mkdir ../dir2
|
|
317 |
$ cd ..
|
|
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
318 |
""") |
319 |
self.failUnlessExists('dir') |
|
320 |
self.failUnlessExists('dir2') |
|
321 |
||
322 |
||
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
323 |
class TestCd(script.TestCaseWithTransportAndScript): |
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
324 |
|
325 |
def test_cd_usage(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
326 |
self.assertRaises(SyntaxError, self.run_script, '$ cd foo bar') |
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
327 |
|
328 |
def test_cd_out_of_jail(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
329 |
self.assertRaises(ValueError, self.run_script, '$ cd /out-of-jail') |
330 |
self.assertRaises(ValueError, self.run_script, '$ cd ..') |
|
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
331 |
|
332 |
def test_cd_dir_and_back_home(self): |
|
333 |
self.assertEquals(self.test_dir, osutils.getcwd()) |
|
334 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
335 |
$ mkdir dir
|
336 |
$ cd dir
|
|
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
337 |
""") |
338 |
self.assertEquals(osutils.pathjoin(self.test_dir, 'dir'), |
|
339 |
osutils.getcwd()) |
|
340 |
||
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
341 |
self.run_script('$ cd') |
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
342 |
self.assertEquals(self.test_dir, osutils.getcwd()) |
4665.5.6
by Vincent Ladeuil
Implement 'bzr' command. |
343 |
|
344 |
||
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
345 |
class TestBzr(script.TestCaseWithTransportAndScript): |
4665.5.6
by Vincent Ladeuil
Implement 'bzr' command. |
346 |
|
347 |
def test_bzr_smoke(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
348 |
self.run_script('$ bzr init branch') |
4665.5.6
by Vincent Ladeuil
Implement 'bzr' command. |
349 |
self.failUnlessExists('branch') |
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
350 |
|
351 |
||
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
352 |
class TestEcho(script.TestCaseWithMemoryTransportAndScript): |
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
353 |
|
354 |
def test_echo_usage(self): |
|
355 |
story = """ |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
356 |
$ echo foo
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
357 |
<bar
|
358 |
"""
|
|
359 |
self.assertRaises(SyntaxError, self.run_script, story) |
|
360 |
||
4789.18.1
by John Arbash Meinel
Rework test_script a little bit. |
361 |
def test_echo_input(self): |
362 |
self.assertRaises(SyntaxError, self.run_script, """ |
|
363 |
$ echo <foo
|
|
364 |
""") |
|
365 |
||
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
366 |
def test_echo_to_output(self): |
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
367 |
retcode, out, err = self.run_command(['echo'], None, '\n', None) |
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
368 |
self.assertEquals('\n', out) |
369 |
self.assertEquals(None, err) |
|
370 |
||
371 |
def test_echo_some_to_output(self): |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
372 |
retcode, out, err = self.run_command(['echo', 'hello'], |
373 |
None, 'hello\n', None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
374 |
self.assertEquals('hello\n', out) |
375 |
self.assertEquals(None, err) |
|
376 |
||
377 |
def test_echo_more_output(self): |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
378 |
retcode, out, err = self.run_command( |
379 |
['echo', 'hello', 'happy', 'world'], |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
380 |
None, 'hello happy world\n', None) |
381 |
self.assertEquals('hello happy world\n', out) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
382 |
self.assertEquals(None, err) |
383 |
||
384 |
def test_echo_appended(self): |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
385 |
retcode, out, err = self.run_command(['echo', 'hello', '>file'], |
386 |
None, None, None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
387 |
self.assertEquals(None, out) |
388 |
self.assertEquals(None, err) |
|
389 |
self.assertFileEqual('hello\n', 'file') |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
390 |
retcode, out, err = self.run_command(['echo', 'happy', '>>file'], |
391 |
None, None, None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
392 |
self.assertEquals(None, out) |
393 |
self.assertEquals(None, err) |
|
394 |
self.assertFileEqual('hello\nhappy\n', 'file') |
|
4665.5.15
by Vincent Ladeuil
Catch the retcode for all commands. |
395 |
|
5417.1.5
by Martin Pool
Better handling of blank lines in test scripts |
396 |
def test_empty_line_in_output_is_respected(self): |
397 |
self.run_script(""" |
|
398 |
$ echo
|
|
399 |
||
400 |
$ echo bar
|
|
401 |
bar
|
|
402 |
""") |
|
403 |
||
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
404 |
|
405 |
class TestRm(script.TestCaseWithTransportAndScript): |
|
406 |
||
407 |
def test_rm_usage(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
408 |
self.assertRaises(SyntaxError, self.run_script, '$ rm') |
409 |
self.assertRaises(SyntaxError, self.run_script, '$ rm -ff foo') |
|
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
410 |
|
411 |
def test_rm_file(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
412 |
self.run_script('$ echo content >file') |
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
413 |
self.failUnlessExists('file') |
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
414 |
self.run_script('$ rm file') |
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
415 |
self.failIfExists('file') |
416 |
||
417 |
def test_rm_file_force(self): |
|
418 |
self.failIfExists('file') |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
419 |
self.run_script('$ rm -f file') |
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
420 |
self.failIfExists('file') |
421 |
||
422 |
def test_rm_files(self): |
|
423 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
424 |
$ echo content >file
|
425 |
$ echo content >file2
|
|
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
426 |
""") |
427 |
self.failUnlessExists('file2') |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
428 |
self.run_script('$ rm file file2') |
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
429 |
self.failIfExists('file2') |
430 |
||
431 |
def test_rm_dir(self): |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
432 |
self.run_script('$ mkdir dir') |
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
433 |
self.failUnlessExists('dir') |
434 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
435 |
$ rm dir
|
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
436 |
2>rm: cannot remove 'dir': Is a directory
|
437 |
""") |
|
438 |
self.failUnlessExists('dir') |
|
439 |
||
440 |
def test_rm_dir_recursive(self): |
|
441 |
self.run_script(""" |
|
4665.5.20
by Vincent Ladeuil
Fixed as per Martin's review. |
442 |
$ mkdir dir
|
443 |
$ rm -r dir
|
|
4665.5.17
by Vincent Ladeuil
Implement 'rm' command. |
444 |
""") |
445 |
self.failIfExists('dir') |
|
4953.2.1
by Neil Martinsen-Burrell
add an mv command to shell-like tests |
446 |
|
447 |
||
448 |
class TestMv(script.TestCaseWithTransportAndScript): |
|
449 |
||
450 |
def test_usage(self): |
|
451 |
self.assertRaises(SyntaxError, self.run_script, '$ mv') |
|
452 |
self.assertRaises(SyntaxError, self.run_script, '$ mv f') |
|
453 |
self.assertRaises(SyntaxError, self.run_script, '$ mv f1 f2 f3') |
|
454 |
||
455 |
def test_move_file(self): |
|
456 |
self.run_script('$ echo content >file') |
|
457 |
self.failUnlessExists('file') |
|
458 |
self.run_script('$ mv file new_name') |
|
459 |
self.failIfExists('file') |
|
460 |
self.failUnlessExists('new_name') |
|
461 |
||
4953.2.3
by Vincent Ladeuil
Use os.rename() and fix some typos. |
462 |
def test_move_unknown_file(self): |
463 |
self.assertRaises(AssertionError, |
|
464 |
self.run_script, '$ mv unknown does-not-exist') |
|
465 |
||
4953.2.1
by Neil Martinsen-Burrell
add an mv command to shell-like tests |
466 |
def test_move_dir(self): |
467 |
self.run_script(""" |
|
468 |
$ mkdir dir
|
|
469 |
$ echo content >dir/file
|
|
470 |
""") |
|
471 |
self.run_script('$ mv dir new_name') |
|
472 |
self.failIfExists('dir') |
|
473 |
self.failUnlessExists('new_name') |
|
474 |
self.failUnlessExists('new_name/file') |
|
4953.2.3
by Vincent Ladeuil
Use os.rename() and fix some typos. |
475 |
|
4953.2.2
by Neil Martinsen-Burrell
added a test for "mv file dir" and a NEWS entry |
476 |
def test_move_file_into_dir(self): |
477 |
self.run_script(""" |
|
478 |
$ mkdir dir
|
|
479 |
$ echo content > file
|
|
480 |
""") |
|
481 |
self.run_script('$ mv file dir') |
|
482 |
self.failUnlessExists('dir') |
|
483 |
self.failIfExists('file') |
|
484 |
self.failUnlessExists('dir/file') |
|
485 |
||
5417.1.1
by Martin Pool
ScriptRunner can now cope with commands that prompt for input. |
486 |
|
487 |
class cmd_test_confirm(commands.Command): |
|
488 |
||
489 |
def run(self): |
|
490 |
if ui.ui_factory.get_boolean( |
|
491 |
'Really do it', |
|
492 |
# 'bzrlib.tests.test_script.confirm',
|
|
493 |
# {}
|
|
494 |
):
|
|
5417.1.3
by Martin Pool
Additional script tests |
495 |
self.outf.write('Do it!\n') |
5417.1.1
by Martin Pool
ScriptRunner can now cope with commands that prompt for input. |
496 |
else: |
5417.1.3
by Martin Pool
Additional script tests |
497 |
print 'ok, no' |
5417.1.1
by Martin Pool
ScriptRunner can now cope with commands that prompt for input. |
498 |
|
499 |
||
500 |
class TestUserInteraction(script.TestCaseWithMemoryTransportAndScript): |
|
501 |
||
502 |
def test_confirm_action(self): |
|
5417.1.2
by Martin Pool
Additional docs; yay testdoc |
503 |
"""You can write tests that demonstrate user confirmation.
|
504 |
|
|
505 |
Specifically, ScriptRunner does't care if the output line for the prompt
|
|
506 |
isn't terminated by a newline from the program; it's implicitly terminated
|
|
507 |
by the input.
|
|
508 |
"""
|
|
5417.1.1
by Martin Pool
ScriptRunner can now cope with commands that prompt for input. |
509 |
commands.builtin_command_registry.register(cmd_test_confirm) |
510 |
self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm') |
|
511 |
self.run_script(""" |
|
512 |
$ bzr test-confirm
|
|
513 |
2>Really do it? [y/n]:
|
|
514 |
<yes
|
|
5417.1.3
by Martin Pool
Additional script tests |
515 |
Do it!
|
516 |
$ bzr test-confirm
|
|
517 |
2>Really do it? [y/n]:
|
|
518 |
<no
|
|
519 |
ok, no
|
|
5417.1.1
by Martin Pool
ScriptRunner can now cope with commands that prompt for input. |
520 |
""") |
521 |