[PATCH 05 of 10 ipv6 V2] runtests: export LOCALIP

Jun Wu quark at fb.com
Fri Feb 17 13:51:19 EST 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1487260879 28800
#      Thu Feb 16 08:01:19 2017 -0800
# Node ID 9222c925de31506ee513f58a913ddec0c3a8a9c5
# Parent  c34ad0f0fc375de9e2d96d17ddcb644d9054d154
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 9222c925de31
runtests: export LOCALIP

Previously, tests hard-code local IP address as "127.0.0.1". That won't work
for IPv6.

This patch exports the $LOCALIP environment variable, which is set to "::1"
if we decide to use IPv6.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -843,4 +843,5 @@ class Test(unittest.TestCase):
             (br'(?m)^(saved backup bundle to .*\.hg)( \(glob\))?$',
              br'\1 (glob)'),
+            (br'([^0-9])%s' % re.escape(self._localip()), br'\1$LOCALIP'),
             ]
         r.append((self._escapepath(self._testtmp), b'$TESTTMP'))
@@ -858,4 +859,10 @@ class Test(unittest.TestCase):
             return re.escape(p)
 
+    def _localip(self):
+        if self._useipv6:
+            return b'::1'
+        else:
+            return b'127.0.0.1'
+
     def _getenv(self):
         """Obtain environment variables to use during test execution."""
@@ -882,4 +889,8 @@ class Test(unittest.TestCase):
         env['HGIPV6'] = str(int(self._useipv6))
 
+        # LOCALIP could be ::1 or 127.0.0.1. Useful for tests that require raw
+        # IP addresses.
+        env['LOCALIP'] = self._localip()
+
         # Reset some environment variables to well-known values so that
         # the tests produce repeatable output.


More information about the Mercurial-devel mailing list