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

[PATCH] fix the test suite so it reports errors it finds

From: William Uther <will+_at_cs.cmu.edu>
Date: 2002-08-12 06:20:01 CEST

Hi all,

As I posted before, there was a test failing on my machine, but the
failure wasn't being detected and so the test suite was PASSing.

I've attached two patches to try and fix this. The first is more
conservative, but it doesn't fix everything I'd like. It only checks
bad stderr output.

The second detects signals and non-zero exit status. As the functions
required for this don't exist on windows, this should fall back to being
the same as the first patch on windows. I haven't tested this on
windows.

This second patch reveals an error in one of the other tests:
log_tests.py 3 fails with this patch when run a second time. The
problem is that this test tries to create a repos without checking if
one is already there and gets an error:

> svn: File exists
> svn: creating Berkeley DB environment dir `repositories/log_tests-3/db'

This wasn't detected previously. I'm working on fixing this test and
will post a patch for it soon. (The svnadmin test that I posted a patch
for earlier also fails if this patch is applied and that test isn't
fixed.)

I am very new to python, so this should be checked carefully.

later,

\x/ill :-}

    * main.py
      (SVNUnexpectedError): A new exception to be thrown when
                            a command exits abnormally.
      (run_svn): Throw SVNUnexpectedError when we get output on stdout and
                 we weren't expecting it.
      (run_one_test): Catch SVNUnexpectedError and fail in that case.

Index: ./subversion/tests/clients/cmdline/svntest/main.py
===================================================================
--- ./subversion/tests/clients/cmdline/svntest/main.py
+++ ./subversion/tests/clients/cmdline/svntest/main.py Sun Aug 11
18:48:47 2002
@@ -63,6 +63,9 @@
  # Exception raised if get_child is passed a file.
  class SVNTreeIsNotDirectory(Exception): pass

+# Exception raised if a call to svn fails when we weren't expecting it.
+class SVNUnexpectedError(Exception): pass
+

  # Windows specifics
  if sys.platform == 'win32':
@@ -213,6 +216,7 @@

    if (not error_expected) and (stderr_lines):
      map(sys.stdout.write, stderr_lines)
+ raise SVNUnexpectedError

    return stdout_lines, stderr_lines

@@ -321,6 +325,8 @@
      error = apply(func, args)
    except SVNTreeUnequal:
      print "caught an SVNTreeUnequal exception, returning error instead"
+ except SVNUnexpectedError:
+ error = 1
    except:
      print "caught unexpected exception"
      traceback.print_exc(file=sys.stdout)

-------------------- Second patch ---------------------

    * main.py
      (SVNUnexpectedError): A new exception to be thrown when
                a command exits abnormally.
      (run_svn): Throw SVNUnexpectedError when we get unexpected output
                on stderr. Same if we get a signal or an unexpected
abnormal exit.
      (run_svnadmin): Throw SVNUnexpectedError if we get a signal
                or an abnormal exit.
      (run_one_test): Catch SVNUnexpectedError and fail in that case.

Index: ./subversion/tests/clients/cmdline/svntest/main.py
===================================================================
--- ./subversion/tests/clients/cmdline/svntest/main.py
+++ ./subversion/tests/clients/cmdline/svntest/main.py Mon Aug 12
00:05:43 2002
@@ -17,7 +17,8 @@
  ######################################################################

  import sys # for argv[]
-import os # for popen2()
+import os # for popen3()
+import popen2 # for Popen3() on UNIX
  import shutil # for rmtree()
  import re # to parse version string
  import stat # for ST_MODE
@@ -63,6 +64,9 @@
  # Exception raised if get_child is passed a file.
  class SVNTreeIsNotDirectory(Exception): pass

+# Exception raised if a call to svn fails when we weren't expecting it.
+class SVNUnexpectedError(Exception): pass
+

  # Windows specifics
  if sys.platform == 'win32':
@@ -196,41 +200,67 @@
  # For running subversion and returning the output
  def run_svn(error_expected, *varargs):
    """Run svn with VARARGS; return stdout, stderr as lists of lines.
-
- If ERROR_EXPECTED is None, any stderr also will be printed. """
+ If ERROR_EXPECTED is None, any stderr also will be printed,
+ and a non-zero error code will throw a SVNUnexpectedError"""

    command = svn_binary
    for arg in varargs: # build the command string
      command = command + ' "' + str(arg) + '"'

- infile, outfile, errfile = os.popen3(command)
- stdout_lines = outfile.readlines()
- stderr_lines = errfile.readlines()
-
- outfile.close()
- infile.close()
- errfile.close()
-
+ if windows:
+ infile, outfile, errfile = os.popen3(command)
+ stdout_lines = outfile.readlines()
+ stderr_lines = errfile.readlines()
+ outfile.close()
+ infile.close()
+ errfile.close()
+ else:
+ child = popen2.Popen3(command, 1)
+ stdout_lines = child.fromchild.readlines()
+ stderr_lines = child.childerr.readlines()
+ result = child.wait();
+ if os.WIFSIGNALED(result):
+ print "svn got signal: " + str(os.WTERMSIG(result))
+ raise SVNUnexpectedError
+ if (not error_expected) and os.WIFEXITED(result) and
os.WEXITSTATUS(result):
+ map(sys.stdout.write, stderr_lines)
+ print "svn exit status: " + str(os.WEXITSTATUS(result))
+ raise SVNUnexpectedError
+
    if (not error_expected) and (stderr_lines):
      map(sys.stdout.write, stderr_lines)
+ raise SVNUnexpectedError

    return stdout_lines, stderr_lines

  # For running svnadmin. Ignores the output.
  def run_svnadmin(*varargs):
- "Run svnadmin with VARARGS, returns stdout, stderr as list of lines."
+ """Run svnadmin with VARARGS, returns stdout, stderr as list of lines.
+ Any signal or non-zero return value will throw a
SVNUnexpectedError."""

    command = svnadmin_binary
    for arg in varargs: # build the command string
      command = command + ' "' + str(arg) + '"'

- infile, outfile, errfile = os.popen3(command)
- stdout_lines = outfile.readlines()
- stderr_lines = errfile.readlines()
-
- outfile.close()
- infile.close()
- errfile.close()
+ if windows:
+ infile, outfile, errfile = os.popen3(command)
+ stdout_lines = outfile.readlines()
+ stderr_lines = errfile.readlines()
+ outfile.close()
+ infile.close()
+ errfile.close()
+ else:
+ child = popen2.Popen3(command, 1)
+ stdout_lines = child.fromchild.readlines()
+ stderr_lines = child.childerr.readlines()
+ result = child.wait();
+ if os.WIFSIGNALED(result):
+ print "svnadmin got signal: " + str(os.WTERMSIG(result))
+ raise SVNUnexpectedError
+ if os.WIFEXITED(result) and os.WEXITSTATUS(result):
+ map(sys.stdout.write, stderr_lines)
+ print "svnadmin exit status: " + str(os.WEXITSTATUS(result))
+ raise SVNUnexpectedError

    return stdout_lines, stderr_lines

@@ -321,6 +351,8 @@
      error = apply(func, args)
    except SVNTreeUnequal:
      print "caught an SVNTreeUnequal exception, returning error instead"
+ except SVNUnexpectedError:
+ error = 1
    except:
      print "caught unexpected exception"
      traceback.print_exc(file=sys.stdout)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Aug 12 06:20:55 2002

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.