Rev 5532: Merge nmb fix in file:///home/vila/src/bzr/bugs/662509-ignore-empty/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Nov 8 09:41:30 GMT 2010
At file:///home/vila/src/bzr/bugs/662509-ignore-empty/
------------------------------------------------------------
revno: 5532 [merge]
revision-id: v.ladeuil+lp at free.fr-20101108094130-motjiev9rqw1th8u
parent: pqm at pqm.ubuntu.com-20101107141444-r9agveqsbq5mka5u
parent: nmb at wartburg.edu-20101105030411-z6gactun5yiy5etu
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 662509-ignore-empty
timestamp: Mon 2010-11-08 10:41:30 +0100
message:
Merge nmb fix
modified:
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
-------------- next part --------------
=== 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:41:30 +0000
@@ -196,7 +196,8 @@
self.output_checker = doctest.OutputChecker()
self.check_options = doctest.ELLIPSIS
- def run_script(self, test_case, text):
+ def run_script(self, test_case, text,
+ blank_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 +205,12 @@
attribute used as a jail root.
:param text: A shell-like script (see _script_to_commands for syntax).
+
+ :param blank_output_matches_anything: For commands with no specified
+ output, ignore any output that does happen, including output on
+ standard error.
"""
+ self.blank_output_matches_anything = blank_output_matches_anything
for cmd, input, output, error in _script_to_commands(text):
self.run_command(test_case, cmd, input, output, error)
@@ -245,6 +251,12 @@
else:
test_case.fail('expected output: %r, but found nothing'
% (expected,))
+
+ blank_output_matches_anything = getattr(self,
+ 'blank_output_matches_anything', False)
+ if blank_output_matches_anything and expected is None:
+ return
+
expected = expected or ''
matching = self.output_checker.check_output(
expected, actual, self.check_options)
@@ -473,8 +485,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, blank_output_matches_anything=False):
+ return self.script_runner.run_script(self, script,
+ blank_output_matches_anything=blank_output_matches_anything)
def run_command(self, cmd, input, output, error):
return self.script_runner.run_command(self, cmd, input, output, error)
@@ -502,14 +515,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, blank_output_matches_anything=False):
+ return self.script_runner.run_script(self, script,
+ blank_output_matches_anything=blank_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, blank_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,
+ blank_output_matches_anything=blank_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:41:30 +0000
@@ -186,6 +186,14 @@
$ echo foo
""")
+ def test_blank_output_matches_option(self):
+ """If you want blank output to be a wild card, you can pass
+ blank_output_matches_anything to run_script"""
+ self.run_script(
+ """
+ $ echo foo
+ """, blank_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:41:30 +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
+``blank_output_matches_anything=True``. For example::
+
+ def test_ignoring_blank_output(self):
+ self.run_script("""
+ $ bzr init
+ $ bzr ci -m 'first revision' --unchanged
+ $ bzr log --line
+ 1: ...
+ """, blank_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:41:30 +0000
@@ -185,6 +185,10 @@
Instead, use '...' as a wildcard if you don't care about the output.
(Martin Pool, #637830)
+* Add a blank_output_matches_anything keyword argument with default False to
+ bzrlib.tests.script.ScriptRunner.run_script to specify if missing
+ output does not need to be matched. (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