Merge lp:~mbp/bzr/scripts into lp:bzr

Proposed by Martin Pool
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 5296
Proposed branch: lp:~mbp/bzr/scripts
Merge into: lp:bzr
Diff against target: 129 lines (+42/-19)
4 files modified
NEWS (+8/-4)
bzrlib/tests/script.py (+6/-0)
bzrlib/tests/test_script.py (+12/-0)
doc/developers/testing.txt (+16/-15)
To merge this branch: bzr merge lp:~mbp/bzr/scripts
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+27581@code.launchpad.net

Commit message

ignore common leading whitespace in shell-like script tests

Description of the change

This makes shell-like tests ignore consistent leading indentation which makes them much easier to use.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

Nice sugar.
Will it still work if a test expects an output with leading spaces like:
$ bzr xxx
    done

I'm not sure we *need* to support that though and a leading '\ ' may work too in this case.

review: Approve
Revision history for this message
Martin Pool (mbp) wrote :

On 15 June 2010 17:35, Vincent Ladeuil <email address hidden> wrote:
> Review: Approve
> Nice sugar.
> Will it still work if a test expects an output with leading spaces like:
> $ bzr xxx
>    done
>
> I'm not sure we *need* to support that though and a leading '\ ' may work too in this case.

I think that's an important case and yes, it does support it: dedent
strips the common prefix of space from each line.

--
Martin

Revision history for this message
Martin Pool (mbp) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2010-06-15 04:32:49 +0000
+++ NEWS 2010-06-15 07:45:44 +0000
@@ -36,6 +36,10 @@
36* ``bzr log --exclude-common-ancestry`` is now taken into account for36* ``bzr log --exclude-common-ancestry`` is now taken into account for
37 linear ancetries. (Vincent Ladeuil, #575631)37 linear ancetries. (Vincent Ladeuil, #575631)
3838
39* ``bzr pull`` now works when a lp: URL is explicitly defined as the parent
40 or pull location in locations.conf or branch.conf.
41 (Gordon Tyler, #534787)
42
39* Ensure that wrong path specifications in ``BZR_PLUGINS_AT`` display43* Ensure that wrong path specifications in ``BZR_PLUGINS_AT`` display
40 proper error messages. (Vincent Ladeuil, #591215)44 proper error messages. (Vincent Ladeuil, #591215)
4145
@@ -52,13 +56,13 @@
52 test that all commands available to the test suite have help.56 test that all commands available to the test suite have help.
53 (Robert Collins, #177500)57 (Robert Collins, #177500)
5458
59* ``ScriptRunner`` now strips off leading indentation from test scripts,
60 which previously caused "SyntaxError: No command for line".
61 (Martin Pool)
62
55* Relative imports in plugins are now handled correctly when using63* Relative imports in plugins are now handled correctly when using
56 BZR_PLUGINS_AT. (Vincent Ladeuil, #588959)64 BZR_PLUGINS_AT. (Vincent Ladeuil, #588959)
5765
58* ``bzr pull`` now works when a lp: URL is explicitly defined as the parent
59 or pull location in locations.conf or branch.conf.
60 (Gordon Tyler, #534787)
61
62Improvements66Improvements
63************67************
6468
6569
=== modified file 'bzrlib/tests/script.py'
--- bzrlib/tests/script.py 2010-02-23 07:43:11 +0000
+++ bzrlib/tests/script.py 2010-06-15 07:45:44 +0000
@@ -24,6 +24,7 @@
24import glob24import glob
25import os25import os
26import shlex26import shlex
27import textwrap
27from cStringIO import StringIO28from cStringIO import StringIO
2829
29from bzrlib import (30from bzrlib import (
@@ -73,6 +74,7 @@
73 cmd_line = 174 cmd_line = 1
74 lineno = 075 lineno = 0
75 input, output, error = None, None, None76 input, output, error = None, None, None
77 text = textwrap.dedent(text)
76 for line in text.split('\n'):78 for line in text.split('\n'):
77 lineno += 179 lineno += 1
78 # Keep a copy for error reporting80 # Keep a copy for error reporting
@@ -475,3 +477,7 @@
475 def run_command(self, cmd, input, output, error):477 def run_command(self, cmd, input, output, error):
476 return self.script_runner.run_command(self, cmd, input, output, error)478 return self.script_runner.run_command(self, cmd, input, output, error)
477479
480
481def run_script(test_case, script_string):
482 """Run the given script within a testcase"""
483 return ScriptRunner().run_script(test_case, script_string)
478484
=== modified file 'bzrlib/tests/test_script.py'
--- bzrlib/tests/test_script.py 2010-02-23 07:43:11 +0000
+++ bzrlib/tests/test_script.py 2010-06-15 07:45:44 +0000
@@ -51,6 +51,18 @@
51 [(['cat', '>file'], 'content\n', None, None)],51 [(['cat', '>file'], 'content\n', None, None)],
52 script._script_to_commands('$ cat >file\n<content\n'))52 script._script_to_commands('$ cat >file\n<content\n'))
5353
54 def test_indented(self):
55 # scripts are commonly given indented within the test source code, and
56 # common indentation is stripped off
57 story = """
58 $ bzr add
59 adding file
60 adding file2
61 """
62 self.assertEquals([(['bzr', 'add'], None,
63 'adding file\nadding file2\n', None)],
64 script._script_to_commands(story))
65
54 def test_command_with_output(self):66 def test_command_with_output(self):
55 story = """67 story = """
56$ bzr add68$ bzr add
5769
=== modified file 'doc/developers/testing.txt'
--- doc/developers/testing.txt 2010-06-04 03:09:35 +0000
+++ doc/developers/testing.txt 2010-06-15 07:45:44 +0000
@@ -395,20 +395,21 @@
395The actual use of ScriptRunner within a TestCase looks something like395The actual use of ScriptRunner within a TestCase looks something like
396this::396this::
397397
398 def test_unshelve_keep(self):398 from bzrlib.tests import script
399 # some setup here399
400 sr = ScriptRunner()400 def test_unshelve_keep(self):
401 sr.run_script(self, '''401 # some setup here
402 $ bzr add file402 script.run_script(self, '''
403 $ bzr shelve --all -m Foo403 $ bzr add file
404 $ bzr shelve --list404 $ bzr shelve --all -m Foo
405 1: Foo405 $ bzr shelve --list
406 $ bzr unshelve --keep406 1: Foo
407 $ bzr shelve --list407 $ bzr unshelve --keep
408 1: Foo408 $ bzr shelve --list
409 $ cat file409 1: Foo
410 contents of file410 $ cat file
411 ''')411 contents of file
412 ''')
412413
413414
414Import tariff tests415Import tariff tests
@@ -872,4 +873,4 @@
872.. |--| unicode:: U+2014873.. |--| unicode:: U+2014
873874
874..875..
875 vim: ft=rst tw=74 ai876 vim: ft=rst tw=74 ai et sw=4