Patchwork [v2] run-tests: try to provide a test.env file RFC

login
register
mail settings
Submitter timeless@mozdev.org
Date March 21, 2016, 10:04 p.m.
Message ID <771c3ee4bcfd8fbcb31f.1458597896@waste.org>
Download mbox | patch
Permalink /patch/14021/
State Superseded
Headers show

Comments

timeless@mozdev.org - March 21, 2016, 10:04 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1450782416 0
#      Tue Dec 22 11:06:56 2015 +0000
# Node ID 771c3ee4bcfd8fbcb31f4dbbdd94083a8a789211
# Parent  78e4e558fa74aa4489609953328cbcecf1a8a428
run-tests: try to provide a test.env file RFC

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

--
The Windows side isn't tested.
Long term, it'd be helpful if this included code or instructions
to empty the environment too...
Martijn Pieters - March 24, 2016, 3:57 p.m.
On 21 March 2016 at 15:04, timeless <timeless@mozdev.org> wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1450782416 0
> #      Tue Dec 22 11:06:56 2015 +0000
> # Node ID 771c3ee4bcfd8fbcb31f4dbbdd94083a8a789211
> # Parent  78e4e558fa74aa4489609953328cbcecf1a8a428
> run-tests: try to provide a test.env file RFC
>
> This is a step to providing an environment file that people can use
> to reproduce a failing test environment.
>
> --
> The Windows side isn't tested.
> Long term, it'd be helpful if this included code or instructions
> to empty the environment too...
>
> diff --git a/tests/run-tests.py b/tests/run-tests.py
> --- a/tests/run-tests.py
> +++ b/tests/run-tests.py
> @@ -700,6 +700,18 @@
>              log('\nKeeping testtmp dir: %s\nKeeping threadtmp dir: %s' %
>                  (self._testtmp.decode('utf-8'),
>                   self._threadtmp.decode('utf-8')))
> +            env = self._getenv()
> +            quote = re.compile('"')
> +            def format(k, v):
> +                return 'export %s="%s"\n' % (k, quote.sub('\\"', v))

Why a regular expression here? `v.replace('"', r'\"')` would be plenty
and faster.

> +            if os.name == 'nt':
> +                amp = re.compile('&')
> +                def format(k, v):
> +                    return 'set %s=%s\r\n' % (k, amp.sub('^&', v))

Ditto here; `v.replace('&', '^&')` would achieve the same result.

> +            f = open(os.path.join(self._threadtmp, 'test.env'), 'wb')
> +            for k, v in env.iteritems():
> +                f.write(format(k, v))
> +            f.close()
>          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
> @@ -465,6 +465,18 @@
>    .
>    # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
>
> +  $ egrep 'HGEDITOR|HGPORT|PYTHONHASHSEED|PYTHON|HGPORT|DAEMON_PIDS|EMAIL' \
> +  > keep/child1/test.env | sort
> +  export DAEMON_PIDS="$TESTTMP/keep/child1/daemon.pids" (glob)
> +  export EMAIL="Foo Bar <foo.bar@example.com>"
> +  export HGEDITOR="* -c \"import sys; sys.exit(0)\"" (glob)
> +  export HGPORT1="*" (glob)
> +  export HGPORT2="*" (glob)
> +  export HGPORT="*" (glob)
> +  export PYTHON="*" (glob)
> +  export PYTHONHASHSEED="*" (glob)
> +  export PYTHONPATH="*:$TESTTMP:*" (glob)
> +
>  timeouts
>  ========
>    $ cat > test-timeout.t <<EOF
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -700,6 +700,18 @@ 
             log('\nKeeping testtmp dir: %s\nKeeping threadtmp dir: %s' %
                 (self._testtmp.decode('utf-8'),
                  self._threadtmp.decode('utf-8')))
+            env = self._getenv()
+            quote = re.compile('"')
+            def format(k, v):
+                return 'export %s="%s"\n' % (k, quote.sub('\\"', v))
+            if os.name == 'nt':
+                amp = re.compile('&')
+                def format(k, v):
+                    return 'set %s=%s\r\n' % (k, amp.sub('^&', v))
+            f = open(os.path.join(self._threadtmp, 'test.env'), 'wb')
+            for k, v in env.iteritems():
+                f.write(format(k, v))
+            f.close()
         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
@@ -465,6 +465,18 @@ 
   .
   # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
 
+  $ egrep 'HGEDITOR|HGPORT|PYTHONHASHSEED|PYTHON|HGPORT|DAEMON_PIDS|EMAIL' \
+  > keep/child1/test.env | sort
+  export DAEMON_PIDS="$TESTTMP/keep/child1/daemon.pids" (glob)
+  export EMAIL="Foo Bar <foo.bar@example.com>"
+  export HGEDITOR="* -c \"import sys; sys.exit(0)\"" (glob)
+  export HGPORT1="*" (glob)
+  export HGPORT2="*" (glob)
+  export HGPORT="*" (glob)
+  export PYTHON="*" (glob)
+  export PYTHONHASHSEED="*" (glob)
+  export PYTHONPATH="*:$TESTTMP:*" (glob)
+
 timeouts
 ========
   $ cat > test-timeout.t <<EOF