[PATCH STABLE] tests: tighten checks for octal escapes in shell printf

Jim Hague jim.hague at acm.org
Wed Feb 8 10:56:25 CST 2012


# HG changeset patch
# User Jim Hague <jim.hague at acm.org>
# Date 1328720160 0
# Branch stable
# Node ID 1b507b5d0b8c2feec81c3453bcf0972eded2078d
# Parent  2e8f4b82c551014a5895b3dfc5858f2341bd7f41
tests: tighten checks for octal escapes in shell printf.

printf on AIX default shell ksh (89) says \1 is an invalid escape. It insists
on at least 2 digits. This causes failures in test-keyword.t and test-status.t.

check-code.py already looks out for \NNN and recommends using Python for outputting
octal values. Extend the check to \NN and \N and fix up resulting failures.

diff -r 2e8f4b82c551 -r 1b507b5d0b8c contrib/check-code.py
--- a/contrib/check-code.py	Mon Feb 06 21:17:50 2012 +0100
+++ b/contrib/check-code.py	Wed Feb 08 16:56:00 2012 +0000
@@ -54,7 +54,7 @@
     (r'head -c', "don't use 'head -c', use 'dd'"),
     (r'sha1sum', "don't use sha1sum, use $TESTDIR/md5sum.py"),
     (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.*\\\d{1,3}', "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"),
diff -r 2e8f4b82c551 -r 1b507b5d0b8c tests/test-diffstat.t
--- a/tests/test-diffstat.t	Mon Feb 06 21:17:50 2012 +0100
+++ b/tests/test-diffstat.t	Wed Feb 08 16:56:00 2012 +0000
@@ -35,7 +35,7 @@
 
   $ hg ci -m appenda
 
-  $ printf '\0' > c
+  >>> open("c", "wb").write("\0")
   $ touch d
   $ hg add c d
 
@@ -54,7 +54,7 @@
 
   $ hg ci -m createb
 
-  $ printf '\0' > "file with spaces"
+  >>> open("file with spaces", "wb").write("\0")
   $ hg add "file with spaces"
 
 Filename with spaces diffstat:
diff -r 2e8f4b82c551 -r 1b507b5d0b8c tests/test-keyword.t
--- a/tests/test-keyword.t	Mon Feb 06 21:17:50 2012 +0100
+++ b/tests/test-keyword.t	Wed Feb 08 16:56:00 2012 +0000
@@ -169,10 +169,10 @@
 
 hg status of kw-ignored binary file starting with '\1\n'
 
-  $ printf '\1\nfoo' > i
+  >>> open("i", "wb").write("\1\nfoo")
   $ hg -q commit -Am metasep i
   $ hg status
-  $ printf '\1\nbar' > i
+  >>> open("i", "wb").write("\1\nbar")
   $ hg status
   M i
   $ hg -q commit -m "modify metasep" i
diff -r 2e8f4b82c551 -r 1b507b5d0b8c tests/test-status.t
--- a/tests/test-status.t	Mon Feb 06 21:17:50 2012 +0100
+++ b/tests/test-status.t	Wed Feb 08 16:56:00 2012 +0000
@@ -279,12 +279,12 @@
 
   $ hg init repo5
   $ cd repo5
-  $ printf '\1\nfoo' > 010a
+  >>> open("010a", "wb").write("\1\nfoo")
   $ hg ci -q -A -m 'initial checkin'
   $ hg status -A
   C 010a
 
-  $ printf '\1\nbar' > 010a
+  >>> open("010a", "wb").write("\1\nbar")
   $ hg status -A
   M 010a
   $ hg ci -q -m 'modify 010a'
diff -r 2e8f4b82c551 -r 1b507b5d0b8c tests/test-subrepo-paths.t
--- a/tests/test-subrepo-paths.t	Mon Feb 06 21:17:50 2012 +0100
+++ b/tests/test-subrepo-paths.t	Wed Feb 08 16:56:00 2012 +0000
@@ -17,7 +17,7 @@
 hg debugsub with remapping
 
   $ echo '[subpaths]' >> .hg/hgrc
-  $ printf 'http://example.net/lib(.*) = C:\\libs\\\\1-lib\\\n' >> .hg/hgrc
+  $ printf 'http://example.net/lib(.*) = C:\\libs\\\\1-lib\\\n' >> .hg/hgrc # no-check-code
 
   $ hg debugsub
   path sub


More information about the Mercurial-devel mailing list