1
# Copyright (C) 2009, 2010 Canonical Ltd
1
# Copyright (C) 2009 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
108
108
error.append(line[2:] + '\n')
110
# can happen if the first line is not recognized as a command, eg
111
# if the prompt has leading whitespace
112
110
if output is None:
113
111
if cmd_cur is None:
114
raise SyntaxError('No command for line %r' % (line,),
112
raise SyntaxError('No command for that output',
115
113
(file_name, lineno, 1, orig))
117
115
output.append(line + '\n')
219
217
# Specifying None means: any output is accepted
221
219
if actual is None:
222
test_case.fail('We expected output: %r, but found None'
220
test_case.fail('Unexpected: %s' % actual)
224
221
matching = self.output_checker.check_output(
225
222
expected, actual, self.check_options)
293
290
inputs.append(self._read_input(None, in_name))
294
291
except IOError, e:
295
# Some filenames are illegal on Windows and generate EINVAL
296
# rather than just saying the filename doesn't exist
297
if e.errno in (errno.ENOENT, errno.EINVAL):
292
if e.errno == errno.ENOENT:
299
294
'%s: No such file or directory\n' % (in_name,))
301
295
# Basically cat copy input to output
302
296
output = ''.join(inputs)
303
297
# Handle output redirections
305
299
output = self._write_output(output, out_name, out_mode)
306
300
except IOError, e:
307
# If out_name cannot be created, we may get 'ENOENT', however if
308
# out_name is something like '', we can get EINVAL
309
if e.errno in (errno.ENOENT, errno.EINVAL):
301
if e.errno == errno.ENOENT:
310
302
return 1, None, '%s: No such file or directory\n' % (out_name,)
312
303
return 0, output, None
314
305
def do_echo(self, test_case, input, args):
315
306
(in_name, out_name, out_mode, args) = _scan_redirection_options(args)
317
raise SyntaxError('echo doesn\'t read from stdin')
308
raise SyntaxError('Specify parameters OR use redirection')
319
310
input = ' '.join(args)
312
input = self._read_input(input, in_name)
314
if e.errno == errno.ENOENT:
315
return 1, None, '%s: No such file or directory\n' % (in_name,)
320
316
# Always append a \n'
326
322
output = self._write_output(output, out_name, out_mode)
327
323
except IOError, e:
328
if e.errno in (errno.ENOENT, errno.EINVAL):
324
if e.errno == errno.ENOENT:
329
325
return 1, None, '%s: No such file or directory\n' % (out_name,)
331
326
return 0, output, None
333
328
def _get_jail_root(self, test_case):
403
398
return retcode, None, err
405
def do_mv(self, test_case, input, args):
407
def error(msg, src, dst):
408
return "mv: cannot move %s to %s: %s\n" % (src, dst, msg)
410
if not args or len(args) != 2:
411
raise SyntaxError("Usage: mv path1 path2")
415
if os.path.isdir(dst):
416
real_dst = os.path.join(dst, os.path.basename(src))
417
os.rename(src, real_dst)
419
if e.errno == errno.ENOENT:
420
err = error('No such file or directory', src, dst)
427
return retcode, None, err
431
401
class TestCaseWithMemoryTransportAndScript(tests.TestCaseWithMemoryTransport):
432
402
"""Helper class to experiment shell-like test and memory fs.