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