[PATCH] test-tests: Add test to guarantee portability of other unit tests

Marti Raudsepp marti at juffo.org
Mon Jan 25 15:34:28 CST 2010


Here's a test case to check other test scripts for bashisms and other
portability problems. This can save us from making the same mistakes
over and over again, without needing to involve humans.

Some tests that might be useful would trigger false positives. I also
considered making a test for this:
http://www.selenic.com/pipermail/mercurial-devel/2009-October/016162.html
But "grep ' ((.*))' test-*" also flags Python code in
test-convert-hg-source

*.out files, and the 'test-tests' script itself should probably be
excluded from these checks, but I couldn't think of a reliable way to do
it in shell. I had to implement some hacks to prevent the script from
flagging itself -- like '$''PWD'

Also, even though Jim Hague in commit a19d2993385d claims that on AIX
printf doesn't support \NNN escapes, I found that test-diffstat still
passes with 'printf \0'. I asked someone in ##aix to confirm this
problem, but they said that a \141 escape works, with /bin/sh and ksh,
in AIX 5.3 and 6.1... So I added a special case for ignoring printf '\0'

Now, what's next... Creating a unit test to verify test-tests? :)

----

# HG changeset patch
# User Marti Raudsepp <marti at juffo.org>
# Date 1264453525 -7200
# Branch stable
# Node ID b73aa81f921cfcf255089ce80a62d998bd099049
# Parent  1c4ab236ebcbb2602a3e77c32796a29db2a227c4
test-tests: Add test to guarantee portability of other unit tests

diff --git a/tests/test-tests b/tests/test-tests
new file mode 100755
--- /dev/null
+++ b/tests/test-tests
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# Test the quality and portability of other unit test scripts
+
+# echo switches are not supported by many shells
+# http://www.selenic.com/pipermail/mercurial-devel/2009-November/016426.html
+echo '% tests should avoid echo flags'
+grep 'echo -[Een]' $TESTDIR/test-*
+
+# Solaris 'sh' doesn't define PWD in environment, tests should use `pwd`
+# http://www.selenic.com/pipermail/mercurial-devel/2010-January/018135.html
+echo '% tests should use `pwd` instead of PWD'
+grep '$''PWD' $TESTDIR/test-*
+
+# Allegedly AIX shell printf does not support \NNN or \xNN character escapes
+# http://www.selenic.com/pipermail/mercurial-devel/2010-January/017933.html
+# but "print '\0'" works??
+echo '% tests should not use printf escapes'
+egrep 'printf .*\\[x1-9][0-9]' $TESTDIR/test-*
+
+# Some shells don't handle 'export FOO=bar'
+# see commits 1f0f01bc86a5 and 95046688f80f
+echo "% tests should avoid 'export FOO=bar'"
+egrep '^export [A-Za-z0-9]+=' $TESTDIR/test-*
+
+true
diff --git a/tests/test-tests.out b/tests/test-tests.out
new file mode 100644
--- /dev/null
+++ b/tests/test-tests.out
@@ -0,0 +1,4 @@
+% tests should avoid echo flags
+% tests should use `pwd` instead of PWD
+% tests should not use printf escapes
+% tests should avoid 'export FOO=bar'




More information about the Mercurial-devel mailing list