Rev 5501: (vila) Add a new hidden ``test-script`` command (Vincent Ladeuil) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Oct 15 12:33:35 BST 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5501 [merge]
revision-id: pqm at pqm.ubuntu.com-20101015113333-auzmqh8gqjkzlgg0
parent: pqm at pqm.ubuntu.com-20101015112938-8585tdgvnin38kfv
parent: v.ladeuil+lp at free.fr-20101015113054-a3nd1xnb3ro8c44c
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2010-10-15 12:33:33 +0100
message:
(vila) Add a new hidden ``test-script`` command (Vincent Ladeuil)
added:
bzrlib/tests/blackbox/test_script.py test_script.py-20101013135628-rw9f11dgkgx09fnq-1
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
bzrlib/tests/script.py script.py-20090901081155-yk3tiy1nunxg16ne-1
doc/developers/testing.txt testing.txt-20080812140359-i70zzh6v2z7grqex-1
doc/en/release-notes/bzr-2.3.txt NEWS-20050323055033-4e00b5db738777ff
doc/en/whats-new/whats-new-in-2.3.txt whatsnewin2.3.txt-20100818072501-x2h25r7jbnknvy30-1
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2010-10-13 14:06:32 +0000
+++ b/bzrlib/builtins.py 2010-10-15 11:30:54 +0000
@@ -6076,5 +6076,6 @@
('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
('cmd_conflicts', [], 'bzrlib.conflicts'),
('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
+ ('cmd_test_script', [], 'bzrlib.tests.script'),
]:
builtin_command_registry.register_lazy(name, aliases, module_name)
=== modified file 'bzrlib/tests/blackbox/__init__.py'
--- a/bzrlib/tests/blackbox/__init__.py 2010-09-30 17:15:15 +0000
+++ b/bzrlib/tests/blackbox/__init__.py 2010-10-15 11:30:54 +0000
@@ -35,98 +35,101 @@
# add the tests for this module
suite.addTests(basic_tests)
+ prefix = 'bzrlib.tests.blackbox.'
testmod_names = [
- 'bzrlib.tests.blackbox.test_add',
- 'bzrlib.tests.blackbox.test_added',
- 'bzrlib.tests.blackbox.test_alias',
- 'bzrlib.tests.blackbox.test_aliases',
- 'bzrlib.tests.blackbox.test_ancestry',
- 'bzrlib.tests.blackbox.test_annotate',
- 'bzrlib.tests.blackbox.test_branch',
- 'bzrlib.tests.blackbox.test_break_lock',
- 'bzrlib.tests.blackbox.test_breakin',
- 'bzrlib.tests.blackbox.test_bound_branches',
- 'bzrlib.tests.blackbox.test_bundle_info',
- 'bzrlib.tests.blackbox.test_cat',
- 'bzrlib.tests.blackbox.test_cat_revision',
- 'bzrlib.tests.blackbox.test_check',
- 'bzrlib.tests.blackbox.test_checkout',
- 'bzrlib.tests.blackbox.test_clean_tree',
- 'bzrlib.tests.blackbox.test_command_encoding',
- 'bzrlib.tests.blackbox.test_commit',
- 'bzrlib.tests.blackbox.test_config',
- 'bzrlib.tests.blackbox.test_conflicts',
- 'bzrlib.tests.blackbox.test_debug',
- 'bzrlib.tests.blackbox.test_deleted',
- 'bzrlib.tests.blackbox.test_diff',
- 'bzrlib.tests.blackbox.test_dump_btree',
- 'bzrlib.tests.blackbox.test_dpush',
- 'bzrlib.tests.blackbox.test_exceptions',
- 'bzrlib.tests.blackbox.test_export',
- 'bzrlib.tests.blackbox.test_filesystem_cicp',
- 'bzrlib.tests.blackbox.test_filtered_view_ops',
- 'bzrlib.tests.blackbox.test_find_merge_base',
- 'bzrlib.tests.blackbox.test_help',
- 'bzrlib.tests.blackbox.test_hooks',
- 'bzrlib.tests.blackbox.test_ignore',
- 'bzrlib.tests.blackbox.test_ignored',
- 'bzrlib.tests.blackbox.test_info',
- 'bzrlib.tests.blackbox.test_init',
- 'bzrlib.tests.blackbox.test_inventory',
- 'bzrlib.tests.blackbox.test_join',
- 'bzrlib.tests.blackbox.test_locale',
- 'bzrlib.tests.blackbox.test_log',
- 'bzrlib.tests.blackbox.test_logformats',
- 'bzrlib.tests.blackbox.test_lookup_revision',
- 'bzrlib.tests.blackbox.test_ls',
- 'bzrlib.tests.blackbox.test_lsprof',
- 'bzrlib.tests.blackbox.test_merge',
- 'bzrlib.tests.blackbox.test_merge_directive',
- 'bzrlib.tests.blackbox.test_missing',
- 'bzrlib.tests.blackbox.test_modified',
- 'bzrlib.tests.blackbox.test_mv',
- 'bzrlib.tests.blackbox.test_nick',
- 'bzrlib.tests.blackbox.test_non_ascii',
- 'bzrlib.tests.blackbox.test_outside_wt',
- 'bzrlib.tests.blackbox.test_pack',
- 'bzrlib.tests.blackbox.test_pull',
- 'bzrlib.tests.blackbox.test_push',
- 'bzrlib.tests.blackbox.test_reconcile',
- 'bzrlib.tests.blackbox.test_reconfigure',
- 'bzrlib.tests.blackbox.test_reference',
- 'bzrlib.tests.blackbox.test_remerge',
- 'bzrlib.tests.blackbox.test_remove',
- 'bzrlib.tests.blackbox.test_re_sign',
- 'bzrlib.tests.blackbox.test_remove_tree',
- 'bzrlib.tests.blackbox.test_revert',
- 'bzrlib.tests.blackbox.test_revno',
- 'bzrlib.tests.blackbox.test_revision_history',
- 'bzrlib.tests.blackbox.test_revision_info',
- 'bzrlib.tests.blackbox.test_rmbranch',
- 'bzrlib.tests.blackbox.test_selftest',
- 'bzrlib.tests.blackbox.test_send',
- 'bzrlib.tests.blackbox.test_serve',
- 'bzrlib.tests.blackbox.test_shared_repository',
- 'bzrlib.tests.blackbox.test_shelve',
- 'bzrlib.tests.blackbox.test_sign_my_commits',
- 'bzrlib.tests.blackbox.test_split',
- 'bzrlib.tests.blackbox.test_status',
- 'bzrlib.tests.blackbox.test_switch',
- 'bzrlib.tests.blackbox.test_tags',
- 'bzrlib.tests.blackbox.test_testament',
- 'bzrlib.tests.blackbox.test_too_much',
- 'bzrlib.tests.blackbox.test_uncommit',
- 'bzrlib.tests.blackbox.test_unknowns',
- 'bzrlib.tests.blackbox.test_update',
- 'bzrlib.tests.blackbox.test_upgrade',
- 'bzrlib.tests.blackbox.test_version',
- 'bzrlib.tests.blackbox.test_version_info',
- 'bzrlib.tests.blackbox.test_versioning',
- 'bzrlib.tests.blackbox.test_view',
- 'bzrlib.tests.blackbox.test_whoami',
+ 'test_add',
+ 'test_added',
+ 'test_alias',
+ 'test_aliases',
+ 'test_ancestry',
+ 'test_annotate',
+ 'test_branch',
+ 'test_break_lock',
+ 'test_breakin',
+ 'test_bound_branches',
+ 'test_bundle_info',
+ 'test_cat',
+ 'test_cat_revision',
+ 'test_check',
+ 'test_checkout',
+ 'test_clean_tree',
+ 'test_command_encoding',
+ 'test_commit',
+ 'test_config',
+ 'test_conflicts',
+ 'test_debug',
+ 'test_deleted',
+ 'test_diff',
+ 'test_dump_btree',
+ 'test_dpush',
+ 'test_exceptions',
+ 'test_export',
+ 'test_filesystem_cicp',
+ 'test_filtered_view_ops',
+ 'test_find_merge_base',
+ 'test_help',
+ 'test_hooks',
+ 'test_ignore',
+ 'test_ignored',
+ 'test_info',
+ 'test_init',
+ 'test_inventory',
+ 'test_join',
+ 'test_locale',
+ 'test_log',
+ 'test_logformats',
+ 'test_lookup_revision',
+ 'test_ls',
+ 'test_lsprof',
+ 'test_merge',
+ 'test_merge_directive',
+ 'test_missing',
+ 'test_modified',
+ 'test_mv',
+ 'test_nick',
+ 'test_non_ascii',
+ 'test_outside_wt',
+ 'test_pack',
+ 'test_pull',
+ 'test_push',
+ 'test_reconcile',
+ 'test_reconfigure',
+ 'test_reference',
+ 'test_remerge',
+ 'test_remove',
+ 'test_re_sign',
+ 'test_remove_tree',
+ 'test_revert',
+ 'test_revno',
+ 'test_revision_history',
+ 'test_revision_info',
+ 'test_rmbranch',
+ 'test_script',
+ 'test_selftest',
+ 'test_send',
+ 'test_serve',
+ 'test_shared_repository',
+ 'test_shelve',
+ 'test_sign_my_commits',
+ 'test_split',
+ 'test_status',
+ 'test_switch',
+ 'test_tags',
+ 'test_testament',
+ 'test_too_much',
+ 'test_uncommit',
+ 'test_unknowns',
+ 'test_update',
+ 'test_upgrade',
+ 'test_version',
+ 'test_version_info',
+ 'test_versioning',
+ 'test_view',
+ 'test_whoami',
]
# add the tests for the sub modules
- suite.addTests(loader.loadTestsFromModuleNames(testmod_names))
+ suite.addTests(loader.loadTestsFromModuleNames(
+ [prefix + module_name for module_name in testmod_names]))
return suite
=== added file 'bzrlib/tests/blackbox/test_script.py'
--- a/bzrlib/tests/blackbox/test_script.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/blackbox/test_script.py 2010-10-13 13:57:22 +0000
@@ -0,0 +1,62 @@
+# Copyright (C) 2010 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Blacbox tests for the test-script command."""
+
+import os
+
+from bzrlib import (
+ tests,
+ )
+from bzrlib.tests import (
+ script,
+ )
+
+
+class TestTestScript(tests.TestCaseInTempDir):
+
+ def test_unknnown_file(self):
+ self.run_bzr(['test-script', 'I-do-not-exist'], retcode=3)
+
+ def test_empty_file(self):
+ self.build_tree_contents([('script', '')])
+ out, err = self.run_bzr(['test-script', 'script'])
+ out_lines = out.splitlines()
+ self.assertStartsWith(out_lines[-3], 'Ran 1 test in ')
+ self.assertEquals('OK', out_lines[-1])
+ self.assertEquals('', err)
+
+ def test_simple_file(self):
+ self.build_tree_contents([('script', '''
+$ echo hello world
+hello world
+''')])
+ out, err = self.run_bzr(['test-script', 'script'])
+ 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
+hello bar
+''')])
+ out, err = self.run_bzr(['test-script', 'script'], retcode=1)
+ out_lines = out.splitlines()
+ self.assertStartsWith(out_lines[-3], 'Ran 1 test in ')
+ self.assertEquals('FAILED (failures=1)', out_lines[-1])
+ self.assertEquals('', err)
=== modified file 'bzrlib/tests/script.py'
--- a/bzrlib/tests/script.py 2010-09-15 05:10:04 +0000
+++ b/bzrlib/tests/script.py 2010-10-13 07:55:13 +0000
@@ -28,6 +28,8 @@
from cStringIO import StringIO
from bzrlib import (
+ commands,
+ errors,
osutils,
tests,
)
@@ -511,3 +513,32 @@
def run_script(test_case, script_string):
"""Run the given script within a testcase"""
return ScriptRunner().run_script(test_case, script_string)
+
+
+class cmd_test_script(commands.Command):
+ """Run a shell-like test from a file."""
+
+ hidden = True
+ takes_args = ['infile']
+
+ @commands.display_command
+ def run(self, infile):
+
+ f = open(infile)
+ try:
+ script = f.read()
+ finally:
+ f.close()
+
+ class Test(TestCaseWithTransportAndScript):
+
+ script = None # Set before running
+
+ def test_it(self):
+ self.run_script(script)
+
+ runner = tests.TextTestRunner(stream=self.outf)
+ test = Test('test_it')
+ test.path = os.path.realpath(infile)
+ res = runner.run(test)
+ return len(res.errors) + len(res.failures)
=== modified file 'doc/developers/testing.txt'
--- a/doc/developers/testing.txt 2010-10-11 22:40:23 +0000
+++ b/doc/developers/testing.txt 2010-10-13 07:55:13 +0000
@@ -340,9 +340,9 @@
Shell-like tests
----------------
-``bzrlib/tests/script.py`` allows users to write tests in a syntax very close to a shell session,
-using a restricted and limited set of commands that should be enough to mimic
-most of the behaviours.
+``bzrlib/tests/script.py`` allows users to write tests in a syntax very
+close to a shell session, using a restricted and limited set of commands
+that should be enough to mimic most of the behaviours.
A script is a set of commands, each command is composed of:
@@ -433,6 +433,12 @@
$ cat file
+You can run files containing shell-like scripts with::
+
+ $ bzr test-script <script>
+
+where ``<script>`` is the path to the file containing the shell-like script.
+
The actual use of ScriptRunner within a TestCase looks something like
this::
=== modified file 'doc/en/release-notes/bzr-2.3.txt'
--- a/doc/en/release-notes/bzr-2.3.txt 2010-10-15 11:20:45 +0000
+++ b/doc/en/release-notes/bzr-2.3.txt 2010-10-15 11:33:33 +0000
@@ -86,6 +86,9 @@
Instead, use '...' as a wildcard if you don't care about the output.
(Martin Pool, #637830)
+* ``bzr test-script script`` is a new command that runs a shell-like script
+ from an the ``script`` file. (Vincent Ladeuil)
+
bzr 2.3b2
#########
=== modified file 'doc/en/whats-new/whats-new-in-2.3.txt'
--- a/doc/en/whats-new/whats-new-in-2.3.txt 2010-10-15 07:35:21 +0000
+++ b/doc/en/whats-new/whats-new-in-2.3.txt 2010-10-15 11:30:54 +0000
@@ -90,6 +90,14 @@
``bzr log -vp -r mainline:annotate:bzrlib/transform.py:500``
(Aaron Bentley)
+Testing/Bug reporting
+*********************
+
+* Shell-like scripts can now be run directly from the command line without
+ writing a python test. This should help users adding reproducing recipes
+ to bug reports. (Vincent Ladeuil)
+
+
Documentation
*************
More information about the bazaar-commits
mailing list