check-code: add a rule against a GNU sed-ism stable
authorKevin Bullock <kbullock@ringworld.org>
Mon, 22 Apr 2013 16:33:28 -0500
branchstable
changeset 19080 5e4491c114b2
parent 19079 1e433b5457fd
child 19081 e97ce4a5afc5
check-code: add a rule against a GNU sed-ism BSD sed requires the 'i' command to be followed with a backslash and a newline, like so: $ sed -e '/^@/i\ > other' We've encountered this problem before, e.g. in test-mq.t (900767dfa80d). This change adds a check-code rule and fixes two instances of the problem in test-record.t.
contrib/check-code.py
tests/test-record.t
--- a/contrib/check-code.py	Mon Apr 22 12:27:56 2013 +0400
+++ b/contrib/check-code.py	Mon Apr 22 16:33:28 2013 -0500
@@ -74,6 +74,8 @@
     (r'/dev/u?random', "don't use entropy, use /dev/zero"),
     (r'do\s*true;\s*done', "don't use true as loop body, use sleep 0"),
     (r'^( *)\t', "don't use tabs to indent"),
+    (r'sed .*\'/[^/]*/i[^\\][^\n]',
+     "put a backslash-escaped newline after sed 'i' command"),
   ],
   # warnings
   [
--- a/tests/test-record.t	Mon Apr 22 12:27:56 2013 +0400
+++ b/tests/test-record.t	Mon Apr 22 16:33:28 2013 -0500
@@ -1039,7 +1039,8 @@
 Editing patch (and ignoring trailing text)
 
   $ cat > editor.sh << '__EOF__'
-  > sed -e 7d -e '5s/^-/ /' -e '/^# ---/itrailing\nditto' "$1" > tmp
+  > sed -e 7d -e '5s/^-/ /' -e '/^# ---/i\
+  > trailing\nditto' "$1" > tmp
   > mv tmp "$1"
   > __EOF__
   $ cat > editedfile << '__EOF__'
@@ -1204,7 +1205,8 @@
 random text in random positions is still an error
 
   $ cat > editor.sh << '__EOF__'
-  > sed -e '/^@/iother' "$1" > tmp
+  > sed -e '/^@/i\
+  > other' "$1" > tmp
   > mv tmp "$1"
   > __EOF__
   $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg record <<EOF