[PATCH 1 of 2] test-patchbomb: convert the pretendmail program from *.sh to *.py

Matt Harbison mharbison72 at gmail.com
Mon Apr 10 01:52:30 UTC 2017


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1491785368 14400
#      Sun Apr 09 20:49:28 2017 -0400
# Node ID 1de38b5ca1886aa41844dc7a80c1b92b65a8171e
# Parent  9259cf823690e4fcd34a4d2ecd57ced2060d2b3d
test-patchbomb: convert the pretendmail program from *.sh to *.py

Windows doesn't know how to execute *.sh, so tests were failing with:

  abort: 'pretendmail.py' specified as email transport, but not in PATH

I was able to create a *.bat file to do the same thing, but neither the *.py nor
*.bat were able to read from stdin[1] and write to stdout on Windows, like `cat`
was doing in the shell script.  The *.py script is infinitely more readable.

It isn't possible to specify 'method = python `pwd`/*.py', because everything
specified on the RHS ends up quoted, because of the space.  Therefore, $PATHEXT
is modified to include *.py, which causes a registry lookup and Windows to
figure out that it should open *.py with python.exe.  Unlike the python
installer, the MSYS installer doesn't add registry entries for *.sh, so it isn't
possible to execute shell scripts directly.

[1] https://stackoverflow.com/questions/6979747/read-stdin-stream-in-a-batch-file

diff --git a/tests/test-patchbomb.t b/tests/test-patchbomb.t
--- a/tests/test-patchbomb.t
+++ b/tests/test-patchbomb.t
@@ -2849,15 +2849,31 @@
 
 Set up a fake sendmail program
 
-  $ cat > pretendmail.sh << 'EOF'
-  > #!/bin/sh
-  > echo "$@"
-  > cat
+  $ cat > pretendmail.py << 'EOF'
+  > #!/usr/bin/env python
+  > 
+  > from __future__ import print_function
+  > import sys
+  > 
+  > print(sys.argv)
+  > 
+  > for line in sys.stdin:
+  >     print(line.rstrip())
+  > exit(0)
   > EOF
-  $ chmod +x pretendmail.sh
+
+Make it possible to execute *.py directly in cmd.exe for this test
+
+#if windows
+  $ export PATHEXT='.COM;.EXE;.BAT;.CMD;.PY'
+#endif
+
+#if execbit
+  $ chmod +x pretendmail.py
+#endif
 
   $ echo '[email]' >> $HGRCPATH
-  $ echo "method=`pwd`/pretendmail.sh" >> $HGRCPATH
+  $ echo "method=`pwd`/pretendmail.py" >> $HGRCPATH
 
 Test introduction configuration
 =================================
@@ -2950,7 +2966,7 @@
   
   warning: invalid patchbomb.intro value "mpmwearaclownnose"
   (should be one of always, never, auto)
-  -f test foo
+  ['$TESTTMP/t2/pretendmail.py', '-f', 'test', 'foo']
   Content-Type: text/plain; charset="us-ascii"
   MIME-Version: 1.0
   Content-Transfer-Encoding: 7bit
@@ -2982,7 +2998,7 @@
   +d
   
   sending [PATCH] test ...
-  sending mail: $TESTTMP/t2/pretendmail.sh -f test foo
+  sending mail: $TESTTMP/t2/pretendmail.py -f test foo
 
 Test pull url header
 =================================


More information about the Mercurial-devel mailing list