/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/script.py

Merge shell-like-tests into description

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
If an error occurs and no expected error is specified, the execution stops.
40
40
 
 
41
An error is defined by a returned status different from zero, not by the
 
42
presence of text on the error stream.
 
43
 
41
44
The matching is done on a full string comparison basis unless '...' is used, in
42
45
which case expected output/errors can be lees precise.
43
46
 
232
235
 
233
236
    def run_script(self, text):
234
237
        for cmd, input, output, error in _script_to_commands(text):
235
 
            out, err = self.run_command(cmd, input, output, error)
 
238
            self.run_command(cmd, input, output, error)
236
239
 
237
240
    def _check_output(self, expected, actual):
238
241
        if expected is None:
244
247
            expected, actual, self.check_options)
245
248
        if not matching:
246
249
            # Note that we can't use output_checker.output_difference() here
247
 
            # because... the API is boken (expected must be a doctest specific
248
 
            # object of whicha 'want' attribute will be our 'expected'
249
 
            # parameter. So we just fallbacl to our good old assertEqualDiff
250
 
            # since we know there are differences and the output should be
251
 
            # decently readable.
 
250
            # because... the API is broken ('expected' must be a doctest
 
251
            # specific object of which a 'want' attribute will be our
 
252
            # 'expected' parameter. So we just fallback to our good old
 
253
            # assertEqualDiff since we know there *are* differences and the
 
254
            # output should be decently readable.
252
255
            self.test_case.assertEqualDiff(expected, actual)
253
256
 
254
257
    def run_command(self, cmd, input, output, error):
261
264
            str_input = ''
262
265
        else:
263
266
            str_input = ''.join(input)
264
 
        actual_output, actual_error = method(str_input, cmd[1:])
 
267
        retcode, actual_output, actual_error = method(str_input, cmd[1:])
265
268
 
266
269
        self._check_output(output, actual_output)
267
270
        self._check_output(error, actual_error)
268
 
        if not error and actual_error:
 
271
        if retcode and not error and actual_error:
269
272
            self.test_case.fail('Unexpected error: %s' % actual_error)
270
 
        return actual_output, actual_error
 
273
        return retcode, actual_output, actual_error
271
274
 
272
275
    def _read_input(self, input, in_name):
273
276
        if in_name is not None:
290
293
        return output
291
294
 
292
295
    def do_bzr(self, input, args):
293
 
        out, err = self.test_case._run_bzr_core(
 
296
        retcode, out, err = self.test_case._run_bzr_core(
294
297
            args, retcode=None, encoding=None, stdin=input, working_dir=None)
295
 
        return out, err
 
298
        return retcode, out, err
296
299
 
297
300
    def do_cat(self, input, args):
298
301
        (in_name, out_name, out_mode, args) = _scan_redirection_options(args)
307
310
        output = input
308
311
        # Handle output redirections
309
312
        output = self._write_output(output, out_name, out_mode)
310
 
        return output, None
 
313
        return 0, output, None
311
314
 
312
315
    def do_echo(self, input, args):
313
316
        (in_name, out_name, out_mode, args) = _scan_redirection_options(args)
322
325
        output = input
323
326
        # Handle output redirections
324
327
        output = self._write_output(output, out_name, out_mode)
325
 
        return output, None
 
328
        return 0, output, None
326
329
 
327
330
    def _ensure_in_jail(self, path):
328
331
        jail_root = self.test_case.get_jail_root()
338
341
        else:
339
342
            d = self.test_case.get_jail_root()
340
343
        os.chdir(d)
341
 
        return None, None
 
344
        return 0, None, None
342
345
 
343
346
    def do_mkdir(self, input, args):
344
347
        if not args or len(args) != 1:
346
349
        d = args[0]
347
350
        self._ensure_in_jail(d)
348
351
        os.mkdir(d)
349
 
        return None, None
 
352
        return 0, None, None
350
353
 
351
354
 
352
355
class TestCaseWithMemoryTransportAndScript(tests.TestCaseWithMemoryTransport):