1
# Copyright (C) 2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Front-end command for shell-like test scripts.
19
See doc/developers/testing.txt for more explanations.
20
This module should be importable even if testtools aren't available.
31
class cmd_test_script(commands.Command):
32
"""Run a shell-like test from a file."""
35
takes_args = ['infile']
37
option.Option('null-output',
38
help='Null command outputs match any output.'),
41
@commands.display_command
42
def run(self, infile, null_output=False):
43
# local imports to defer testtools dependency
44
from bzrlib import tests
45
from bzrlib.tests.script import TestCaseWithTransportAndScript
53
class Test(TestCaseWithTransportAndScript):
55
script = None # Set before running
58
self.run_script(script,
59
null_output_matches_anything=null_output)
61
runner = tests.TextTestRunner(stream=self.outf)
62
test = Test('test_it')
63
test.path = os.path.realpath(infile)
64
res = runner.run(test)
65
return len(res.errors) + len(res.failures)