subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From julianf...@apache.org
Subject svn commit: r1833123 - in /subversion/trunk/subversion/tests/cmdline: move_tests.py prop_tests.py svnadmin_tests.py svnmover_tests.py svnmucc_tests.py svntest/verify.py
Date Thu, 07 Jun 2018 13:26:02 GMT
Author: julianfoad
Date: Thu Jun  7 13:26:01 2018
New Revision: 1833123

URL: http://svn.apache.org/viewvc?rev=1833123&view=rev
Log:
In the test suite, make some expected output checking more robust.

Require that the regexes in RegexListOutput and UnorderedRegexListOutput
classes match a whole actual line, not just a prefix.

Adjust the few callers that were not already expecting to match a whole
line.

This patch does not yet do the same for RegexOutput. Many callers assume
the regex in that class matches a prefix.

* subversion/tests/cmdline/move_tests.py,
  subversion/tests/cmdline/prop_tests.py,
  subversion/tests/cmdline/svnadmin_tests.py,
  subversion/tests/cmdline/svnmover_tests.py,
  subversion/tests/cmdline/svnmucc_tests.py
    Append '.*' or other suitable ending to patterns that lacked it.

* subversion/tests/cmdline/svntest/verify.py
  (re_fullmatch,
   regex_fullmatch): New.
  (RegexListOutput,
   UnorderedRegexListOutput): Use them to match the whole line, not just a
    prefix. When printing differences, print the expected regex and actual
    text in such a way that control characters and trailing spaces can be
    seen.

Modified:
    subversion/trunk/subversion/tests/cmdline/move_tests.py
    subversion/trunk/subversion/tests/cmdline/prop_tests.py
    subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py
    subversion/trunk/subversion/tests/cmdline/svnmover_tests.py
    subversion/trunk/subversion/tests/cmdline/svnmucc_tests.py
    subversion/trunk/subversion/tests/cmdline/svntest/verify.py

Modified: subversion/trunk/subversion/tests/cmdline/move_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/move_tests.py?rev=1833123&r1=1833122&r2=1833123&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/move_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/move_tests.py Thu Jun  7 13:26:01 2018
@@ -1261,7 +1261,7 @@ def nested_replaces(sbox):
     '   D /A/B/C/Y',
   ]))
   expected_output = svntest.verify.UnorderedRegexListOutput(escaped
-                    + [ '^-', '^r2', '^-', '^Changed paths:', ])
+                    + [ '^--*', '^r2.*', '^--*', '^Changed paths:', ])
   svntest.actions.run_and_verify_svn(expected_output, [],
                                      'log', '-qvr2', repo_url)
 

Modified: subversion/trunk/subversion/tests/cmdline/prop_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/prop_tests.py?rev=1833123&r1=1833122&r2=1833123&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/prop_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/prop_tests.py Thu Jun  7 13:26:01 2018
@@ -1768,7 +1768,7 @@ def rm_of_replaced_file(sbox):
                                                    'proplist', '-v',
                                                    mu_path + '@base')
   expected_output = svntest.verify.UnorderedRegexListOutput([
-      'Properties on',
+      'Properties on.*',
       '  yellow',
       '    submarine',
       '  orange',

Modified: subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py?rev=1833123&r1=1833122&r2=1833123&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py Thu Jun  7 13:26:01 2018
@@ -1633,9 +1633,9 @@ text
   sbox.build(empty=True)
 
   # Try to load the dumpstream, expecting a failure (because of mixed EOLs).
-  exp_err = svntest.verify.RegexListOutput(['svnadmin: E125005',
-                                            'svnadmin: E125005',
-                                            'svnadmin: E125017'],
+  exp_err = svntest.verify.RegexListOutput(['svnadmin: E125005:.*',
+                                            'svnadmin: E125005:.*',
+                                            'svnadmin: E125017:.*'],
                                            match_all=False)
   load_and_verify_dumpstream(sbox, [], exp_err, dumpfile_revisions,
                              False, dump_str, '--ignore-uuid')
@@ -1764,10 +1764,10 @@ def test_lslocks_and_rmlocks(sbox):
   def expected_output_list(path):
     return [
       "Path: " + path,
-      "UUID Token: opaquelocktoken",
+      "UUID Token: opaquelocktoken:.*",
       "Owner: jrandom",
-      "Created:",
-      "Expires:",
+      "Created:.*",
+      "Expires:.*",
       "Comment \(1 line\):",
       "Locking files",
       "\n", # empty line
@@ -2169,7 +2169,7 @@ def verify_keep_going(sbox):
                                                         sbox.repo_dir)
 
   if (svntest.main.is_fs_log_addressing()):
-    exp_out = svntest.verify.RegexListOutput([".*Verifying metadata at revision 0"])
+    exp_out = svntest.verify.RegexListOutput([".*Verifying metadata at revision 0.*"])
   else:
     exp_out = svntest.verify.RegexListOutput([".*Verified revision 0.",
                                               ".*Verified revision 1."])

Modified: subversion/trunk/subversion/tests/cmdline/svnmover_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svnmover_tests.py?rev=1833123&r1=1833122&r2=1833123&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svnmover_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svnmover_tests.py Thu Jun  7 13:26:01 2018
@@ -469,7 +469,7 @@ rm A/B/C/Y
     '   D /top0/A/B/C/Y',
   ]))
   expected_output = svntest.verify.UnorderedRegexListOutput(escaped
-                          + ['^-', '^r2', '^-', '^Changed paths:',])
+                          + ['^--*', '^r2.*', '^--*', '^Changed paths:',])
   svntest.actions.run_and_verify_svn(expected_output, [],
                                      'log', '-qvr2', repo_url)
 
