[PATCH] run-tests: add --rev to run tests with specific version of hg

timeless timeless at mozdev.org
Thu Apr 7 02:54:07 UTC 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1459995887 0
#      Thu Apr 07 02:24:47 2016 +0000
# Node ID c95967671da37d6669e7ef786f471bf727d78592
# Parent  ea86cdcd9b50bf38c6b9dd7bbaa04b9c8cc0aefb
run-tests: add --rev to run tests with specific version of hg

This is mostly designed for use outside of hg.

Keep in mind that unless you specify a path inside $TESTTMP, your tests
will almost certainly fail.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -263,6 +263,9 @@
     parser.add_option("--with-python3", metavar="PYTHON3",
                       help="Python 3 interpreter (if running under Python 2)"
                            " (TEMPORARY)")
+    parser.add_option('--rev', type="string",
+                      metavar="rev",
+                      help="run tests using the given revision")
     parser.add_option('--extra-config-opt', action="append",
                       help='set the given config opt in the test hgrc')
     parser.add_option('--random', action="store_true",
@@ -294,12 +297,16 @@
 
     if options.with_hg:
         options.with_hg = canonpath(_bytespath(options.with_hg))
+        if options.rev:
+            parser.error('--with-hg and --rev are incompatible')
         if not (os.path.isfile(options.with_hg) and
                 os.access(options.with_hg, os.X_OK)):
             parser.error('--with-hg must specify an executable hg script')
         if not os.path.basename(options.with_hg) == b'hg':
             sys.stderr.write('warning: --with-hg should specify an hg script\n')
     if options.local:
+        if options.rev:
+            parser.error('--local and --rev are incompatible')
         testdir = os.path.dirname(_bytespath(canonpath(sys.argv[0])))
         hgbin = os.path.join(os.path.dirname(testdir), b'hg')
         if os.name != 'nt' and not os.access(hgbin, os.X_OK):
@@ -2330,6 +2337,25 @@
             script = _bytespath(script)
             exe = _bytespath(exe)
         hgroot = os.path.dirname(os.path.dirname(script))
+        if self.options.rev:
+            tempsrc = os.path.join(self._hgtmp, b"source")
+            proc = subprocess.Popen(['hg', 'archive',
+                                     '-R', hgroot,
+                                     '--rev', self.options.rev,
+                                     tempsrc,
+                                    ],
+                                    stderr=subprocess.STDOUT,
+                                    stdout=subprocess.PIPE)
+            proc.wait()
+            out, _err = proc.communicate()
+            out = b"hg archive failed:\n" + out
+            if proc.returncode != 0:
+                if PYTHON3:
+                    sys.stdout.buffer.write(out)
+                else:
+                    sys.stdout.write(out)
+                sys.exit(1)
+            hgroot = tempsrc
         self._hgroot = hgroot
         os.chdir(hgroot)
         nohome = b'--home=""'
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
@@ -815,3 +815,32 @@
   # Ran 1 tests, 0 skipped, 0 warned, 1 failed.
   python hash seed: * (glob)
   [1]
+
+support for running a different version of mercurial
+note that it is typical for ~1/5 tests not to pass when using older
+versions of mercurial...
+
+  $ cat >> test-version.t <<EOF
+  >   $ hg version
+  >   Mercurial Distributed SCM (version unknown)
+  >   
+  >   Copyright (C) 2005-2008 Matt Mackall <mpm at selenic.com> and others
+  >   This is free software; see the source for copying conditions. There is NO
+  >   warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  > EOF
+  $ run-tests.py --pure --rev 1.2 test-version.t
+  .
+  # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
+
+To run tests at a version from the revision you select from --rev
+you need a test which introspects the source directory
+
+  $ cat > test-old-basic.t <<EOF
+  >   $ run-tests.py --pure --local ../../source/tests/test-basic.t
+  >   .
+  >   # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
+  > EOF
+  $ run-tests.py --pure --rev 1.7 test-old-basic.t
+  .
+  # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
+


More information about the Mercurial-devel mailing list