You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ju...@apache.org on 2011/12/19 14:41:42 UTC

svn commit: r1220740 - in /subversion/trunk/subversion/tests/cmdline: diff_tests.py log_tests.py

Author: julianfoad
Date: Mon Dec 19 13:41:41 2011
New Revision: 1220740

URL: http://svn.apache.org/viewvc?rev=1220740&view=rev
Log:
Expand a test 'svn log --diff' to actually test the diff rather than just
checking that some kind of diff appears. The test was added in r1210147 to
test a fix for handling a copied file, and the test was sufficient on trunk
because the failure mode was a total failure, but I found that on the 1.7.x
branch the failure mode was to produce an incorrect diff.

* subversion/tests/cmdline/diff_tests.py
  (make_no_diff_deleted_header): New function.

* subversion/tests/cmdline/log_tests.py
  (parse_log_output): Support parsing diffs from the log output.
  (log_diff): In the part of the test where the log includes a copied file,
    test for the correct content of diffs in the log output.

Modified:
    subversion/trunk/subversion/tests/cmdline/diff_tests.py
    subversion/trunk/subversion/tests/cmdline/log_tests.py

Modified: subversion/trunk/subversion/tests/cmdline/diff_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/diff_tests.py?rev=1220740&r1=1220739&r2=1220740&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/diff_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/diff_tests.py Mon Dec 19 13:41:41 2011
@@ -57,6 +57,16 @@ def make_diff_header(path, old_tag, new_
     "+++ " + path_as_shown + "\t(" + new_tag + ")\n",
     ]
 
+def make_no_diff_deleted_header(path, old_tag, new_tag):
+  """Generate the expected diff header for a deleted file PATH when in
+  'no-diff-deleted' mode. (In that mode, no further details appear after the
+  header.) Return the header as an array of newline-terminated strings."""
+  path_as_shown = path.replace('\\', '/')
+  return [
+    "Index: " + path_as_shown + " (deleted)\n",
+    "===================================================================\n",
+    ]
+
 def make_git_diff_header(target_path, repos_relpath,
                          old_tag, new_tag, add=False, src_label=None,
                          dst_label=None, delete=False, text_changes=True,

Modified: subversion/trunk/subversion/tests/cmdline/log_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/log_tests.py?rev=1220740&r1=1220739&r2=1220740&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/log_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/log_tests.py Mon Dec 19 13:41:41 2011
@@ -34,6 +34,7 @@ from svntest import wc
 from svntest.main import server_has_mergeinfo
 from svntest.main import SVN_PROP_MERGEINFO
 from merge_tests import set_up_branch
+from diff_tests import make_diff_header, make_no_diff_deleted_header
 
 # (abbreviation)
 Skip = svntest.testcase.Skip_deco
@@ -424,7 +425,7 @@ class SVNLogParseError(Exception):
   pass
 
 
-def parse_log_output(log_lines):
+def parse_log_output(log_lines, with_diffs=False):
   """Return a log chain derived from LOG_LINES.
   A log chain is a list of hashes; each hash represents one log
   message, in the order it appears in LOG_LINES (the first log
@@ -438,6 +439,7 @@ def parse_log_output(log_lines):
      'date'     ===>  string
      'msg'      ===>  string  (the log message itself)
      'lines'    ===>  number  (so that it may be checked against rev)
+
   If LOG_LINES contains changed-path information, then the hash
   also contains
 
@@ -451,7 +453,11 @@ def parse_log_output(log_lines):
 
      'reverse_merges'   ===> list of reverse-merging revisions that resulted
   in this log being part of the list of messages.
-     """
+
+  If LOG_LINES contains diffs and WITH_DIFFS=True, then the hash also contains
+
+     'diff_lines'  ===> list of strings  (diffs)
+  """
 
   # Here's some log output to look at while writing this function:
 
@@ -566,6 +572,20 @@ def parse_log_output(log_lines):
       for line in log_lines[0:lines]:
         msg += line
       del log_lines[0:lines]
+
+      # Maybe accumulate a diff.
+      # If there is a diff, there is a blank line before and after it.
+      if with_diffs and len(log_lines) >= 2 and log_lines[0] == '\n':
+        log_lines.pop(0)
+        diff_lines = []
+        while len(log_lines) and log_lines[0] != msg_separator:
+          diff_lines.append(log_lines.pop(0))
+        if diff_lines[-1] == '\n':
+          diff_lines.pop()
+        else:
+          raise SVNLogParseError("no blank line after diff in log")
+        this_item['diff_lines'] = diff_lines
+
     elif this_line == msg_separator:
       if this_item:
         this_item['msg'] = msg
@@ -2125,11 +2145,25 @@ def log_diff(sbox):
                                                               '-r10:8', 'A2')
   os.chdir(was_cwd)
 
-  for line in output:
-    if line.startswith('Index:'):
-      break
-  else:
-    raise SVNLogParseError("no diffs found in log output")
+  r9diff = make_no_diff_deleted_header('A2/B/E/alpha', 8, 9) \
+           + make_diff_header('A2/B/E/beta', 'revision 8', 'revision 9') \
+           + [ "@@ -1 +1,2 @@\n",
+               " This is the file 'beta'.\n",
+               "+9\n",
+               "\ No newline at end of file\n",
+             ]
+  r8diff = make_diff_header('A2/D/G/rho', 'revision 0', 'revision 8') \
+           + [ "@@ -0,0 +1 @@\n",
+               "+8\n",
+               "\ No newline at end of file\n",
+             ]
+  log_chain = parse_log_output(output, with_diffs=True)
+  if len(log_chain) != 3:
+    raise SVNLogParseError("%d logs found, 3 expected" % len(log_chain))
+  svntest.verify.compare_and_display_lines(None, "diff for r9",
+                                           r9diff, log_chain[1]['diff_lines'])
+  svntest.verify.compare_and_display_lines(None, "diff for r8",
+                                           r8diff, log_chain[2]['diff_lines'])
 
 
 ########################################################################