lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] [PATCH] Make test_coding_rules_test.sh a bash script


From: Greg Chicares
Subject: Re: [lmi] [PATCH] Make test_coding_rules_test.sh a bash script
Date: Fri, 15 Jul 2016 23:16:00 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.8.0

On 2016-07-15 21:41, Vadim Zeitlin wrote:

[...dash doesn't do ANSI-C quoting here:
  boilerplate="$good_copyright"$'\n'"$good_url"
so you suggested changing the hashbang from 'sh' to 'bash']

>  However these extra two characters make all the difference because without
> them the test fails under Debian, where /bin/sh is dash and doesn't
> understand the $'\n' syntax used in this file, unlike bash.
> 
>  FWIW I think that maybe avoiding this syntax in the first place could be
> even better as there doesn't seem to be any reason to rely on it (even
> though it has been recently standardized as part of SUS, apparently, and so
> is not really ksh93/bash-specific any more), but for now I'd be glad if
> just the change above could be applied.

I'd rather fix the problem by making the script work with dash.

Is the '$' even necessary? If I eliminate it, that line seems
to work correctly in dash:

/home/greg[0]$cat /etc/debian_version
7.10
/home/greg[0]$dash
$ echo "good_copyright"'\n'"good_url"
good_copyright
good_url

However, that can't be the solution, because if I remove the '$'
and run the script (using cygwin, which I guess means bash in
posix mode), then the outcome is different. For example, this:

cat >eraseme_000 <<EOF
$boilerplate
EOF

produces this:

$cat eraseme_000

...Copyright (C)...2016...\n...http://savannah.nongnu.org/projects/lmi...


which is a single line with slash-en instead of newline.

