Hi,
Just while writing test cases for the svnadmin verify --keep-going
feature I realized that we do not support regex in the EXPECTED ERR list
and felt that it would be really helpful if we supported. So I came up
with this patch.
This patch would support regex in the entries of the EXPECTED ERR list.
Example:
------------
Expected err = ["* Verified revision 1.",
"* Error verifying revision 2.",
".*svnadmin: E160004*",
"* Verified revision 3.",
".*svnadmin: E165005*"]
Actual err = ["* Verified revision 1.",
"* Error verifying revision 2.",
"svnadmin: E160004: Invalid change kind in rev file",
"* Verified revision 3.",
"svnadmin: E165005: Repository
'svn-test-work/repositories/svnadmin_tests-32' failed to verify"]
The above Expected err and Actual err would match successfully.
Earlier, only *exact* entries in the list were checked for match and hence
the above example wouldnt match successfully.
But here, the entry in the EXPECTED ERR list is expected to start with
".*" to treat that particular list entry as regex. I could not think of
an easier/simpler way to solve this. Please share your thoughts.
Attaching the log message and the patch with this mail.
Thanks and regards
Prabhu
Support regex in the expected error list. In addition to directly matching the
entries of the expected error list with the actual error, support regex
in the entries of the expected error list.
* tests/cmdline/svntest/verify.py
(ExpectedOutput): Match the corresponding entries of the EXPECTED list to
that of the ACTUAL list. If the entry in the EXPECTED starts with ".*" then
treat it as regex and match the entry with the corresponding entry in ACTUAL
list.
Example:
--------
Expected err = ["* Verified revision 1.",
"* Error verifying revision 2.",
".*svnadmin: E160004*",
"* Verified revision 3.",
".*svnadmin: E165005*"]
Actual err = ["* Verified revision 1.",
"* Error verifying revision 2.",
"svnadmin: E160004: Invalid change kind in rev file",
"* Verified revision 3.",
"svnadmin: E165005: Repository 'svn-test-work/repositories/svnadmin_tests-32' failed to verify"]
The above Expected err and Actual err would match successfully.
Earlier, only *exact* entries in the list were checked for match and hence
the above example wouldnt match successfully.
Index: tests/cmdline/svntest/verify.py
===================================================================
--- tests/cmdline/svntest/verify.py (revision 1427745)
+++ tests/cmdline/svntest/verify.py (working copy)
@@ -166,16 +166,20 @@ class ExpectedOutput:
"Return whether EXPECTED and ACTUAL are equivalent."
if not self.is_regex:
if self.match_all:
- # The EXPECTED lines must match the ACTUAL lines, one-to-one, in
- # the same order.
- return expected == actual
+ if not actual:
+ return True
# The EXPECTED lines must match a subset of the ACTUAL lines,
# one-to-one, in the same order, with zero or more other ACTUAL
# lines interspersed among the matching ACTUAL lines.
i_expected = 0
for actual_line in actual:
- if expected[i_expected] == actual_line:
+ # As soon an actual_line matches something, then we're good.
+ # Also check if the regex in the EXPECTED line matches the
+ # corresponding ACTUAL line.
+ if ((expected[i_expected] == actual_line) or
+ (expected[i_expected].startswith(".*") and
+ re.match(expected[i_expected], actual_line))):
i_expected += 1
if i_expected == len(expected):
return True