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.2
by Vincent Ladeuil
Handle simple, double and back quotes. |
25 |
class TestScriptSyntax(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.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
35 |
script._script_to_commands('cd trunk')) |
36 |
||
|
4665.5.2
by Vincent Ladeuil
Handle simple, double and back quotes. |
37 |
def test_command_with_single_quoted_param(self): |
38 |
story = """bzr commit -m 'two words'""" |
|
|
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
39 |
self.assertEquals([(['bzr', 'commit', '-m', 'two words'], |
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): |
|
44 |
story = """bzr commit -m "two words" """ |
|
|
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
45 |
self.assertEquals([(['bzr', 'commit', '-m', 'two words'], |
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.7
by Vincent Ladeuil
Simplify output/errors handling. |
50 |
self.assertEquals([(['cat', '>file'], 'content\n', None, None)], |
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
51 |
script._script_to_commands('cat >file\n<content\n')) |
52 |
||
53 |
def test_command_with_output(self): |
|
54 |
story = """ |
|
55 |
bzr add
|
|
56 |
>adding file
|
|
|
4665.5.7
by Vincent Ladeuil
Simplify output/errors handling. |
57 |
>adding file2
|
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
58 |
"""
|
|
4665.5.7
by Vincent Ladeuil
Simplify output/errors handling. |
59 |
self.assertEquals([(['bzr', 'add'], None, |
60 |
'adding file\nadding file2\n', None)], |
|
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
61 |
script._script_to_commands(story)) |
62 |
||
|
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
63 |
def test_command_with_error(self): |
64 |
story = """ |
|
65 |
bzr branch foo
|
|
66 |
2>bzr: ERROR: Not a branch: "foo"
|
|
67 |
"""
|
|
68 |
self.assertEquals([(['bzr', 'branch', 'foo'], |
|
|
4665.5.7
by Vincent Ladeuil
Simplify output/errors handling. |
69 |
None, None, 'bzr: ERROR: Not a branch: "foo"\n')], |
|
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
70 |
script._script_to_commands(story)) |
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
71 |
def test_input_without_command(self): |
72 |
self.assertRaises(SyntaxError, script._script_to_commands, '<input') |
|
73 |
||
74 |
def test_output_without_command(self): |
|
75 |
self.assertRaises(SyntaxError, script._script_to_commands, '>input') |
|
76 |
||
|
4665.5.2
by Vincent Ladeuil
Handle simple, double and back quotes. |
77 |
def test_command_with_backquotes(self): |
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
78 |
story = """ |
79 |
foo = `bzr file-id toto`
|
|
80 |
"""
|
|
|
4665.5.3
by Vincent Ladeuil
Separate error from normal output. |
81 |
self.assertEquals([(['foo', '=', '`bzr file-id toto`'], |
82 |
None, None, None)], |
|
|
4665.5.1
by Vincent Ladeuil
Start some shell-like capability to write tests. |
83 |
script._script_to_commands(story)) |
84 |
||
85 |
||
|
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
86 |
class TestScriptExecution(script.TestCaseWithTransportAndScript): |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
87 |
|
88 |
def test_unknown_command(self): |
|
89 |
self.assertRaises(SyntaxError, self.run_script, 'foo') |
|
90 |
||
|
4665.5.13
by Vincent Ladeuil
Script execution must stop on unexpected errors. |
91 |
def test_stops_on_unexpected_output(self): |
|
4665.5.6
by Vincent Ladeuil
Implement 'bzr' command. |
92 |
story = """ |
93 |
mkdir dir
|
|
94 |
cd dir
|
|
95 |
>Hello, I have just cd into dir !
|
|
96 |
"""
|
|
97 |
self.assertRaises(AssertionError, self.run_script, story) |
|
98 |
||
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
99 |
|
|
4665.5.13
by Vincent Ladeuil
Script execution must stop on unexpected errors. |
100 |
def test_stops_on_unexpected_error(self): |
101 |
story = """ |
|
102 |
cat
|
|
103 |
<Hello
|
|
104 |
bzr not-a-command
|
|
105 |
"""
|
|
106 |
self.assertRaises(AssertionError, self.run_script, story) |
|
107 |
||
108 |
def test_continue_on_expected_error(self): |
|
109 |
story = """ |
|
110 |
bzr not-a-command
|
|
111 |
2>..."not-a-command"
|
|
112 |
"""
|
|
113 |
self.run_script(story) |
|
114 |
||
|
4665.5.12
by Vincent Ladeuil
Support '...' in expected strings. |
115 |
def test_ellipsis_output(self): |
116 |
story = """ |
|
117 |
cat
|
|
118 |
<first line
|
|
119 |
<second line
|
|
120 |
<last line
|
|
121 |
>first line
|
|
122 |
>...
|
|
123 |
>last line
|
|
124 |
"""
|
|
125 |
self.run_script(story) |
|
126 |
story = """ |
|
127 |
bzr not-a-command
|
|
128 |
2>..."not-a-command"
|
|
129 |
"""
|
|
130 |
self.run_script(story) |
|
131 |
||
132 |
story = """ |
|
133 |
bzr branch not-a-branch
|
|
134 |
2>bzr: ERROR: Not a branch...not-a-branch/".
|
|
135 |
"""
|
|
136 |
self.run_script(story) |
|
137 |
||
138 |
||
|
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
139 |
class TestCat(script.TestCaseWithTransportAndScript): |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
140 |
|
141 |
def test_cat_usage(self): |
|
142 |
self.assertRaises(SyntaxError, self.run_script, 'cat foo bar baz') |
|
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
143 |
self.assertRaises(SyntaxError, self.run_script, 'cat foo <bar') |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
144 |
|
145 |
def test_cat_input_to_output(self): |
|
|
4665.5.7
by Vincent Ladeuil
Simplify output/errors handling. |
146 |
out, err = self.run_command(['cat'], 'content\n', 'content\n', None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
147 |
self.assertEquals('content\n', out) |
148 |
self.assertEquals(None, err) |
|
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
149 |
|
150 |
def test_cat_file_to_output(self): |
|
151 |
self.build_tree_contents([('file', 'content\n')]) |
|
|
4665.5.7
by Vincent Ladeuil
Simplify output/errors handling. |
152 |
out, err = self.run_command(['cat', 'file'], None, 'content\n', None) |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
153 |
self.assertEquals('content\n', out) |
154 |
self.assertEquals(None, err) |
|
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
155 |
|
156 |
def test_cat_input_to_file(self): |
|
|
4665.5.7
by Vincent Ladeuil
Simplify output/errors handling. |
157 |
out, err = self.run_command(['cat', '>file'], 'content\n', None, None) |
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
158 |
self.assertFileEqual('content\n', 'file') |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
159 |
self.assertEquals(None, out) |
160 |
self.assertEquals(None, err) |
|
161 |
out, err = self.run_command(['cat', '>>file'], 'more\n', None, None) |
|
162 |
self.assertFileEqual('content\nmore\n', 'file') |
|
163 |
self.assertEquals(None, out) |
|
164 |
self.assertEquals(None, err) |
|
|
4665.5.4
by Vincent Ladeuil
Implement a 'cat' command. |
165 |
|
166 |
def test_cat_file_to_file(self): |
|
167 |
self.build_tree_contents([('file', 'content\n')]) |
|
168 |
out, err = self.run_command(['cat', 'file', '>file2'], None, None, None) |
|
169 |
self.assertFileEqual('content\n', 'file2') |
|
|
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
170 |
|
171 |
||
|
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
172 |
class TestMkdir(script.TestCaseWithTransportAndScript): |
|
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
173 |
|
174 |
def test_mkdir_usage(self): |
|
175 |
self.assertRaises(SyntaxError, self.run_script, 'mkdir') |
|
176 |
self.assertRaises(SyntaxError, self.run_script, 'mkdir foo bar') |
|
177 |
||
178 |
def test_mkdir_jailed(self): |
|
179 |
self.assertRaises(ValueError, self.run_script, 'mkdir /out-of-jail') |
|
180 |
self.assertRaises(ValueError, self.run_script, 'mkdir ../out-of-jail') |
|
181 |
||
182 |
def test_mkdir_in_jail(self): |
|
183 |
self.run_script(""" |
|
184 |
mkdir dir
|
|
185 |
cd dir
|
|
186 |
mkdir ../dir2
|
|
187 |
cd ..
|
|
188 |
""") |
|
189 |
self.failUnlessExists('dir') |
|
190 |
self.failUnlessExists('dir2') |
|
191 |
||
192 |
||
|
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
193 |
class TestCd(script.TestCaseWithTransportAndScript): |
|
4665.5.5
by Vincent Ladeuil
Implement 'cd' and 'mkdir'. |
194 |
|
195 |
def test_cd_usage(self): |
|
196 |
self.assertRaises(SyntaxError, self.run_script, 'cd foo bar') |
|
197 |
||
198 |
def test_cd_out_of_jail(self): |
|
199 |
self.assertRaises(ValueError, self.run_script, 'cd /out-of-jail') |
|
200 |
self.assertRaises(ValueError, self.run_script, 'cd ..') |
|
201 |
||
202 |
def test_cd_dir_and_back_home(self): |
|
203 |
self.assertEquals(self.test_dir, osutils.getcwd()) |
|
204 |
self.run_script(""" |
|
205 |
mkdir dir
|
|
206 |
cd dir
|
|
207 |
""") |
|
208 |
self.assertEquals(osutils.pathjoin(self.test_dir, 'dir'), |
|
209 |
osutils.getcwd()) |
|
210 |
||
211 |
self.run_script('cd') |
|
212 |
self.assertEquals(self.test_dir, osutils.getcwd()) |
|
|
4665.5.6
by Vincent Ladeuil
Implement 'bzr' command. |
213 |
|
214 |
||
|
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
215 |
class TestBzr(script.TestCaseWithTransportAndScript): |
|
4665.5.6
by Vincent Ladeuil
Implement 'bzr' command. |
216 |
|
217 |
def test_bzr_smoke(self): |
|
218 |
self.run_script('bzr init branch') |
|
219 |
self.failUnlessExists('branch') |
|
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
220 |
|
221 |
||
|
4665.5.11
by Vincent Ladeuil
Create a new test case based on TestCaseWithMemoryTransport. |
222 |
class TestEcho(script.TestCaseWithMemoryTransportAndScript): |
|
4665.5.8
by Vincent Ladeuil
Implement 'echo' command. |
223 |
|
224 |
def test_echo_usage(self): |
|
225 |
story = """ |
|
226 |
echo foo
|
|
227 |
<bar
|
|
228 |
"""
|
|
229 |
self.assertRaises(SyntaxError, self.run_script, story) |
|
230 |
||
231 |
def test_echo_to_output(self): |
|
232 |
out, err = self.run_command(['echo'], None, '\n', None) |
|
233 |
self.assertEquals('\n', out) |
|
234 |
self.assertEquals(None, err) |
|
235 |
||
236 |
def test_echo_some_to_output(self): |
|
237 |
out, err = self.run_command(['echo', 'hello'], None, 'hello\n', None) |
|
238 |
self.assertEquals('hello\n', out) |
|
239 |
self.assertEquals(None, err) |
|
240 |
||
241 |
def test_echo_more_output(self): |
|
242 |
out, err = self.run_command(['echo', 'hello', 'happy', 'world'], |
|
243 |
None, 'hellohappyworld\n', None) |
|
244 |
self.assertEquals('hellohappyworld\n', out) |
|
245 |
self.assertEquals(None, err) |
|
246 |
||
247 |
def test_echo_appended(self): |
|
248 |
out, err = self.run_command(['echo', 'hello', '>file'], |
|
249 |
None, None, None) |
|
250 |
self.assertEquals(None, out) |
|
251 |
self.assertEquals(None, err) |
|
252 |
self.assertFileEqual('hello\n', 'file') |
|
253 |
out, err = self.run_command(['echo', 'happy', '>>file'], |
|
254 |
None, None, None) |
|
255 |
self.assertEquals(None, out) |
|
256 |
self.assertEquals(None, err) |
|
257 |
self.assertFileEqual('hello\nhappy\n', 'file') |