[PATCH v4] run-tests: try to provide a test.env file

timeless timeless at mozdev.org
Wed Mar 30 06:31:44 UTC 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1459319293 0
#      Wed Mar 30 06:28:13 2016 +0000
# Node ID a676aeec04c67f873c8940de1b870ebbbb5cc26b
# Parent  ff0d3b6b287f89594bd8d0308fe2810d2a18ea01
run-tests: try to provide a test.env file

This is a step to providing an environment file that people can use
to reproduce a failing test environment.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -739,6 +739,21 @@
             log('\nKeeping testtmp dir: %s\nKeeping threadtmp dir: %s' %
                 (self._testtmp.decode('utf-8'),
                  self._threadtmp.decode('utf-8')))
+            env = self._getenv()
+            def format(k, v):
+                """Posix environment format"""
+                return '%s="%s"\nexport %s\n' % (k, v.replace('"', r'\"'), k)
+            with open(os.path.join(self._threadtmp, b'test.env'), 'wb') as f:
+                keys = sorted(env.keys())
+                for k in keys:
+                    v = env[k].encode('utf-8').replace(b'"', b'\\"')
+                    f.write(b'%s="%s"\n' % (k.encode('utf-8'), v))
+                exports = " ".join(keys).encode('utf-8')
+                f.write(b"export %s\n" % (exports))
+                keep = "|".join(keys).encode('utf-8')
+                f.write(b"for i in $(env | sed -e 's/=.*//' |\n")
+                f.write(b"egrep -v '%s');\n " % keep)
+                f.write(b"do unset $i ; done\n")
         else:
             shutil.rmtree(self._testtmp, True)
             shutil.rmtree(self._threadtmp, True)
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
@@ -489,6 +489,19 @@
   .
   # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
 
+  $ egrep 'HGEDITOR|HGPORT|PYTHONHASHSEED|PYTHONPATH|HGPORT|DAEMON_PIDS|EMAIL|PYTHON$|PYTHON=' \
+  > keep/child1/test.env |grep -v egrep| sort
+  DAEMON_PIDS="$TESTTMP/keep/child1/daemon.pids" (glob)
+  EMAIL="Foo Bar <foo.bar at example.com>"
+  HGEDITOR="* -c \"import sys; sys.exit(0)\"" (glob)
+  HGPORT1="*" (glob)
+  HGPORT2="*" (glob)
+  HGPORT="*" (glob)
+  PYTHON="*" (glob)
+  PYTHONHASHSEED="*" (glob)
+  PYTHONPATH="*:$TESTTMP:*" (glob)
+  export *DAEMON_PIDS*EMAIL*HGEDITOR*HGPORT*HGPORT1*HGPORT2*PYTHON*PYTHONHASHSEED*PYTHONPATH* (glob)
+
 timeouts
 ========
   $ cat > test-timeout.t <<EOF


More information about the Mercurial-devel mailing list