[PATCH] test-subrepo-svn: remove bashism

Matt Mackall mpm at selenic.com
Mon Jan 18 14:53:53 CST 2010


On Sun, 2010-01-17 at 01:53 +0100, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <mads at kiilerich.com>
> # Date 1263689584 -3600
> # Node ID 099546713846736599e5f7df12117dd0cb061437
> # Parent  5a6930e204a9a963a53d5eed6998149465b970df
> test-subrepo-svn: remove bashism

Here's a script I hacked up this morning you might enjoy.

diff -r 8a9651cb2836 tests/check-tests.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/check-tests.py	Mon Jan 18 14:51:20 2010 -0600
@@ -0,0 +1,51 @@
+import sys, re, glob
+
+pats = [
+    (r'(pushd|popd)', "don't use pushd|popd, use cd"),
+    (r'\W\$?\(\([^\)]*\)\)', "don't use (()) or $(()), use expr"),
+    (r'^function', "don't use 'function', use old style"),
+    (r'grep.*-q', "don't use grep -q, redirect to /dev/null"),
+    (r'echo.*\\n', "don't use 'echo \n', use printf"),
+    (r'^diff.*-\w*N', "don't use diff -N"),
+    (r'(^| )wc[^|]*$', "filter wc output"),
+    (r'head -c', "don't use head -c, use dd"),
+    (r'ls.*-\w*R', "don't use ls -R, use find"),
+    (r'printf.*\\\d\d\d', "don't use printf \NNN, use python"),
+    (r'printf.*\\x', "don't use printf \\x, use python"),
+    (r'\$\(.*\)', "don't use $(expr), use `expr`"),
+    (r'rm -rf \*', "don't use naked rm -rf, target a directory"),
+    (r'(^|\|\s*)grep (-\w\s+)*[^|]*[(|]\w',
+     "use egrep for extended grep syntax"),
+    (r'/bin/', "don't use explicit paths for tools"),
+]
+
+#cpats = [(re.compile(p), m) for p, m in pats]
+cpats = pats
+
+if len(sys.argv) == 1:
+    check = glob.glob("test-*")
+else:
+    check = sys.argv[1:]
+
+def checkpat(f, line, num, pat, msg):
+    m = re.search(pat, line)
+    if m:
+        print "%s:%d:" % (f, num)
+        print " > %s" % line[:-1]
+        print " %s" % msg
+
+for f in check:
+    if f.endswith(".out") or f.endswith(".err") or f.endswith("~"):
+        continue
+    if f.endswith(".py"):
+        continue
+    if f.endswith(".bat"):
+        continue
+    if f.endswith(".hg"):
+        continue
+
+    for n, l in enumerate(open(f)):
+        if re.match("\s*#", l):
+            continue
+        for p, msg in cpats:
+            checkpat(f, l, n, p, msg)


-- 
http://selenic.com : development and support for Mercurial and Linux




More information about the Mercurial-devel mailing list