Patchwork [1,of,2] run-tests: add substitution patterns for common '\' path output on Windows

login
register
mail settings
Submitter Matt Harbison
Date Dec. 17, 2017, 10:25 p.m.
Message ID <0da9bd92808476cd491f.1513549548@Envy>
Download mbox | patch
Permalink /patch/26333/
State Accepted
Headers show

Comments

Matt Harbison - Dec. 17, 2017, 10:25 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1513127473 18000
#      Tue Dec 12 20:11:13 2017 -0500
# Node ID 0da9bd92808476cd491f1fb135c53a78769a3d35
# Parent  ca9cde0697c1e923f4c9a3396343afc238ba92f2
run-tests: add substitution patterns for common '\' path output on Windows

The goal is to reduce the amount of hand tuning of new/changed tests that is
required on Windows.  Since the OS prints the proper paths everywhere else, this
is limited to Windows.  These are based on the check-code rules that were
dropped in 5feb782c7a95.

There are some minor tweaks, because those were trying to detect '/' paths
without a '(glob)' at the end, whereas these detect '\' paths. Also, it looks
like the 'no changes made to subrepo' one was broke, because the path to the
subrepo has been getting output but was not in the pattern.  End anchors are
dropped because '(glob)' is no longer required, but '(feature !)' annotations
are a possibility.

The 'saved backup bundle' pattern dropped from run-tests.py was simply carrying
over the first capture group.  The replace() method runs prior to evaluating
'\1', but it wasn't doing anything because of the 'r' prefix on '\\'.

The 'not recording move' entry is new, because I stumbled upon it searching for
some of these patterns.  There are probably others.

Patch

diff --git a/tests/common-pattern.py b/tests/common-pattern.py
--- a/tests/common-pattern.py
+++ b/tests/common-pattern.py
@@ -1,6 +1,9 @@ 
 # common patterns in test at can safely be replaced
 from __future__ import absolute_import
 
+import os
+import sys
+
 substitutions = [
     # list of possible compressions
     (br'(zstd,)?zlib,none,bzip2',
@@ -83,3 +86,55 @@ 
 
 for replace, msgs in _errors.items():
     substitutions.extend((m, replace) for m in msgs)
+
+# Output lines on Windows that can be autocorrected for '\' vs '/' path
+# differences.
+_winpathfixes = [
+    # cloning subrepo s\ss from $TESTTMP/t/s/ss
+    # cloning subrepo foo\bar from http://localhost:$HGPORT/foo/bar
+    br'(?m)^cloning subrepo \S+\\.*',
+
+    # pulling from $TESTTMP\issue1852a
+    br'(?m)^pulling from \$TESTTMP\\.*',
+
+    # pushing to $TESTTMP\a
+    br'(?m)^pushing to \$TESTTMP\\.*',
+
+    # pushing subrepo s\ss to $TESTTMP/t/s/ss
+    br'(?m)^pushing subrepo \S+\\\S+ to.*',
+
+    # moving d1\d11\a1 to d3/d11/a1
+    br'(?m)^moving \S+\\.*',
+
+    # d1\a: not recording move - dummy does not exist
+    br'\S+\\\S+: not recording move .+',
+
+    # reverting s\a
+    br'(?m)^reverting (?!subrepo ).*\\.*',
+
+    # saved backup bundle to
+    #     $TESTTMP\test\.hg\strip-backup/443431ffac4f-2fc5398a-backup.hg
+    br'(?m)^saved backup bundle to \$TESTTMP.*\.hg',
+
+    # no changes made to subrepo s\ss since last push to ../tcc/s/ss
+    br'(?m)^no changes made to subrepo \S+\\\S+ since.*',
+
+    # changeset 5:9cc5aa7204f0: stuff/maybelarge.dat references missing
+    #     $TESTTMP\largefiles-repo-hg\.hg\largefiles\76..38
+    br'(?m)^changeset .* references (corrupted|missing) \$TESTTMP\\.*',
+
+    # stuff/maybelarge.dat: largefile 76..38 not available from
+    #     file:/*/$TESTTMP\largefiles-repo (glob)
+    br'.*: largefile \S+ not available from file:/\*/.+',
+]
+
+ispy3 = (sys.version_info[0] >= 3)
+
+if ispy3:
+    osname = os.name.encode('ascii')
+else:
+    osname = os.name
+
+if osname == 'nt':
+    substitutions.extend([(s, lambda match: match.group().replace(b'\\', b'/'))
+                          for s in _winpathfixes])
diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -972,8 +972,6 @@ 
             self._portmap(0),
             self._portmap(1),
             self._portmap(2),
-            (br'(?m)^(saved backup bundle to .*\.hg)( \(glob\))?$',
-             br'\1'.replace(br'\\', br'/')),
             (br'([^0-9])%s' % re.escape(self._localip()), br'\1$LOCALIP'),
             (br'\bHG_TXNID=TXN:[a-f0-9]{40}\b', br'HG_TXNID=TXN:$ID$'),
             ]