If you see no trivial way to make this work portably, then would
you please tell me whether the patch that follows makes it work
correctly with debian? (This patch works with cygwin, but I
regrettably haven't yet moved development to debian.)

diff --git a/test_coding_rules_test.sh b/test_coding_rules_test.sh
index fc3d445..af078de 100755
--- a/test_coding_rules_test.sh
+++ b/test_coding_rules_test.sh
@@ -34,18 +34,18 @@ good_copyright="...Copyright (C)...`date -u +'%Y'`..."

 good_url="...http://savannah.nongnu.org/projects/lmi...";

-boilerplate="$good_copyright"$'\n'"$good_url"
-
 # Files in general.

 cat >eraseme_000 <<EOF
-$boilerplate
+$good_copyright
+$good_url
 EOF

 # Files in general: copyright.

 cat >eraseme_copyright_000 <<EOF
-$boilerplate
+$good_copyright
+$good_url
 "(C) 1999": upper-case 'C' is correct in ASCII copyright symbol.
 EOF

@@ -60,7 +60,8 @@ EOF
 # html files: copyright.

 cat >eraseme_copyright_002.html <<EOF
-$boilerplate
+$good_copyright
+$good_url
 Copyright &copy; `date -u +'%Y'`
 EOF

@@ -71,7 +72,8 @@ Copyright &copy; `date -u +'%Y'`
 EOF

 cat >eraseme_copyright_004.html <<EOF
-$boilerplate
+$good_copyright
+$good_url
 Missing circle-C copyright.
 EOF

@@ -80,14 +82,16 @@ EOF
 Q='?'

 cat >eraseme_marker_000 <<EOF
-$boilerplate
+$good_copyright
+$good_url
  TODO ${Q}${Q} Okay.
  INELEGANT !! Okay.
  number_of_valid_pointers += !!p; // This legitimate usage is allowed.
 EOF

 cat >eraseme_marker_001 <<EOF
-$boilerplate
+$good_copyright
+$good_url
  TODO${Q}${Q} Bad spacing.
  TODO ${Q}${Q}Bad spacing.
  TODO ${Q}${Q}${Q} Tripled.
@@ -102,11 +106,13 @@ EOF
 # Files in general: taboos.

 cat >eraseme_taboo_000 <<EOF
-$boilerplate
+$good_copyright
+$good_url
 EOF

 cat >eraseme_taboo_001 <<EOF
-$boilerplate
+$good_copyright
+$good_url
 675 Mass Ave, Cambridge, MA
 59 Temple Place, Suite 330
 Then said they unto him, Say now Shibboleth: and he said Sibboleth
@@ -126,48 +132,56 @@ EOF
 # Files in general: whitespace.

 cat >eraseme_whitespace_000 <<EOF
-$boilerplate
+$good_copyright
+$good_url
 Spaces are permitted; they  can   be    consecutive.
 EOF

 ascii_ff=$'\f'
 cat >eraseme_whitespace_001 <<EOF
-$boilerplate
+$good_copyright
+$good_url
 $ascii_ff
 EOF

 ascii_cr=$'\r'
 cat >eraseme_whitespace_002 <<EOF
-$boilerplate
+$good_copyright
+$good_url
 $ascii_cr
 EOF

 ascii_ht=$'\t'
 cat >eraseme_whitespace_003 <<EOF
-$boilerplate
+$good_copyright
+$good_url
 $ascii_ht
 EOF

 ascii_vt=$'\v'
 cat >eraseme_whitespace_004 <<EOF
-$boilerplate
+$good_copyright
+$good_url
 $ascii_vt
 EOF

 # C++ source files.

 cat >eraseme_cpp_000.cpp <<EOF
-$boilerplate
+$good_copyright
+$good_url
 EOF

 cat >eraseme_cpp_001.cpp <<EOF
-$boilerplate
+$good_copyright
+$good_url
 This header must be included only by other headers:
 #include "config.hpp"
 EOF

 cat >eraseme_cpp_002.cpp <<EOF
-$boilerplate
+$good_copyright
+$good_url
 Labels must be indented either two spaces:
   l0:
   LABEL_1 :
@@ -185,7 +199,8 @@ be aligned with its corresponding case labels:
 EOF

 cat >eraseme_cpp_003.cpp <<EOF
-$boilerplate
+$good_copyright
+$good_url
 '*' and '&' are part of the type, not the name: write
   foo& bar(); // bar() returns a 'reference to foo'
   int* x;     // x is a 'pointer to int'
@@ -199,7 +214,8 @@ but that's okay: the compiler would catch it.
 EOF

 cat >eraseme_cpp_004.cpp <<EOF
-$boilerplate
+$good_copyright
+$good_url
 Write a cv-qualifier after the type it modifies:
   void foo(T const&); // Yes.
   void foo(const T&); // No.
@@ -210,7 +226,8 @@ EOF
 # Headers.

 cat >eraseme_hpp_000.hpp <<EOF
-$boilerplate
+$good_copyright
+$good_url
 #ifndef eraseme_hpp_000_hpp
 #define eraseme_hpp_000_hpp
 #include "config.hpp"
@@ -218,7 +235,8 @@ $boilerplate
 EOF

 cat >eraseme_hpp_001.hpp <<EOF
-$boilerplate
+$good_copyright
+$good_url
 #ifndef eraseme_hpp_001_hpp
 #define eraseme_hpp_001_hpp
 #include "config.hpp"
@@ -227,7 +245,8 @@ Name in comment is required to match:
 EOF

 cat >eraseme_hpp_002.hpp <<EOF
-$boilerplate
+$good_copyright
+$good_url
 Stray comments on include guards are forbidden as meaningless.
 #ifndef eraseme_hpp_002_hpp // Here's a guard to make the header idempotent.
 #define eraseme_hpp_002_hpp // But such a comment is only distracting.
@@ -236,7 +255,8 @@ Stray comments on include guards are forbidden as 
meaningless.
 EOF

 cat >eraseme_hpp_003.hpp <<EOF
-$boilerplate
+$good_copyright
+$good_url
 Include guards must occur in correct order.
 #define eraseme_hpp_003_hpp
 #ifndef eraseme_hpp_003_hpp
@@ -245,7 +265,8 @@ Include guards must occur in correct order.
 EOF

 cat >eraseme_hpp_004.hpp <<EOF
-$boilerplate
+$good_copyright
+$good_url
 #ifndef eraseme_hpp_004_hpp
 #define eraseme_hpp_004_hpp
 #include "config.hpp"
@@ -254,7 +275,8 @@ Nothing but newline is permitted after the closing include 
guard.
 EOF

 cat >eraseme_hpp_005.hpp <<EOF
-$boilerplate
+$good_copyright
+$good_url
 #ifndef eraseme_hpp_005_hpp
 #define eraseme_hpp_005_hpp
 This compulsory include directive must occur, in canonical form (with
@@ -266,7 +288,8 @@ only one space, preceding '"'), before any other include 
directive.
 EOF

 cat >eraseme_hpp_006.hpp <<EOF
-$boilerplate
+$good_copyright
+$good_url
 #ifndef eraseme_hpp_006_hpp
 #define eraseme_hpp_006_hpp
 Missing compulsory include directive.
@@ -276,7 +299,8 @@ EOF
 # Log files.

 cat >eraseme_log_000.Log <<EOF
-$boilerplate
+$good_copyright
+$good_url
 'Log' is just a suffix, distinct from the extension '.Log'; the dot in
 this file's name merely avoids "camel case", which the author dislikes.
 This line's length is over the limit, but...acceptable in the preamble.
@@ -293,7 +317,8 @@ http URL, like this:
 EOF

 cat >eraseme_log_001.Log <<EOF
-$boilerplate
+$good_copyright
+$good_url
 The word "MAINTENANCE" is expected on a line by itself, but this file has
 no such line. The 'grep' regex is "^MAINTENANCE$", so these don't suffice:
 Maintenance
@@ -303,7 +328,8 @@ and each long line preceding them elicits a diagnostic.
 EOF

 cat >eraseme_log_002.Log <<EOF
-$boilerplate
+$good_copyright
+$good_url
 MAINTENANCE
 This line's length is at the limit, so it should elicit no diagnostic.
 This line's length is slightly over the limit, so it must be diagnosed.
@@ -314,20 +340,23 @@ EOF

 cat >eraseme_make_000.make <<EOF
 ${ascii_ht}
-$boilerplate
+$good_copyright
+$good_url
 A line's initial tab can be followed by any other character.
 ${ascii_ht}This is okay.
 ${ascii_ht}
 EOF

 cat >eraseme_make_001.make <<EOF
-$boilerplate
+$good_copyright
+$good_url
 Consecutive tabs are forbidden.
 ${ascii_ht}${ascii_ht}
 EOF

 cat >eraseme_make_002.make <<EOF
-$boilerplate
+$good_copyright
+$good_url
 Tab can occur only at the beginning of a line.
  ${ascii_ht}
 EOF




reply via email to

[Prev in Thread] Current Thread [Next in Thread]