@@ -755,7 +755,7 @@ def simple_moves_within_a_branch(sbox):
                 'mv lib/foo/y2 y2')
   # move and rename, dir with children
   test_svnmover2(sbox, '/trunk',
-                 reported_br_diff('') +
+                 reported_br_diff('trunk') +
                  reported_add('subdir') +
                  reported_move('lib', 'subdir/lib2'),
                 'mkdir subdir',
@@ -765,7 +765,7 @@ def simple_moves_within_a_branch(sbox):
   # moves and renames together
   # (put it all back to how it was, in one commit)
   test_svnmover2(sbox, '/trunk',
-                 reported_br_diff('') +
+                 reported_br_diff('trunk') +
                  reported_move('subdir/lib2/README.txt', 'README') +
                  reported_move('subdir/lib2', 'lib') +
                  reported_move('y2', 'lib/foo/y') +

Modified: subversion/trunk/subversion/tests/cmdline/svnmucc_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svnmucc_tests.py?rev=1833123&r1=1833122&r2=1833123&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svnmucc_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svnmucc_tests.py Thu Jun  7 13:26:01 2018
@@ -458,7 +458,7 @@ rm A/B/C/Y
     '   D /A/B/C/Y',
   ]))
   expected_output = svntest.verify.UnorderedRegexListOutput(excaped
-                    + ['^-', '^r3', '^-', '^Changed paths:',])
+                    + ['^--*', '^r3.*', '^--*', '^Changed paths:',])
   svntest.actions.run_and_verify_svn(expected_output, [],
                                      'log', '-qvr3', repo_url)
 

Modified: subversion/trunk/subversion/tests/cmdline/svntest/verify.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svntest/verify.py?rev=1833123&r1=1833122&r2=1833123&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svntest/verify.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svntest/verify.py Thu Jun  7 13:26:01 2018
@@ -181,12 +181,36 @@ class AnyOutput(ExpectedOutput):
       logger.warn(message)
 
 
+def re_fullmatch(pattern, string, flags=0):
+  """If the whole STRING matches the regular expression PATTERN,
+     return a corresponding match object.
+     Based on re.fullmatch() in Python 3.4.
+  """
+  if pattern.endswith('$'):
+    return re.match(pattern, string, flags)
+
+  return re.match(pattern + '$', string, flags)
+
+def regex_fullmatch(rx, string):
+  """If the whole STRING matches the compiled regular expression RX,
+     return a corresponding match object.
+     Based on regex.fullmatch() in Python 3.4.
+  """
+  if rx.pattern.endswith('$'):
+    return rx.match(string)
+
+  return re_fullmatch(rx.pattern, string, rx.flags)
+
 class RegexOutput(ExpectedOutput):
   """Matches a single regular expression.
 
      If MATCH_ALL is true, every actual line must match the RE.  If
      MATCH_ALL is false, at least one actual line must match the RE.  In
      any case, there must be at least one line of actual output.
+
+     The RE must match a prefix of the actual line, in contrast to the
+     RegexListOutput and UnorderedRegexListOutput classes which match
+     whole lines.
   """
 
   def __init__(self, expected, match_all=True):
@@ -228,6 +252,9 @@ class RegexListOutput(ExpectedOutput):
      ones.
 
      In any case, there must be at least one line of actual output.
+
+     The REs must match whole actual lines, in contrast to the RegexOutput
+     class which matches a prefix of the actual line.
   """
 
   def __init__(self, expected, match_all=True):
@@ -243,11 +270,11 @@ class RegexListOutput(ExpectedOutput):
 
     if self.match_all:
       return (len(self.expected_res) == len(actual) and
-              all(e.match(a) for e, a in zip(self.expected_res, actual)))
+              all(regex_fullmatch(e, a) for e, a in zip(self.expected_res, actual)))
 
     i_expected = 0
     for actual_line in actual:
-      if self.expected_res[i_expected].match(actual_line):
+      if regex_fullmatch(self.expected_res[i_expected], actual_line):
         i_expected += 1
         if i_expected == len(self.expected_res):
           return True
@@ -266,13 +293,13 @@ class RegexListOutput(ExpectedOutput):
         logger.warn('# Expected %d lines; actual %d lines' %
                     (len(self.expected), len(actual)))
       for e, a in map(None, self.expected_res, actual):
-        if e is not None and a is not None and e.match(a):
+        if e is not None and a is not None and regex_fullmatch(e, a):
           logger.warn("|  " + a.rstrip())
         else:
           if e is not None:
-            logger.warn("| -" + e.pattern.rstrip())
+            logger.warn("| -" + repr(e.pattern))
           if a is not None:
-            logger.warn("| +" + a.rstrip())
+            logger.warn("| +" + repr(a))
 
   def insert(self, index, line):
     self.expected.insert(index, line)
@@ -313,6 +340,9 @@ class UnorderedRegexListOutput(ExpectedO
      expressions.  The implementation matches each expression in turn to
      the first unmatched actual line that it can match, and does not try
      all the permutations when there are multiple possible matches.
+
+     The REs must match whole actual lines, in contrast to the RegexOutput
+     class which matches a prefix of the actual line.
   """
 
   def __init__(self, expected):
@@ -332,7 +362,7 @@ class UnorderedRegexListOutput(ExpectedO
     for e in self.expected:
       expect_re = re.compile(e)
       for actual_line in actual:
-        if expect_re.match(actual_line):
+        if regex_fullmatch(expect_re, actual_line):
           actual.remove(actual_line)
           break
       else:
@@ -358,7 +388,7 @@ class UnorderedRegexListOutput(ExpectedO
     for e in self.expected:
       expect_re = re.compile(e)
       for actual_line in actual:
-        if expect_re.match(actual_line):
+        if regex_fullmatch(expect_re, actual_line):
           actual.remove(actual_line)
           break
       else:



Mime
View raw message