[PATCH 1 of 6 V2] run-tests: allow to register any arbitrary pattern for replacement

Boris Feld boris.feld at octobus.net
Mon Nov 13 06:11:15 EST 2017


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1509860067 -3600
#      Sun Nov 05 06:34:27 2017 +0100
# Node ID a7d1303d69b73deac107d78ed37506f662ec661b
# Parent  5d4369079c861d8fb01ab4505bf7d5911cf7a6e1
# EXP-Topic better-substitute
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r a7d1303d69b7
run-tests: allow to register any arbitrary pattern for replacement

We add a 'common-pattern.py' file that allow to define extra pattern. This seems
a cleaner approach than editing the 'run-test.py' file over and over. In
addition allowing arbitrary pattern registration will also help extension.

The format used is a python file is picked out of convenience defining a list of
tuple in 'substitutions' variable. This is picked out of convenience since it is
dead simple to implement.

The end goal is to register more pattern for Mercurial test. There are multiple
common patterns that change over time. That impact is annoying. Using pattern
emplacement for them would be handy.

The next patches will define all the needed patterns and the last patch will
mass-update the tests outputs as it was easier to do in a single pass.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -968,6 +968,13 @@ class Test(unittest.TestCase):
             ]
         r.append((self._escapepath(self._testtmp), b'$TESTTMP'))
 
+        testdir = os.path.dirname(self.path)
+        replacementfile = os.path.join(testdir, 'common-pattern.py')
+
+        if os.path.exists(replacementfile):
+            data = {}
+            execfile(replacementfile, data)
+            r.extend(data.get('substitutions', ()))
         return r
 
     def _escapepath(self, p):
diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t
--- a/tests/test-run-tests.t
+++ b/tests/test-run-tests.t
@@ -1503,3 +1503,43 @@ Test cases in .t files
   # Ran 2 tests, 0 skipped, 1 failed.
   python hash seed: * (glob)
   [1]
+
+Test automatic pattern replacement
+
+  $ cat << EOF >> common-pattern.py
+  > substitutions = [
+  >     (br'foo-(.*)\\b',
+  >      br'\$XXX=\\1\$'),
+  >     (br'bar\\n',
+  >      br'\$YYY$\\n'),
+  > ]
+  > EOF
+
+  $ cat << EOF >> test-substitution.t
+  >   $ echo foo-12
+  >   \$XXX=12$
+  >   $ echo foo-42
+  >   \$XXX=42$
+  >   $ echo bar prior
+  >   bar prior
+  >   $ echo lastbar
+  >   last\$YYY$
+  >   $ echo foo-bar foo-baz
+  > EOF
+
+  $ rt test-substitution.t
+  
+  --- $TESTTMP/anothertests/cases/test-substitution.t
+  +++ $TESTTMP/anothertests/cases/test-substitution.t.err
+  @@ -7,3 +7,4 @@
+     $ echo lastbar
+     last$YYY$
+     $ echo foo-bar foo-baz
+  +  $XXX=bar foo-baz$
+  
+  ERROR: test-substitution.t output changed
+  !
+  Failed test-substitution.t: output changed
+  # Ran 1 tests, 0 skipped, 1 failed.
+  python hash seed: * (glob)
+  [1]


More information about the Mercurial-devel mailing list