Rev 4608: Merge shell-like-tests into description in file:///home/vila/src/bzr/experimental/conflict-manager/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Sep 9 15:04:42 BST 2009


At file:///home/vila/src/bzr/experimental/conflict-manager/

------------------------------------------------------------
revno: 4608 [merge]
revision-id: v.ladeuil+lp at free.fr-20090909140442-epfva9k97vbez7rl
parent: v.ladeuil+lp at free.fr-20090909121151-cdj33eyvs7m3f2bf
parent: v.ladeuil+lp at free.fr-20090909140419-14581woemoz5lzka
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: description
timestamp: Wed 2009-09-09 16:04:42 +0200
message:
  Merge shell-like-tests into description
modified:
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/script.py         script.py-20090901081155-yk3tiy1nunxg16ne-1
  bzrlib/tests/test_script.py    test_script.py-20090901081156-y90z4w2t62fv7e7b-1
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-09-01 08:24:44 +0000
+++ b/bzrlib/tests/__init__.py	2009-09-09 14:04:19 +0000
@@ -1670,7 +1670,7 @@
         if retcode is not None:
             self.assertEquals(retcode, result,
                               message='Unexpected return code')
-        return out, err
+        return result, out, err
 
     def run_bzr(self, args, retcode=0, encoding=None, stdin=None,
                 working_dir=None, error_regexes=[], output_encoding=None):
@@ -1705,7 +1705,7 @@
         :keyword error_regexes: A list of expected error messages.  If
             specified they must be seen in the error output of the command.
         """
-        out, err = self._run_bzr_autosplit(
+        retcode, out, err = self._run_bzr_autosplit(
             args=args,
             retcode=retcode,
             encoding=encoding,

=== modified file 'bzrlib/tests/script.py'
--- a/bzrlib/tests/script.py	2009-09-04 14:55:59 +0000
+++ b/bzrlib/tests/script.py	2009-09-09 14:04:19 +0000
@@ -38,6 +38,9 @@
 
 If an error occurs and no expected error is specified, the execution stops.
 
+An error is defined by a returned status different from zero, not by the
+presence of text on the error stream.
+
 The matching is done on a full string comparison basis unless '...' is used, in
 which case expected output/errors can be lees precise.
 
@@ -232,7 +235,7 @@
 
     def run_script(self, text):
         for cmd, input, output, error in _script_to_commands(text):
-            out, err = self.run_command(cmd, input, output, error)
+            self.run_command(cmd, input, output, error)
 
     def _check_output(self, expected, actual):
         if expected is None:
@@ -244,11 +247,11 @@
             expected, actual, self.check_options)
         if not matching:
             # Note that we can't use output_checker.output_difference() here
-            # because... the API is boken (expected must be a doctest specific
-            # object of whicha 'want' attribute will be our 'expected'
-            # parameter. So we just fallbacl to our good old assertEqualDiff
-            # since we know there are differences and the output should be
-            # decently readable.
+            # because... the API is broken ('expected' must be a doctest
+            # specific object of which a 'want' attribute will be our
+            # 'expected' parameter. So we just fallback to our good old
+            # assertEqualDiff since we know there *are* differences and the
+            # output should be decently readable.
             self.test_case.assertEqualDiff(expected, actual)
 
     def run_command(self, cmd, input, output, error):
@@ -261,13 +264,13 @@
             str_input = ''
         else:
             str_input = ''.join(input)
-        actual_output, actual_error = method(str_input, cmd[1:])
+        retcode, actual_output, actual_error = method(str_input, cmd[1:])
 
         self._check_output(output, actual_output)
         self._check_output(error, actual_error)
-        if not error and actual_error:
+        if retcode and not error and actual_error:
             self.test_case.fail('Unexpected error: %s' % actual_error)
-        return actual_output, actual_error
+        return retcode, actual_output, actual_error
 
     def _read_input(self, input, in_name):
         if in_name is not None:
@@ -290,9 +293,9 @@
         return output
 
     def do_bzr(self, input, args):
-        out, err = self.test_case._run_bzr_core(
+        retcode, out, err = self.test_case._run_bzr_core(
             args, retcode=None, encoding=None, stdin=input, working_dir=None)
-        return out, err
+        return retcode, out, err
 
     def do_cat(self, input, args):
         (in_name, out_name, out_mode, args) = _scan_redirection_options(args)
@@ -307,7 +310,7 @@
         output = input
         # Handle output redirections
         output = self._write_output(output, out_name, out_mode)
-        return output, None
+        return 0, output, None
 
     def do_echo(self, input, args):
         (in_name, out_name, out_mode, args) = _scan_redirection_options(args)
@@ -322,7 +325,7 @@
         output = input
         # Handle output redirections
         output = self._write_output(output, out_name, out_mode)
-        return output, None
+        return 0, output, None
 
     def _ensure_in_jail(self, path):
         jail_root = self.test_case.get_jail_root()
@@ -338,7 +341,7 @@
         else:
             d = self.test_case.get_jail_root()
         os.chdir(d)
-        return None, None
+        return 0, None, None
 
     def do_mkdir(self, input, args):
         if not args or len(args) != 1:
@@ -346,7 +349,7 @@
         d = args[0]
         self._ensure_in_jail(d)
         os.mkdir(d)
-        return None, None
+        return 0, None, None
 
 
 class TestCaseWithMemoryTransportAndScript(tests.TestCaseWithMemoryTransport):

=== modified file 'bzrlib/tests/test_script.py'
--- a/bzrlib/tests/test_script.py	2009-09-04 14:55:59 +0000
+++ b/bzrlib/tests/test_script.py	2009-09-09 14:04:19 +0000
@@ -68,6 +68,7 @@
         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')
 
@@ -92,7 +93,7 @@
         story = """
 mkdir dir
 cd dir
