~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/script.py

Rework test_script a little bit.


Don't allow someone to request a stdin request to echo.
Echo never reads from stdin, it just echos its arguments.
You use 'cat' if you want to read from stdin.

A few other fixes because the tests were using filenames
that are actually illegal on Windows, rather than just
nonexistant.


Change the exception handling for commands so that
unknown errors don't get silently squashed and then
turn into hard-to-debug errors later.

test_script now passes on Windows.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009 Canonical Ltd
2
2
#
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
107
107
                error = []
108
108
            error.append(line[2:] + '\n')
109
109
        else:
110
 
            # can happen if the first line is not recognized as a command, eg
111
 
            # if the prompt has leading whitespace
112
110
            if output is None:
113
111
                if cmd_cur is None:
114
 
                    raise SyntaxError('No command for line %r' % (line,),
 
112
                    raise SyntaxError('No command for that output',
115
113
                                      (file_name, lineno, 1, orig))
116
114
                output = []
117
115
            output.append(line + '\n')
402
400
            retcode = 0
403
401
        return retcode, None, err
404
402
 
405
 
    def do_mv(self, test_case, input, args):
406
 
        err = None
407
 
        def error(msg, src, dst):
408
 
            return "mv: cannot move %s to %s: %s\n" % (src, dst, msg)
409
 
 
410
 
        if not args or len(args) != 2:
411
 
            raise SyntaxError("Usage: mv path1 path2")
412
 
        src, dst = args
413
 
        try:
414
 
            real_dst = dst
415
 
            if os.path.isdir(dst):
416
 
                real_dst = os.path.join(dst, os.path.basename(src))
417
 
            os.rename(src, real_dst)
418
 
        except OSError, e:
419
 
            if e.errno == errno.ENOENT:
420
 
                err = error('No such file or directory', src, dst)
421
 
            else:
422
 
                raise
423
 
        if err:
424
 
            retcode = 1
425
 
        else:
426
 
            retcode = 0
427
 
        return retcode, None, err
428
 
 
429
 
 
430
403
 
431
404
class TestCaseWithMemoryTransportAndScript(tests.TestCaseWithMemoryTransport):
432
405
    """Helper class to experiment shell-like test and memory fs.