Rev 4678: Script execution must stop on unexpected errors. in file:///home/vila/src/bzr/experimental/shell-like-tests/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Sep 4 15:55:59 BST 2009


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

------------------------------------------------------------
revno: 4678
revision-id: v.ladeuil+lp at free.fr-20090904145559-f1yfpurfxs668klk
parent: v.ladeuil+lp at free.fr-20090904131523-t280hl1i8efz1ncb
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: shell-like-tests
timestamp: Fri 2009-09-04 16:55:59 +0200
message:
  Script execution must stop on unexpected errors.
  
  * bzrlib/tests/test_script.py:
  (TestScriptExecution.test_stops_on_unexpected_error,
  TestScriptExecution.test_continue_on_expected_error): Test
  behaviour on errors.
  
  * bzrlib/tests/script.py:
  (ScriptRunner.run_command): Fail on unexpected errors.
-------------- next part --------------
=== modified file 'bzrlib/tests/script.py'
--- a/bzrlib/tests/script.py	2009-09-04 13:15:23 +0000
+++ b/bzrlib/tests/script.py	2009-09-04 14:55:59 +0000
@@ -36,7 +36,6 @@
 When no output is specified, any ouput from the command is accepted
 and let the execution continue. 
 
-FIXME: not yet true
 If an error occurs and no expected error is specified, the execution stops.
 
 The matching is done on a full string comparison basis unless '...' is used, in
@@ -63,12 +62,34 @@
   2> bzr: ERROR: unknown command "not-a-command"
 
 You can use ellipsis (...) to replace any piece of text you don't want to be
-matched exactly.
+matched exactly:
 
   bzr branch not-a-branch
   2>bzr: ERROR: Not a branch...not-a-branch/".
 
 
+This can be used to ignore entire lines too:
+
+cat
+<first line
+<second line
+<third line
+<fourth line
+<last line
+>first line
+>...
+>last line
+
+You can check the content of a file with cat:
+
+  cat <file
+  >expected content
+
+You can also check the existence of a file with cat, the following will fail if
+the file doesn't exist:
+
+  cat file
+
 """
 
 import doctest
@@ -227,7 +248,7 @@
             # 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
-            # decemtly readable.
+            # decently readable.
             self.test_case.assertEqualDiff(expected, actual)
 
     def run_command(self, cmd, input, output, error):
@@ -244,6 +265,8 @@
 
         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
 
     def _read_input(self, input, in_name):

=== modified file 'bzrlib/tests/test_script.py'
--- a/bzrlib/tests/test_script.py	2009-09-04 13:15:23 +0000
+++ b/bzrlib/tests/test_script.py	2009-09-04 14:55:59 +0000
@@ -88,7 +88,7 @@
     def test_unknown_command(self):
         self.assertRaises(SyntaxError, self.run_script, 'foo')
 
-    def test_unexpected_output(self):
+    def test_stops_on_unexpected_output(self):
         story = """
 mkdir dir
 cd dir
@@ -97,6 +97,21 @@
         self.assertRaises(AssertionError, self.run_script, story)
 
 
+    def test_stops_on_unexpected_error(self):
+        story = """
+cat
+<Hello
+bzr not-a-command
+"""
+        self.assertRaises(AssertionError, self.run_script, story)
+
+    def test_continue_on_expected_error(self):
+        story = """
+bzr not-a-command
+2>..."not-a-command"
+"""
+        self.run_script(story)
+
     def test_ellipsis_output(self):
         story = """
 cat



More information about the bazaar-commits mailing list