* src/sanity/style.test: Do not use the deprecated GREP_OPTIONS.

This commit is contained in:
Alexandre Duret-Lutz 2015-01-03 11:52:29 +01:00
parent 40fb80ea2c
commit c73a4ac916

View file

@ -1,6 +1,6 @@
#! /bin/sh #! /bin/sh
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Laboratoire de # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Laboratoire de
# Recherche et Développement de l'Epita (LRDE). # Recherche et Développement de l'Epita (LRDE).
# Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 # Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6
# (LIP6), département Systèmes Répartis Coopératifs (SRC), Université # (LIP6), département Systèmes Répartis Coopératifs (SRC), Université
@ -34,11 +34,12 @@ diag()
rm -f failures rm -f failures
GREP=grep
# Get some help from GNU grep. # Get some help from GNU grep.
if (grep --color=auto -n --version)>/dev/null 2>&1; then if (grep --color=auto -n --version)>/dev/null 2>&1; then
GREP_OPTIONS='--color=auto -n' GREP="$GREP --color=auto -n"
GREP_COLOR='1;31' GREP_COLOR='1;31'
export GREP_OPTIONS
export GREP_COLOR export GREP_COLOR
fi fi
@ -60,8 +61,8 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
-a -type f -a -print | -a -type f -a -print |
while read file; do while read file; do
if grep 'GNU Bison' "$file" >/dev/null || if $GREP 'GNU Bison' "$file" >/dev/null ||
grep 'generated by flex' "$file" >/dev/null ; then $GREP 'generated by flex' "$file" >/dev/null ; then
continue continue
fi fi
@ -73,22 +74,22 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
fail=false fail=false
# Check this before stripping comments and strings. # Check this before stripping comments and strings.
grep -i 'accepting cond' $file && $GREP -i 'accepting cond' $file &&
diag 'accepting -> acceptance' diag 'accepting -> acceptance'
grep -i 'version 2 of the License' $file && $GREP -i 'version 2 of the License' $file &&
diag 'license text should refer to version 2' diag 'license text should refer to version 2'
grep -i 'Temple Place' $file && $GREP -i 'Temple Place' $file &&
diag 'license text should give a url instead of an address' diag 'license text should give a url instead of an address'
grep Copyright $file >/dev/null || $GREP Copyright $file >/dev/null ||
diag "missing copyright" diag "missing copyright"
# If some grep implementation ignore LC_ALL=C, this rule might be # If some grep implementation ignores LC_ALL=C, this rule might be
# a problem on utf-8 characters such as "δ" which really # a problem on utf-8 characters such as "δ" which really
# corresponds to multiple bytes, but might be matched as a single # corresponds to multiple bytes, but might be matched as a single
# character by grep. # character by grep.
grep '<< *"\([^\\]\|\\.\)"' $file && $GREP '<< *"\([^\\]\|\\.\)"' $file &&
diag "Use << 'c' instead" 'of << "c".' diag "Use << 'c' instead" 'of << "c".'
# A doxygen comments such as # A doxygen comments such as
@ -122,135 +123,135 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
s,"[^"\n]*","",g; s,"[^"\n]*","",g;
s,SPOT_API ,,g' -0777 <$file >$tmp s,SPOT_API ,,g' -0777 <$file >$tmp
grep '[ ]$' $tmp && $GREP '[ ]$' $tmp &&
diag 'Trailing whitespace.' diag 'Trailing whitespace.'
case $file in case $file in
*.test);; *.test);;
*) *)
grep -E '[^<]class[ \t]+[A-Z]' $tmp && $GREP -E '[^<]class[ \t]+[A-Z]' $tmp &&
diag 'Use lower case class names.' diag 'Use lower case class names.'
grep '[ ]if(' $tmp && $GREP '[ ]if(' $tmp &&
diag 'Missing space after "if"' diag 'Missing space after "if"'
grep '[ ]if (.*).*{' $tmp && $GREP '[ ]if (.*).*{' $tmp &&
diag 'Opening { should be on its own line.' diag 'Opening { should be on its own line.'
grep '[ ]if (.*).*;' $tmp && $GREP '[ ]if (.*).*;' $tmp &&
diag 'if body should be on another line.' diag 'if body should be on another line.'
grep '[ ]else.*;' $tmp && $GREP '[ ]else.*;' $tmp &&
diag 'else body should be on another line.' diag 'else body should be on another line.'
grep '[ ]while(' $tmp && $GREP '[ ]while(' $tmp &&
diag 'Missing space after "while"' diag 'Missing space after "while"'
grep '[ ]while (.*).*{' $tmp && $GREP '[ ]while (.*).*{' $tmp &&
diag 'Opening { should be on its own line.' diag 'Opening { should be on its own line.'
grep '[ ]while (.*).*[^)];' $tmp && $GREP '[ ]while (.*).*[^)];' $tmp &&
diag 'while body should be on another line.' diag 'while body should be on another line.'
grep '[ ]for(' $tmp && $GREP '[ ]for(' $tmp &&
diag 'Missing space after "for"' diag 'Missing space after "for"'
grep '[ ]for (.*).*{' $tmp && $GREP '[ ]for (.*).*{' $tmp &&
diag 'Opening { should be on its own line.' diag 'Opening { should be on its own line.'
grep '[ ]for (.*;.*;.*).*;' $tmp && $GREP '[ ]for (.*;.*;.*).*;' $tmp &&
diag 'for body should be on another line.' diag 'for body should be on another line.'
grep '[ ]switch(' $tmp && $GREP '[ ]switch(' $tmp &&
diag 'Missing space after "switch"' diag 'Missing space after "switch"'
grep '[ ]switch (.*).*{' $tmp && $GREP '[ ]switch (.*).*{' $tmp &&
diag 'Opening { should be on its own line.' diag 'Opening { should be on its own line.'
grep 'namespace .*{' $tmp && $GREP 'namespace .*{' $tmp &&
diag 'Opening { should be on its own line.' diag 'Opening { should be on its own line.'
grep 'class .*{' $tmp && $GREP 'class .*{' $tmp &&
diag 'Opening { should be on its own line.' diag 'Opening { should be on its own line.'
grep '( ' $tmp && $GREP '( ' $tmp &&
diag 'No space after opening (.' diag 'No space after opening (.'
grep ' )' $tmp && $GREP ' )' $tmp &&
diag 'No space before closing ).' diag 'No space before closing ).'
grep '! ' $tmp && $GREP '! ' $tmp &&
diag 'No space after unary operators (!).' diag 'No space after unary operators (!).'
grep ",[^ \" %'\\\\]" $tmp && $GREP ",[^ \" %'\\\\]" $tmp &&
diag 'Space after coma.' diag 'Space after coma.'
# The 'r' allows operator&& # The 'r' allows operator&&
# The '.' allows &&... # The '.' allows &&...
grep '[^ r]&&[^ .]' $tmp && $GREP '[^ r]&&[^ .]' $tmp &&
diag 'Space around binary operators.' diag 'Space around binary operators.'
# The 'r' allows operator|| # The 'r' allows operator||
grep '[^ r]||[^ ]' $tmp && $GREP '[^ r]||[^ ]' $tmp &&
diag 'Space around binary operators.' diag 'Space around binary operators.'
# The 'r' allows operator== # The 'r' allows operator==
grep '[^ r<>][!<>=]=[^ ]' $tmp && $GREP '[^ r<>][!<>=]=[^ ]' $tmp &&
diag 'Space around binary operators.' diag 'Space around binary operators.'
# The 'r' allows operator<<= # The 'r' allows operator<<=
grep '[^ r][<>][<>]=[^ ]' $tmp && $GREP '[^ r][<>][<>]=[^ ]' $tmp &&
diag 'Space around binary operators.' diag 'Space around binary operators.'
grep 'operator[^a-zA-Z0-9_(]*[ ][^a-zA-Z0-9_(]*(' $tmp && $GREP 'operator[^a-zA-Z0-9_(]*[ ][^a-zA-Z0-9_(]*(' $tmp &&
diag 'Write operatorXX(...) without spaces around XX.' diag 'Write operatorXX(...) without spaces around XX.'
grep 'operator[^(]* (' $tmp && $GREP 'operator[^(]* (' $tmp &&
diag 'No space before (' diag 'No space before ('
grep '[ ]default:[^:].*;' $tmp && $GREP '[ ]default:[^:].*;' $tmp &&
diag 'Label should be on their own line.' diag 'Label should be on their own line.'
grep '[ ]case.*:[^:].*;' $tmp && $GREP '[ ]case.*:[^:].*;' $tmp &&
diag 'Label should be on their own line.' diag 'Label should be on their own line.'
grep '[ ];' $tmp && $GREP '[ ];' $tmp &&
diag 'No space before semicolon.' diag 'No space before semicolon.'
grep -v 'for (.*;;)' $tmp | grep ';[^ ")'"']" && $GREP -v 'for (.*;;)' $tmp | $GREP ';[^ ")'"']" &&
diag 'Must have space or newline after semicolon.' diag 'Must have space or newline after semicolon.'
grep '}.*}' $tmp && $GREP '}.*}' $tmp &&
diag 'No two } on the same line.' diag 'No two } on the same line.'
grep '{.*{' $tmp && $GREP '{.*{' $tmp &&
diag 'No two { on the same line.' diag 'No two { on the same line.'
grep 'delete[ ]*[(][^(]*[)];' $tmp && $GREP 'delete[ ]*[(][^(]*[)];' $tmp &&
diag 'No useless parentheses after delete.' diag 'No useless parentheses after delete.'
grep 'return[ ]*[(][^(]*[)];' $tmp && $GREP 'return[ ]*[(][^(]*[)];' $tmp &&
diag 'No useless parentheses after return.' diag 'No useless parentheses after return.'
grep 'NULL' $tmp && $GREP 'NULL' $tmp &&
diag 'Use 0 instead of NULL. NULL is not portable.' diag 'Use 0 instead of NULL. NULL is not portable.'
# std::list::size() can be O(n). Better use empty() whenever # std::list::size() can be O(n). Better use empty() whenever
# possible, even for other containers. # possible, even for other containers.
egrep '(->|[.])size\(\) [=!]= 0|![a-zA-Z0-9_]*(->|[.])size\(\)|(if |while |assert)\([a-zA-Z0-9_]*(->|[.])size\(\)\)' $tmp && e$GREP '(->|[.])size\(\) [=!]= 0|![a-zA-Z0-9_]*(->|[.])size\(\)|(if |while |assert)\([a-zA-Z0-9_]*(->|[.])size\(\)\)' $tmp &&
diag 'Prefer empty() to check emptiness.' diag 'Prefer empty() to check emptiness.'
egrep 'assert\((0|!".*")\)' $tmp && e$GREP 'assert\((0|!".*")\)' $tmp &&
diag 'Prefer SPOT_UNREACHABLE or SPOT_UNIMPLEMENTED.' diag 'Prefer SPOT_UNREACHABLE or SPOT_UNIMPLEMENTED.'
egrep '^[^=*<]*([+][+]|--);' $tmp && e$GREP '^[^=*<]*([+][+]|--);' $tmp &&
diag 'Take good habits: use ++i instead of i++ when you have the choice.' diag 'Take good habits: use ++i instead of i++ when you have the choice.'
grep '[^a-zA-Z0-9_](\*[a-zA-Z0-9_]*)\.' $tmp && $GREP '[^a-zA-Z0-9_](\*[a-zA-Z0-9_]*)\.' $tmp &&
diag 'Use "x->y", not "(*x).y"' diag 'Use "x->y", not "(*x).y"'
# we allow these functions only in ?...:... # we allow these functions only in ?...:...
egrep 'bdd_(false|true)[ ]*\(' $tmp | grep -v '[?:]' && e$GREP 'bdd_(false|true)[ ]*\(' $tmp | $GREP -v '[?:]' &&
diag 'Use bddfalse and bddtrue instead of bdd_false() and bdd_true()' diag 'Use bddfalse and bddtrue instead of bdd_false() and bdd_true()'
res=`perl -ne '$/ = undef; res=`perl -ne '$/ = undef;
@ -263,25 +264,25 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
case $file in case $file in
*.hh | *.hxx) *.hh | *.hxx)
if egrep '(<<|>>)' $tmp >/dev/null; then if e$GREP '(<<|>>)' $tmp >/dev/null; then
: :
else else
grep '#.*include.*<iostream>' $tmp && $GREP '#.*include.*<iostream>' $tmp &&
diag 'Avoid <iostream> in headers, better use <iosfwd>.' diag 'Avoid <iostream> in headers, better use <iosfwd>.'
fi fi
# Headers from src/priv/ are not installed, so may only be # Headers from src/priv/ are not installed, so may only be
# included from *.cc files or from other src/priv/ headers # included from *.cc files or from other src/priv/ headers
# (in the latter case they do not have to specify the priv/ # (in the latter case they do not have to specify the priv/
# directory, so they will not match this regex). # directory, so they will not match this regex).
grep '#.*include.*priv/' $tmp && $GREP '#.*include.*priv/' $tmp &&
diag 'Do not include private headers in public headers.' diag 'Do not include private headers in public headers.'
;; ;;
*.cc) *.cc)
if grep 'namespace$' $tmp >/dev/null; then if $GREP 'namespace$' $tmp >/dev/null; then
: :
else else
# We only check classes, but the rule should apply to functions too # We only check classes, but the rule should apply to functions too
grep '^[ ]*class[ ]' $tmp && $GREP '^[ ]*class[ ]' $tmp &&
diag 'Private definitions must be in anonymous namespace.' diag 'Private definitions must be in anonymous namespace.'
fi fi
;; ;;
@ -306,10 +307,10 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
# Strip comments. # Strip comments.
sed 's,#.*,,' < $file > $tmp sed 's,#.*,,' < $file > $tmp
grep '[ ]$' $tmp && $GREP '[ ]$' $tmp &&
diag 'Trailing whitespace.' diag 'Trailing whitespace.'
grep '\.libs/' $tmp && $GREP '\.libs/' $tmp &&
diag "Don't reference files in .libs/, use Libtool instead." diag "Don't reference files in .libs/, use Libtool instead."
$fail && echo "$file" >>failures $fail && echo "$file" >>failures