68
68
self.assertEquals([(['bzr', 'branch', 'foo'],
69
69
None, None, 'bzr: ERROR: Not a branch: "foo"\n')],
70
70
script._script_to_commands(story))
71
72
def test_input_without_command(self):
72
73
self.assertRaises(SyntaxError, script._script_to_commands, '<input')
143
144
self.assertRaises(SyntaxError, self.run_script, 'cat foo <bar')
145
146
def test_cat_input_to_output(self):
146
out, err = self.run_command(['cat'], 'content\n', 'content\n', None)
147
retcode, out, err = self.run_command(['cat'],
148
'content\n', 'content\n', None)
147
149
self.assertEquals('content\n', out)
148
150
self.assertEquals(None, err)
150
152
def test_cat_file_to_output(self):
151
153
self.build_tree_contents([('file', 'content\n')])
152
out, err = self.run_command(['cat', 'file'], None, 'content\n', None)
154
retcode, out, err = self.run_command(['cat', 'file'],
155
None, 'content\n', None)
153
156
self.assertEquals('content\n', out)
154
157
self.assertEquals(None, err)
156
159
def test_cat_input_to_file(self):
157
out, err = self.run_command(['cat', '>file'], 'content\n', None, None)
160
retcode, out, err = self.run_command(['cat', '>file'],
161
'content\n', None, None)
158
162
self.assertFileEqual('content\n', 'file')
159
163
self.assertEquals(None, out)
160
164
self.assertEquals(None, err)
161
out, err = self.run_command(['cat', '>>file'], 'more\n', None, None)
165
retcode, out, err = self.run_command(['cat', '>>file'],
166
'more\n', None, None)
162
167
self.assertFileEqual('content\nmore\n', 'file')
163
168
self.assertEquals(None, out)
164
169
self.assertEquals(None, err)
166
171
def test_cat_file_to_file(self):
167
172
self.build_tree_contents([('file', 'content\n')])
168
out, err = self.run_command(['cat', 'file', '>file2'], None, None, None)
173
retcode, out, err = self.run_command(['cat', 'file', '>file2'],
169
175
self.assertFileEqual('content\n', 'file2')
229
235
self.assertRaises(SyntaxError, self.run_script, story)
231
237
def test_echo_to_output(self):
232
out, err = self.run_command(['echo'], None, '\n', None)
238
retcode, out, err = self.run_command(['echo'], None, '\n', None)
233
239
self.assertEquals('\n', out)
234
240
self.assertEquals(None, err)
236
242
def test_echo_some_to_output(self):
237
out, err = self.run_command(['echo', 'hello'], None, 'hello\n', None)
243
retcode, out, err = self.run_command(['echo', 'hello'],
244
None, 'hello\n', None)
238
245
self.assertEquals('hello\n', out)
239
246
self.assertEquals(None, err)
241
248
def test_echo_more_output(self):
242
out, err = self.run_command(['echo', 'hello', 'happy', 'world'],
243
None, 'hellohappyworld\n', None)
249
retcode, out, err = self.run_command(
250
['echo', 'hello', 'happy', 'world'],
251
None, 'hellohappyworld\n', None)
244
252
self.assertEquals('hellohappyworld\n', out)
245
253
self.assertEquals(None, err)
247
255
def test_echo_appended(self):
248
out, err = self.run_command(['echo', 'hello', '>file'],
256
retcode, out, err = self.run_command(['echo', 'hello', '>file'],
250
258
self.assertEquals(None, out)
251
259
self.assertEquals(None, err)
252
260
self.assertFileEqual('hello\n', 'file')
253
out, err = self.run_command(['echo', 'happy', '>>file'],
261
retcode, out, err = self.run_command(['echo', 'happy', '>>file'],
255
263
self.assertEquals(None, out)
256
264
self.assertEquals(None, err)
257
265
self.assertFileEqual('hello\nhappy\n', 'file')