~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/script.py

  • Committer: Matthäus G. Chajdas
  • Date: 2010-10-12 01:18:01 UTC
  • mto: (5484.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 5485.
  • Revision ID: dev@anteru.net-20101012011801-thahmhfxdzz0j6d4
Remove spaces.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 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
24
24
import glob
25
25
import os
26
26
import shlex
 
27
import textwrap
27
28
from cStringIO import StringIO
28
29
 
29
30
from bzrlib import (
55
56
    Input lines start with '<'.
56
57
    Output lines start with nothing.
57
58
    Error lines start with '2>'.
 
59
 
 
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.
58
63
    """
59
64
 
60
65
    commands = []
73
78
    cmd_line = 1
74
79
    lineno = 0
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] == '':
 
86
        del lines[0]
 
87
    if lines and lines[-1] == '':
 
88
        del lines[-1]
 
89
    for line in lines:
77
90
        lineno += 1
78
91
        # Keep a copy for error reporting
79
92
        orig = line
80
93
        comment =  line.find('#')
81
94
        if comment >= 0:
82
95
            # Delete comments
 
96
            # NB: this syntax means comments are allowed inside output, which
 
97
            # may be confusing...
83
98
            line = line[0:comment]
84
99
            line = line.rstrip()
85
 
        if line == '':
86
 
            # Ignore empty lines
87
 
            continue
 
100
            if line == '':
 
101
                continue
88
102
        if line.startswith('$'):
89
103
            # Time to output the current command
90
104
            add_command(cmd_cur, input, output, error)
230
244
            # 'expected' parameter. So we just fallback to our good old
231
245
            # assertEqualDiff since we know there *are* differences and the
232
246
            # output should be decently readable.
233
 
            test_case.assertEqualDiff(expected, actual)
 
247
            #
 
248
            # As a special case, we allow output that's missing a final
 
249
            # newline to match an expected string that does have one, so that
 
250
            # we can match a prompt printed on one line, then input given on
 
251
            # the next line.
 
252
            if expected == actual + '\n':
 
253
                pass
 
254
            else:
 
255
                test_case.assertEqualDiff(expected, actual)
234
256
 
235
257
    def _pre_process_args(self, args):
236
258
        new_args = []
475
497
    def run_command(self, cmd, input, output, error):
476
498
        return self.script_runner.run_command(self, cmd, input, output, error)
477
499
 
 
500
 
 
501
def run_script(test_case, script_string):
 
502
    """Run the given script within a testcase"""
 
503
    return ScriptRunner().run_script(test_case, script_string)