55
56
Input lines start with '<'.
56
57
Output lines start with nothing.
57
58
Error lines start with '2>'.
60
:return: A sequence of ([args], input, output, errors), where the args are
61
split in to words, and the input, output, and errors are just strings,
62
typically containing newlines.
75
80
input, output, error = None, None, None
76
for line in text.split('\n'):
81
text = textwrap.dedent(text)
82
lines = text.split('\n')
83
# to make use of triple-quoted strings easier, we ignore a blank line
84
# right at the start and right at the end; the rest are meaningful
85
if lines and lines[0] == '':
87
if lines and lines[-1] == '':
78
91
# Keep a copy for error reporting
80
93
comment = line.find('#')
96
# NB: this syntax means comments are allowed inside output, which
83
98
line = line[0:comment]
84
99
line = line.rstrip()
88
102
if line.startswith('$'):
89
103
# Time to output the current command
90
104
add_command(cmd_cur, input, output, error)
207
221
retcode, actual_output, actual_error = method(test_case,
210
self._check_output(output, actual_output, test_case)
211
self._check_output(error, actual_error, test_case)
225
self._check_output(output, actual_output, test_case)
226
except AssertionError, e:
227
raise AssertionError(str(e) + " in stdout of command %s" % cmd)
229
self._check_output(error, actual_error, test_case)
230
except AssertionError, e:
231
raise AssertionError(str(e) +
232
" in stderr of running command %s" % cmd)
212
233
if retcode and not error and actual_error:
213
234
test_case.fail('In \n\t%s\nUnexpected error: %s'
214
235
% (' '.join(cmd), actual_error))
215
236
return retcode, actual_output, actual_error
217
238
def _check_output(self, expected, actual, test_case):
219
# Specifying None means: any output is accepted
222
test_case.fail('We expected output: %r, but found None'
242
elif expected == '...\n':
245
test_case.fail('expected output: %r, but found nothing'
247
expected = expected or ''
224
248
matching = self.output_checker.check_output(
225
249
expected, actual, self.check_options)
230
254
# 'expected' parameter. So we just fallback to our good old
231
255
# assertEqualDiff since we know there *are* differences and the
232
256
# output should be decently readable.
233
test_case.assertEqualDiff(expected, actual)
258
# As a special case, we allow output that's missing a final
259
# newline to match an expected string that does have one, so that
260
# we can match a prompt printed on one line, then input given on
262
if expected == actual + '\n':
265
test_case.assertEqualDiff(expected, actual)
235
267
def _pre_process_args(self, args):
475
507
def run_command(self, cmd, input, output, error):
476
508
return self.script_runner.run_command(self, cmd, input, output, error)
511
def run_script(test_case, script_string):
512
"""Run the given script within a testcase"""
513
return ScriptRunner().run_script(test_case, script_string)