Rev 4680: Catch the retcode for all commands. in file:///home/vila/src/bzr/experimental/shell-like-tests/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Sep 9 14:48:05 BST 2009


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

------------------------------------------------------------
revno: 4680
revision-id: v.ladeuil+lp at free.fr-20090909134805-9upqicdxkuc69avk
parent: v.ladeuil+lp at free.fr-20090909130820-0ymqauhsrjt2qt9t
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: shell-like-tests
timestamp: Wed 2009-09-09 15:48:05 +0200
message:
  Catch the retcode for all commands.
  
  * bzrlib/tests/script.py:
  (ScriptRunner._check_output): Fix typos in comment.
  (ScriptRunner.do_bzr, ScriptRunner.run_command): Get and returns
  the retcode.
  (ScriptRunner.do_cat, ScriptRunner.do_cd, ScriptRunner.do_mkdir):
  Returns a retcode.
  
  * bzrlib/tests/__init__.py:
  (TestCase._run_bzr_core): Also returns the retcode for inspection
  by callers.
-------------- 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 13:48:05 +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 13:48:05 +0000
@@ -232,7 +232,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 +244,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 +261,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:
             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 +290,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 +307,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 +322,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 +338,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 +346,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 13:48:05 +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)
 
@@ -143,29 +144,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 +235,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 13:48:05 +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