139
143
:param args: The command line arguments
141
:return: A tuple containing:
145
:return: A tuple containing:
142
146
- The file name redirected from or None
143
147
- The file name redirected to or None
144
148
- The mode to open the output file or None
163
167
in_name = redirected_file_name('<', arg[1:], args)
164
168
elif arg.startswith('>>'):
165
169
out_name = redirected_file_name('>>', arg[2:], args)
167
171
elif arg.startswith('>',):
168
172
out_name = redirected_file_name('>', arg[1:], args)
171
175
remaining.append(arg)
172
176
return in_name, out_name, out_mode, remaining
233
237
self._check_output(error, actual_error, test_case)
234
238
except AssertionError as e:
235
raise AssertionError(str(e) +
236
" in stderr of running command %s" % cmd)
239
raise AssertionError(str(e)
240
+ " in stderr of running command %s" % cmd)
237
241
if retcode and not error and actual_error:
238
242
test_case.fail('In \n\t%s\nUnexpected error: %s'
239
243
% (' '.join(cmd), actual_error))
249
253
test_case.fail('expected output: %r, but found nothing'
252
256
null_output_matches_anything = getattr(
253
257
self, 'null_output_matches_anything', False)
280
284
# Strip the simple and double quotes since we don't care about
281
285
# them. We leave the backquotes in place though since they have a
282
286
# different semantic.
283
if arg[0] in ('"', "'") and arg[0] == arg[-1]:
287
if arg[0] in ('"', "'") and arg[0] == arg[-1]:
286
290
if glob.has_magic(arg):
297
301
def _read_input(self, input, in_name):
298
302
if in_name is not None:
299
infile = open(in_name, 'rb')
303
infile = open(in_name, 'r')
301
305
# Command redirection takes precedence over provided input
302
306
input = infile.read()
317
321
def do_brz(self, test_case, input, args):
318
retcode, out, err = test_case._run_bzr_core(
319
args, retcode=None, encoding=None, stdin=input, working_dir=None)
320
return retcode, out, err
322
encoding = osutils.get_user_encoding()
323
stdout = ui_testing.StringIOWithEncoding()
324
stderr = ui_testing.StringIOWithEncoding()
325
stdout.encoding = stderr.encoding = encoding
326
handler = logging.StreamHandler(stderr)
327
handler.setLevel(logging.INFO)
329
logger = logging.getLogger('')
330
logger.addHandler(handler)
332
retcode = test_case._run_bzr_core(
333
args, encoding=encoding, stdin=input, stdout=stdout,
334
stderr=stderr, working_dir=None)
336
logger.removeHandler(handler)
338
return retcode, stdout.getvalue(), stderr.getvalue()
322
340
def do_cat(self, test_case, input, args):
323
341
(in_name, out_name, out_mode, args) = _scan_redirection_options(args)
406
424
def error(msg, path):
407
return "rm: cannot remove '%s': %s\n" % (path, msg)
425
return "rm: cannot remove '%s': %s\n" % (path, msg)
409
427
force, recursive = False, False
447
465
def do_mv(self, test_case, input, args):
449
468
def error(msg, src, dst):
450
469
return "mv: cannot move %s to %s: %s\n" % (src, dst, msg)
487
505
self.overrideEnv('INSIDE_EMACS', '1')
489
507
def run_script(self, script, null_output_matches_anything=False):
490
return self.script_runner.run_script(self, script,
491
null_output_matches_anything=null_output_matches_anything)
508
return self.script_runner.run_script(self, script,
509
null_output_matches_anything=null_output_matches_anything)
493
511
def run_command(self, cmd, input, output, error):
494
512
return self.script_runner.run_command(self, cmd, input, output, error)
523
541
def run_script(self, script, null_output_matches_anything=False):
524
542
return self.script_runner.run_script(self, script,
525
null_output_matches_anything=null_output_matches_anything)
543
null_output_matches_anything=null_output_matches_anything)
527
545
def run_command(self, cmd, input, output, error):
528
546
return self.script_runner.run_command(self, cmd, input, output, error)
531
549
def run_script(test_case, script_string, null_output_matches_anything=False):
532
550
"""Run the given script within a testcase"""
533
551
return ScriptRunner().run_script(test_case, script_string,
534
null_output_matches_anything=null_output_matches_anything)
552
null_output_matches_anything=null_output_matches_anything)