[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Allow testing of svn client exit codes

From: jeremy hinds <jeremy.hinds_at_gmail.com>
Date: Sat, 23 Feb 2008 23:24:08 -0700

I am hoping to take a crack at issue 3097 (exit non-zero when running
`svn pg` on an unset property) in the near future. And there are a
few similar exit-code issues in there. So I thought a good place to
start is with the ability to test this sort of thing.

I don't know if exit codes are as interesting for the other binaries,
so this patch only deals with the client. And since I am still trying
to familiarize myself with the conventions, and I'm no Python expert,
please let me know what I can do to make this better.

[[[
Allow testing of svn client exit codes.

* subversion/tests/cmdline/svntest/actions.py
 (run_and_verify_svn_with_exit): New function like run_and_verify_svn, but
 with an expected exit code parameter which is checked against the actual
 exit code.

* subversion/tests/cmdline/svntest/main.py
 (run_command_2): New, like run_command but also returns the exit code.
 (run_command_stdin_2): New, like run_command_stdin, but also returns
 the exit code.
 (run_command_stdin): Reimplemented as a wrapper around run_command_stdin_2.
 (run_svn_2): New, invokes svn client using run_command_2.

* subversion/tests/cmdline/svntest/verify.py
 (SVNUnexpectedExitCode): New exception raised when the exit code was not
 what was expected.
 (verify_exit_code): New, compares expected and actual exit code and fails
 the test if they are different.

Patch By: Jeremy Hinds
]]]

Index: subversion/tests/cmdline/svntest/actions.py
===================================================================
--- subversion/tests/cmdline/svntest/actions.py (revision 29576)
+++ subversion/tests/cmdline/svntest/actions.py (working copy)
@@ -193,7 +193,21 @@
                         False)
   return out, err

+def run_and_verify_svn_with_exit(message, expected_stdout, expected_stderr,
+ expected_exit, *varargs):
+ """Like run_and_verify_svn, except that it also checks the exit code."""
+ if expected_stderr is None:
+ raise verify.SVNIncorrectDatatype("expected_stderr must not be None")

+ want_err = None
+ if expected_stderr is not None and expected_stderr is not []:
+ want_err = True
+
+ actual_exit, out, err = main.run_svn_2(want_err, *varargs)
+ verify.verify_outputs(message, out, err, expected_stdout, expected_stderr)
+ verify.verify_exit_code(message, actual_exit, expected_exit)
+ return actual_exit, out, err
+
 def run_and_verify_load(repo_dir, dump_file_content):
   "Runs 'svnadmin load' and reports any errors."
   expected_stderr = []
Index: subversion/tests/cmdline/svntest/main.py
===================================================================
--- subversion/tests/cmdline/svntest/main.py (revision 29576)
+++ subversion/tests/cmdline/svntest/main.py (working copy)
@@ -304,7 +304,7 @@

   return os.path.join(repo_dir, "conf", "svnserve.conf")

-# Run any binary, logging the command line (TODO: and return code)
+# Run any binary, logging the command line and return code
 def run_command(command, error_expected, binary_mode=0, *varargs):
   """Run COMMAND with VARARGS; return stdout, stderr as lists of lines.
   If ERROR_EXPECTED is None, any stderr also will be printed."""
@@ -312,6 +312,13 @@
   return run_command_stdin(command, error_expected, binary_mode,
                            None, *varargs)

+def run_command_2(command, error_expected, binary_mode=0, *varargs):
+ """Like run_command, but returning exit code, stdout, and stderr"""
+
+ return run_command_stdin_2(command, error_expected, binary_mode,
+ None, *varargs)
+
+
 # A regular expression that matches arguments that are trivially safe
 # to pass on a command line without quoting on any supported operating
 # system:
@@ -418,6 +425,18 @@
   Return stdout, stderr as lists of lines.
   If ERROR_EXPECTED is None, any stderr also will be printed."""

+ exit_code, stdout_lines, stderr_lines = run_command_stdin_2(command,
+ error_expected,
+ binary_mode,
+ stdin_lines,
+ *varargs);
+ return stdout_lines, stderr_lines
+
+def run_command_stdin_2(command, error_expected, binary_mode=0,
+ stdin_lines=None, *varargs):
+ """Like run_command_stdin, except returing exit code as int, stdout
+ and stderr as lists of lines."""
+
   if verbose_mode:
     start = time.time()

@@ -434,7 +453,7 @@
     map(sys.stdout.write, stderr_lines)
     raise Failure

- return stdout_lines, stderr_lines
+ return exit_code, stdout_lines, stderr_lines

 def create_config_dir(cfgdir, config_contents=None, server_contents=None):
   "Create config directories and files"
@@ -493,6 +512,11 @@
   return run_command(svn_binary, error_expected, 0,
                      *(_with_auth(_with_config_dir(varargs))))

+def run_svn_2(error_expected, *varargs):
+ """Like run_svn, but also returns exit code."""
+ return run_command_2(svn_binary, error_expected, 0,
+ *(_with_auth(_with_config_dir(varargs))))
+
 # For running svnadmin. Ignores the output.
 def run_svnadmin(*varargs):
   "Run svnadmin with VARARGS, returns stdout, stderr as list of lines."
Index: subversion/tests/cmdline/svntest/verify.py
===================================================================
--- subversion/tests/cmdline/svntest/verify.py (revision 29576)
+++ subversion/tests/cmdline/svntest/verify.py (working copy)
@@ -49,6 +49,11 @@
   STDERR when output was expected."""
   pass

+class SVNUnexpectedExitCode(SVNUnexpectedOutput):
+ """Exception raised if an invocation of svn exits with a value other
+ than what was expected."""
+ pass
+
 class SVNIncorrectDatatype(SVNUnexpectedOutput):
   """Exception raised if invalid input is passed to the
   run_and_verify_* API"""
@@ -324,3 +329,13 @@
       raisable = main.SVNLineUnequal

     compare_and_display_lines(message, label, expected, actual, raisable)
+
+def verify_exit_code(message, actual, expected,
+ raisable=SVNUnexpectedExitCode):
+ """Compare and display expected vs. actual exit codes:
+ if they don't match, print the difference (preceded by MESSAGE iff
+ not None) and raise an exception."""
+
+ if expected != actual:
+ display_lines(message, "Exit Code", str(expected) + '\n',
str(actual) + '\n')
+ raise raisable

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: dev-help_at_subversion.tigris.org
Received on 2008-02-24 07:24:26 CET

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.