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
1=== modified file 'NEWS'
2--- NEWS 2010-06-15 04:32:49 +0000
3+++ NEWS 2010-06-15 07:45:44 +0000
4@@ -36,6 +36,10 @@
5 * ``bzr log --exclude-common-ancestry`` is now taken into account for
6 linear ancetries. (Vincent Ladeuil, #575631)
7
8+* ``bzr pull`` now works when a lp: URL is explicitly defined as the parent
9+ or pull location in locations.conf or branch.conf.
10+ (Gordon Tyler, #534787)
11+
12 * Ensure that wrong path specifications in ``BZR_PLUGINS_AT`` display
13 proper error messages. (Vincent Ladeuil, #591215)
14
15@@ -52,13 +56,13 @@
16 test that all commands available to the test suite have help.
17 (Robert Collins, #177500)
18
19+* ``ScriptRunner`` now strips off leading indentation from test scripts,
20+ which previously caused "SyntaxError: No command for line".
21+ (Martin Pool)
22+
23 * Relative imports in plugins are now handled correctly when using
24 BZR_PLUGINS_AT. (Vincent Ladeuil, #588959)
25
26-* ``bzr pull`` now works when a lp: URL is explicitly defined as the parent
27- or pull location in locations.conf or branch.conf.
28- (Gordon Tyler, #534787)
29-
30 Improvements
31 ************
32
33
34=== modified file 'bzrlib/tests/script.py'
35--- bzrlib/tests/script.py 2010-02-23 07:43:11 +0000
36+++ bzrlib/tests/script.py 2010-06-15 07:45:44 +0000
37@@ -24,6 +24,7 @@
38 import glob
39 import os
40 import shlex
41+import textwrap
42 from cStringIO import StringIO
43
44 from bzrlib import (
45@@ -73,6 +74,7 @@
46 cmd_line = 1
47 lineno = 0
48 input, output, error = None, None, None
49+ text = textwrap.dedent(text)
50 for line in text.split('\n'):
51 lineno += 1
52 # Keep a copy for error reporting
53@@ -475,3 +477,7 @@
54 def run_command(self, cmd, input, output, error):
55 return self.script_runner.run_command(self, cmd, input, output, error)
56
57+
58+def run_script(test_case, script_string):
59+ """Run the given script within a testcase"""
60+ return ScriptRunner().run_script(test_case, script_string)
61
62=== modified file 'bzrlib/tests/test_script.py'
63--- bzrlib/tests/test_script.py 2010-02-23 07:43:11 +0000
64+++ bzrlib/tests/test_script.py 2010-06-15 07:45:44 +0000
65@@ -51,6 +51,18 @@
66 [(['cat', '>file'], 'content\n', None, None)],
67 script._script_to_commands('$ cat >file\n<content\n'))
68
69+ def test_indented(self):
70+ # scripts are commonly given indented within the test source code, and
71+ # common indentation is stripped off
72+ story = """
73+ $ bzr add
74+ adding file
75+ adding file2
76+ """
77+ self.assertEquals([(['bzr', 'add'], None,
78+ 'adding file\nadding file2\n', None)],
79+ script._script_to_commands(story))
80+
81 def test_command_with_output(self):
82 story = """
83 $ bzr add
84
85=== modified file 'doc/developers/testing.txt'
86--- doc/developers/testing.txt 2010-06-04 03:09:35 +0000
87+++ doc/developers/testing.txt 2010-06-15 07:45:44 +0000
88@@ -395,20 +395,21 @@
89 The actual use of ScriptRunner within a TestCase looks something like
90 this::
91
92- def test_unshelve_keep(self):
93- # some setup here
94- sr = ScriptRunner()
95- sr.run_script(self, '''
96- $ bzr add file
97- $ bzr shelve --all -m Foo
98- $ bzr shelve --list
99- 1: Foo
100- $ bzr unshelve --keep
101- $ bzr shelve --list
102- 1: Foo
103- $ cat file
104- contents of file
105- ''')
106+ from bzrlib.tests import script
107+
108+ def test_unshelve_keep(self):
109+ # some setup here
110+ script.run_script(self, '''
111+ $ bzr add file
112+ $ bzr shelve --all -m Foo
113+ $ bzr shelve --list
114+ 1: Foo
115+ $ bzr unshelve --keep
116+ $ bzr shelve --list
117+ 1: Foo
118+ $ cat file
119+ contents of file
120+ ''')
121
122
123 Import tariff tests
124@@ -872,4 +873,4 @@
125 .. |--| unicode:: U+2014
126
127 ..
128- vim: ft=rst tw=74 ai
129+ vim: ft=rst tw=74 ai et sw=4