Rev 4668: Separate error from normal output. in file:///home/vila/src/bzr/experimental/shell-like-tests/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Sep 1 10:33:43 BST 2009


At file:///home/vila/src/bzr/experimental/shell-like-tests/

------------------------------------------------------------
revno: 4668
revision-id: v.ladeuil+lp at free.fr-20090901093342-ph59wrvdt85xrpbn
parent: v.ladeuil+lp at free.fr-20090901092104-ol3np0cs3xyyytgw
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: shell-like-tests
timestamp: Tue 2009-09-01 11:33:42 +0200
message:
  Separate error from normal output.
  
  * bzrlib/tests/test_script.py:
  (TestScriptSyntax): Add error to the mix.
  
  * bzrlib/tests/script.py:
  (_script_to_commands): Separate error from output.
-------------- next part --------------
=== modified file 'bzrlib/tests/script.py'
--- a/bzrlib/tests/script.py	2009-09-01 09:21:04 +0000
+++ b/bzrlib/tests/script.py	2009-09-01 09:33:42 +0000
@@ -41,14 +41,14 @@
     Empty lines are ignored.
     Input and output are full lines terminated by a '\n'.
     Input lines start with '<'.
-    Output lines start with '>' 
+    Output lines start with '>'.
+    Error lines start with '2>'.
     """
     commands = []
     cmd_cur = None
     cmd_line = 1
     lineno = 0
-    input = None
-    output = None
+    input, output, error = None, None, None
     for line in text.split('\n'):
         lineno += 1
         # Keep a copy for error reporting
@@ -77,19 +77,23 @@
                 output = []
             output.append(line[1:] + '\n')
             continue
+        elif line.startswith('2>'):
+            if error is None:
+                if cmd_cur is None:
+                    raise SyntaxError('No command for that error',
+                                      (file_name, lineno, 1, orig))
+                error = []
+            error.append(line[2:] + '\n')
+            continue
         else:
             # Time to output the current command
             if cmd_cur is not None:
-                commands.append((cmd_cur, input, output))
+                commands.append((cmd_cur, input, output, error))
             # And start a new one
             cmd_cur = list(split(line))
             cmd_line = lineno
-            input = None
-            output = None
+            input, output, error = None, None, None
     # Add the last seen command
     if cmd_cur is not None:
-        commands.append((cmd_cur, input, output))
+        commands.append((cmd_cur, input, output, error))
     return commands
-
-
-

=== modified file 'bzrlib/tests/test_script.py'
--- a/bzrlib/tests/test_script.py	2009-09-01 09:21:04 +0000
+++ b/bzrlib/tests/test_script.py	2009-09-01 09:33:42 +0000
@@ -29,21 +29,23 @@
         self.assertEquals([], script._script_to_commands('\n'))
 
     def test_simple_command(self):
-        self.assertEquals([(['cd', 'trunk'], None, None)],
+        self.assertEquals([(['cd', 'trunk'], None, None, None)],
                            script._script_to_commands('cd trunk'))
 
     def test_command_with_single_quoted_param(self):
         story = """bzr commit -m 'two words'"""
-        self.assertEquals([(['bzr', 'commit', '-m', 'two words'], None, None)],
+        self.assertEquals([(['bzr', 'commit', '-m', 'two words'],
+                            None, None, None)],
                            script._script_to_commands(story))
 
     def test_command_with_double_quoted_param(self):
         story = """bzr commit -m "two words" """
-        self.assertEquals([(['bzr', 'commit', '-m', 'two words'], None, None)],
+        self.assertEquals([(['bzr', 'commit', '-m', 'two words'],
+                            None, None, None)],
                            script._script_to_commands(story))
 
     def test_command_with_input(self):
-        self.assertEquals([(['cat', '>file'], ['content\n'], None)],
+        self.assertEquals([(['cat', '>file'], ['content\n'], None, None)],
                            script._script_to_commands('cat >file\n<content\n'))
 
     def test_command_with_output(self):
@@ -51,9 +53,17 @@
 bzr add
 >adding file
 """
-        self.assertEquals([(['bzr', 'add'], None, ['adding file\n'])],
+        self.assertEquals([(['bzr', 'add'], None, ['adding file\n'], None)],
                           script._script_to_commands(story))
 
+    def test_command_with_error(self):
+        story = """
+bzr branch foo
+2>bzr: ERROR: Not a branch: "foo"
+"""
+        self.assertEquals([(['bzr', 'branch', 'foo'],
+                            None, None, ['bzr: ERROR: Not a branch: "foo"\n'])],
+                          script._script_to_commands(story))
     def test_input_without_command(self):
         self.assertRaises(SyntaxError, script._script_to_commands, '<input')
 
@@ -64,7 +74,8 @@
         story = """
 foo = `bzr file-id toto`
 """
-        self.assertEquals([(['foo', '=', '`bzr file-id toto`'], None, None)],
+        self.assertEquals([(['foo', '=', '`bzr file-id toto`'],
+                            None, None, None)],
                           script._script_to_commands(story))
 
 



More information about the bazaar-commits mailing list