14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
from cStringIO import StringIO
20
from bzrlib import tests
21
24
"""Split a command line respecting quotes."""
97
100
if cmd_cur is not None:
98
101
commands.append((cmd_cur, input, output, error))
105
class TestCaseWithScript(tests.TestCaseWithTransport):
108
super(TestCaseWithScript, self).setUp()
111
def run_script(self, text):
112
for cmd, input, output, error in _script_to_commands(text):
113
self.run_command(cmd, input, output, error)
115
def run_command(self, cmd, input, output, error):
116
mname = 'do_' + cmd[0]
117
method = getattr(self, mname, None)
119
raise SyntaxError('Command not found "%s"' % (cmd[0],),
120
None, 1, ' '.join(cmd))
124
str_input = ''.join(input)
125
actual_output, actual_error = method(str_input, cmd[1:])
128
self.assertEquals(''.join(output), actual_output)
131
self.assertEquals(''.join(error), actual_error)
132
return actual_output, actual_error
134
def do_cat(self, input, args):
144
if in_name.startswith('>'):
145
out_name = in_name[1:]
151
in_name, out_name = args[0], args[1][1:]
152
syntax_ok = args[1].startswith('>')
154
raise SyntaxError('Usage: cat [file1] [>file2]')
155
if in_name is not None:
156
infile = open(in_name, 'rb')
158
input = infile.read()
161
out = StringIO(input)
162
output = out.getvalue()
163
if out_name is not None:
164
outfile = open(out_name, 'wb')
166
outfile.write(output)