Rev 5532: (vila) Add an option to accept any output from commands in shell-like tests. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Nov 8 11:35:51 GMT 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5532 [merge]
revision-id: pqm at pqm.ubuntu.com-20101108113549-e4mhhq2fe1i0etbf
parent: pqm at pqm.ubuntu.com-20101107141444-r9agveqsbq5mka5u
parent: v.ladeuil+lp at free.fr-20101108105353-nntejqprr3nislcw
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2010-11-08 11:35:49 +0000
message:
(vila) Add an option to accept any output from commands in shell-like tests.
(Vincent Ladeuil)
modified:
bzrlib/cmd_test_script.py cmd_test_script.py-20101020120519-7hst41avona524nn-1
bzrlib/tests/blackbox/test_script.py test_script.py-20101013135628-rw9f11dgkgx09fnq-1
bzrlib/tests/script.py script.py-20090901081155-yk3tiy1nunxg16ne-1
bzrlib/tests/test_script.py test_script.py-20090901081156-y90z4w2t62fv7e7b-1
doc/developers/testing.txt testing.txt-20080812140359-i70zzh6v2z7grqex-1
doc/en/release-notes/bzr-2.3.txt NEWS-20050323055033-4e00b5db738777ff
=== modified file 'bzrlib/cmd_test_script.py'
--- a/bzrlib/cmd_test_script.py 2010-11-05 20:54:32 +0000
+++ b/bzrlib/cmd_test_script.py 2010-11-08 10:53:53 +0000
@@ -16,13 +16,16 @@
"""Front-end command for shell-like test scripts.
-See developers/testing.html for more explanations.
+See doc/developers/testing.txt for more explanations.
This module should be importable even if testtools aren't available.
"""
import os
-from bzrlib import commands
+from bzrlib import (
+ commands,
+ option,
+ )
class cmd_test_script(commands.Command):
@@ -30,9 +33,13 @@
hidden = True
takes_args = ['infile']
+ takes_options = [
+ option.Option('null-output',
+ help='Null command outputs match any output.'),
+ ]
@commands.display_command
- def run(self, infile):
+ def run(self, infile, null_output=False):
# local imports to defer testtools dependency
from bzrlib import tests
from bzrlib.tests.script import TestCaseWithTransportAndScript
@@ -48,7 +55,8 @@
script = None # Set before running
def test_it(self):
- self.run_script(script)
+ self.run_script(script,
+ null_output_matches_anything=null_output)
runner = tests.TextTestRunner(stream=self.outf)
test = Test('test_it')
=== modified file 'bzrlib/tests/blackbox/test_script.py'
--- a/bzrlib/tests/blackbox/test_script.py 2010-10-13 13:57:22 +0000
+++ b/bzrlib/tests/blackbox/test_script.py 2010-11-08 10:53:53 +0000
@@ -50,6 +50,16 @@
self.assertEquals('OK', out_lines[-1])
self.assertEquals('', err)
+ def test_null_output(self):
+ self.build_tree_contents([('script', '''
+$ echo hello world
+''')])
+ out, err = self.run_bzr(['test-script', 'script', '--null-output'])
+ out_lines = out.splitlines()
+ self.assertStartsWith(out_lines[-3], 'Ran 1 test in ')
+ self.assertEquals('OK', out_lines[-1])
+ self.assertEquals('', err)
+
def test_failing_script(self):
self.build_tree_contents([('script', '''
$ echo hello foo
=== modified file 'bzrlib/tests/script.py'
--- a/bzrlib/tests/script.py 2010-10-28 00:06:59 +0000
+++ b/bzrlib/tests/script.py 2010-11-08 09:58:04 +0000
@@ -196,7 +196,7 @@
self.output_checker = doctest.OutputChecker()
self.check_options = doctest.ELLIPSIS
- def run_script(self, test_case, text):
+ def run_script(self, test_case, text, null_output_matches_anything=False):
"""Run a shell-like script as a test.
:param test_case: A TestCase instance that should provide the fail(),
@@ -204,7 +204,12 @@
attribute used as a jail root.
:param text: A shell-like script (see _script_to_commands for syntax).
+
+ :param null_output_matches_anything: For commands with no specified
+ output, ignore any output that does happen, including output on
+ standard error.
"""
+ self.null_output_matches_anything = null_output_matches_anything
for cmd, input, output, error in _script_to_commands(text):
self.run_command(test_case, cmd, input, output, error)
@@ -245,6 +250,12 @@
else:
test_case.fail('expected output: %r, but found nothing'
% (expected,))
+
+ null_output_matches_anything = getattr(
+ self, 'null_output_matches_anything', False)
+ if null_output_matches_anything and expected is None:
+ return
+
expected = expected or ''
matching = self.output_checker.check_output(
expected, actual, self.check_options)
@@ -473,8 +484,9 @@
super(TestCaseWithMemoryTransportAndScript, self).setUp()
self.script_runner = ScriptRunner()
- def run_script(self, script):
- return self.script_runner.run_script(self, script)
+ def run_script(self, script, null_output_matches_anything=False):
+ return self.script_runner.run_script(self, script,
+ null_output_matches_anything=null_output_matches_anything)
def run_command(self, cmd, input, output, error):
return self.script_runner.run_command(self, cmd, input, output, error)
@@ -502,14 +514,16 @@
super(TestCaseWithTransportAndScript, self).setUp()
self.script_runner = ScriptRunner()
- def run_script(self, script):
- return self.script_runner.run_script(self, script)
+ def run_script(self, script, null_output_matches_anything=False):
+ return self.script_runner.run_script(self, script,
+ null_output_matches_anything=null_output_matches_anything)
def run_command(self, cmd, input, output, error):
return self.script_runner.run_command(self, cmd, input, output, error)
-def run_script(test_case, script_string):
+def run_script(test_case, script_string, null_output_matches_anything=False):
"""Run the given script within a testcase"""
- return ScriptRunner().run_script(test_case, script_string)
+ return ScriptRunner().run_script(test_case, script_string,
+ null_output_matches_anything=null_output_matches_anything)
=== modified file 'bzrlib/tests/test_script.py'
--- a/bzrlib/tests/test_script.py 2010-10-27 23:27:41 +0000
+++ b/bzrlib/tests/test_script.py 2010-11-08 09:58:04 +0000
@@ -186,6 +186,14 @@
$ echo foo
""")
+ def test_null_output_matches_option(self):
+ """If you want null output to be a wild card, you can pass
+ null_output_matches_anything to run_script"""
+ self.run_script(
+ """
+ $ echo foo
+ """, null_output_matches_anything=True)
+
def test_ellipsis_everything(self):
"""A simple ellipsis matches everything."""
self.run_script("""
=== modified file 'doc/developers/testing.txt'
--- a/doc/developers/testing.txt 2010-11-05 20:54:32 +0000
+++ b/doc/developers/testing.txt 2010-11-08 09:58:04 +0000
@@ -367,8 +367,9 @@
The execution stops as soon as an expected output or an expected error is not
matched.
-When no output is specified, any ouput from the command is accepted
-and execution continue.
+If output occurs and no output is expected, the execution stops and the
+test fails. If unexpected output occurs on the standard error, then
+execution stops and the test fails.
If an error occurs and no expected error is specified, the execution stops.
@@ -447,11 +448,11 @@
def test_unshelve_keep(self):
# some setup here
script.run_script(self, '''
- $ bzr add file
- $ bzr shelve --all -m Foo
+ $ bzr add -q file
+ $ bzr shelve -q --all -m Foo
$ bzr shelve --list
1: Foo
- $ bzr unshelve --keep
+ $ bzr unshelve -q --keep
$ bzr shelve --list
1: Foo
$ cat file
@@ -471,6 +472,19 @@
yes
""")
+To avoid having to specify "-q" for all commands whose output is
+irrelevant, the run_script() method may be passed the keyword argument
+``null_output_matches_anything=True``. For example::
+
+ def test_ignoring_null_output(self):
+ self.run_script("""
+ $ bzr init
+ $ bzr ci -m 'first revision' --unchanged
+ $ bzr log --line
+ 1: ...
+ """, null_output_matches_anything=True)
+
+
Import tariff tests
-------------------
=== modified file 'doc/en/release-notes/bzr-2.3.txt'
--- a/doc/en/release-notes/bzr-2.3.txt 2010-11-07 13:38:56 +0000
+++ b/doc/en/release-notes/bzr-2.3.txt 2010-11-08 09:58:04 +0000
@@ -185,6 +185,11 @@
Instead, use '...' as a wildcard if you don't care about the output.
(Martin Pool, #637830)
+* Add a null_output_matches_anything keyword argument with default False to
+ bzrlib.tests.script.ScriptRunner.run_script to specify that the command
+ output should not be checked (as opposed to expecting an empty output).
+ (Neil Martinsen-Burrell, #662509)
+
* ``bzr test-script script`` is a new command that runs a shell-like script
from an the ``script`` file. (Vincent Ladeuil)
More information about the bazaar-commits
mailing list