->Hello, I have just cd into dir !
+>The cd command ouputs nothing
 """
         self.assertRaises(AssertionError, self.run_script, story)
 
@@ -112,6 +113,17 @@
 """
         self.run_script(story)
 
+    def test_continue_on_error_output(self):
+        # The status matters, not the output
+        story = """
+bzr init
+cat >file
+<Hello
+bzr add file
+bzr commit -m 'adding file'
+"""
+        self.run_script(story)
+
     def test_ellipsis_output(self):
         story = """
 cat
@@ -143,29 +155,34 @@
         self.assertRaises(SyntaxError, self.run_script, 'cat foo <bar')
 
     def test_cat_input_to_output(self):
-        out, err = self.run_command(['cat'], 'content\n', 'content\n', None)
+        retcode, out, err = self.run_command(['cat'],
+                                             'content\n', 'content\n', None)
         self.assertEquals('content\n', out)
         self.assertEquals(None, err)
 
     def test_cat_file_to_output(self):
         self.build_tree_contents([('file', 'content\n')])
-        out, err = self.run_command(['cat', 'file'], None, 'content\n', None)
+        retcode, out, err = self.run_command(['cat', 'file'],
+                                             None, 'content\n', None)
         self.assertEquals('content\n', out)
         self.assertEquals(None, err)
 
     def test_cat_input_to_file(self):
-        out, err = self.run_command(['cat', '>file'], 'content\n', None, None)
+        retcode, out, err = self.run_command(['cat', '>file'],
+                                             'content\n', None, None)
         self.assertFileEqual('content\n', 'file')
         self.assertEquals(None, out)
         self.assertEquals(None, err)
-        out, err = self.run_command(['cat', '>>file'], 'more\n', None, None)
+        retcode, out, err = self.run_command(['cat', '>>file'],
+                                             'more\n', None, None)
         self.assertFileEqual('content\nmore\n', 'file')
         self.assertEquals(None, out)
         self.assertEquals(None, err)
 
     def test_cat_file_to_file(self):
         self.build_tree_contents([('file', 'content\n')])
-        out, err = self.run_command(['cat', 'file', '>file2'], None, None, None)
+        retcode, out, err = self.run_command(['cat', 'file', '>file2'],
+                                             None, None, None)
         self.assertFileEqual('content\n', 'file2')
 
 
@@ -229,29 +246,32 @@
         self.assertRaises(SyntaxError, self.run_script, story)
 
     def test_echo_to_output(self):
-        out, err = self.run_command(['echo'], None, '\n', None)
+        retcode, out, err = self.run_command(['echo'], None, '\n', None)
         self.assertEquals('\n', out)
         self.assertEquals(None, err)
 
     def test_echo_some_to_output(self):
-        out, err = self.run_command(['echo', 'hello'], None, 'hello\n', None)
+        retcode, out, err = self.run_command(['echo', 'hello'],
+                                             None, 'hello\n', None)
         self.assertEquals('hello\n', out)
         self.assertEquals(None, err)
 
     def test_echo_more_output(self):
-        out, err = self.run_command(['echo', 'hello', 'happy', 'world'],
-                                    None, 'hellohappyworld\n', None)
+        retcode, out, err = self.run_command(
+            ['echo', 'hello', 'happy', 'world'],
+            None, 'hellohappyworld\n', None)
         self.assertEquals('hellohappyworld\n', out)
         self.assertEquals(None, err)
 
     def test_echo_appended(self):
-        out, err = self.run_command(['echo', 'hello', '>file'],
-                                    None, None, None)
+        retcode, out, err = self.run_command(['echo', 'hello', '>file'],
+                                             None, None, None)
         self.assertEquals(None, out)
         self.assertEquals(None, err)
         self.assertFileEqual('hello\n', 'file')
-        out, err = self.run_command(['echo', 'happy', '>>file'],
-                                    None, None, None)
+        retcode, out, err = self.run_command(['echo', 'happy', '>>file'],
+                                             None, None, None)
         self.assertEquals(None, out)
         self.assertEquals(None, err)
         self.assertFileEqual('hello\nhappy\n', 'file')
+

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2009-09-03 08:10:23 +0000
+++ b/bzrlib/tests/test_selftest.py	2009-09-09 14:04:19 +0000
@@ -1991,30 +1991,32 @@
 
         Attempts to run bzr from inside this class don't actually run it.
 
-        We test how run_bzr actually invokes bzr in another location.
-        Here we only need to test that it is run_bzr passes the right
-        parameters to run_bzr.
+        We test how run_bzr actually invokes bzr in another location.  Here we
+        only need to test that it passes the right parameters to run_bzr.
         """
         self.argv = list(argv)
         self.retcode = retcode
         self.encoding = encoding
         self.stdin = stdin
         self.working_dir = working_dir
-        return self.out, self.err
+        return self.retcode, self.out, self.err
 
     def test_run_bzr_error(self):
         self.out = "It sure does!\n"
         out, err = self.run_bzr_error(['^$'], ['rocks'], retcode=34)
         self.assertEqual(['rocks'], self.argv)
         self.assertEqual(34, self.retcode)
-        self.assertEqual(out, 'It sure does!\n')
+        self.assertEqual('It sure does!\n', out)
+        self.assertEquals(out, self.out)
+        self.assertEqual('', err)
+        self.assertEquals(err, self.err)
 
     def test_run_bzr_error_regexes(self):
         self.out = ''
         self.err = "bzr: ERROR: foobarbaz is not versioned"
         out, err = self.run_bzr_error(
-                ["bzr: ERROR: foobarbaz is not versioned"],
-                ['file-id', 'foobarbaz'])
+            ["bzr: ERROR: foobarbaz is not versioned"],
+            ['file-id', 'foobarbaz'])
 
     def test_encoding(self):
         """Test that run_bzr passes encoding to _run_bzr_core"""



More information about the bazaar-commits mailing list