Submitter | timeless@mozdev.org |
---|---|
Date | March 30, 2016, 6:31 a.m. |
Message ID | <a676aeec04c67f873c89.1459319504@waste.org> |
Download | mbox | patch |
Permalink | /patch/14170/ |
State | Changes Requested |
Headers | show |
Comments
On Wed, 30 Mar 2016 01:31:44 -0500, timeless wrote: > # HG changeset patch > # User timeless <timeless@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) Unused function. > + with open(os.path.join(self._threadtmp, b'test.env'), 'wb') as f: Can you add an inline comment how this file will be used? Someone might think this is a dead code as test.env file isn't sourced by any tests. > + 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') .encode('utf-8') can fail on Python2 because str is bytes. > + 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") It will make hard to pass environment variables in addition to test.env. Rather than assming the user always want to clear environment, I would let him choose. $ env -i sh -c '. test.env; ...'
Patch
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@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