1
# Copyright (C) 2009 Canonical Ltd
1
# Copyright (C) 2009, 2010 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
110
112
if output is None:
111
113
if cmd_cur is None:
112
raise SyntaxError('No command for that output',
114
raise SyntaxError('No command for line %r' % (line,),
113
115
(file_name, lineno, 1, orig))
115
117
output.append(line + '\n')
217
219
# Specifying None means: any output is accepted
219
221
if actual is None:
220
test_case.fail('Unexpected: %s' % actual)
222
test_case.fail('We expected output: %r, but found None'
221
224
matching = self.output_checker.check_output(
222
225
expected, actual, self.check_options)
290
293
inputs.append(self._read_input(None, in_name))
291
294
except IOError, e:
292
if e.errno == errno.ENOENT:
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):
294
299
'%s: No such file or directory\n' % (in_name,))
295
301
# Basically cat copy input to output
296
302
output = ''.join(inputs)
297
303
# Handle output redirections
299
305
output = self._write_output(output, out_name, out_mode)
300
306
except IOError, e:
301
if e.errno == errno.ENOENT:
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):
302
310
return 1, None, '%s: No such file or directory\n' % (out_name,)
303
312
return 0, output, None
305
314
def do_echo(self, test_case, input, args):
306
315
(in_name, out_name, out_mode, args) = _scan_redirection_options(args)
308
raise SyntaxError('Specify parameters OR use redirection')
317
raise SyntaxError('echo doesn\'t read from stdin')
310
319
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,)
316
320
# Always append a \n'
322
326
output = self._write_output(output, out_name, out_mode)
323
327
except IOError, e:
324
if e.errno == errno.ENOENT:
328
if e.errno in (errno.ENOENT, errno.EINVAL):
325
329
return 1, None, '%s: No such file or directory\n' % (out_name,)
326
331
return 0, output, None
328
333
def _get_jail_root(self, test_case):
398
403
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
401
431
class TestCaseWithMemoryTransportAndScript(tests.TestCaseWithMemoryTransport):
402
432
"""Helper class to experiment shell-like test and memory fs.