Commit c73a4ac9 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

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

parent 40fb80ea
#! /bin/sh
# -*- 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).
# Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6
# (LIP6), département Systèmes Répartis Coopératifs (SRC), Université
......@@ -34,11 +34,12 @@ diag()
rm -f failures
GREP=grep
# Get some help from GNU grep.
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'
export GREP_OPTIONS
export GREP_COLOR
fi
......@@ -60,8 +61,8 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
-a -type f -a -print |
while read file; do
if grep 'GNU Bison' "$file" >/dev/null ||
grep 'generated by flex' "$file" >/dev/null ; then
if $GREP 'GNU Bison' "$file" >/dev/null ||
$GREP 'generated by flex' "$file" >/dev/null ; then
continue
fi
......@@ -73,22 +74,22 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
fail=false
# Check this before stripping comments and strings.
grep -i 'accepting cond' $file &&
$GREP -i 'accepting cond' $file &&
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'
grep -i 'Temple Place' $file &&
$GREP -i 'Temple Place' $file &&
diag 'license text should give a url instead of an address'
grep Copyright $file >/dev/null ||
$GREP Copyright $file >/dev/null ||
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
# corresponds to multiple bytes, but might be matched as a single
# character by grep.
grep '<< *"\([^\\]\|\\.\)"' $file &&
$GREP '<< *"\([^\\]\|\\.\)"' $file &&
diag "Use << 'c' instead" 'of << "c".'
# A doxygen comments such as
......@@ -122,135 +123,135 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
s,"[^"\n]*","",g;
s,SPOT_API ,,g' -0777 <$file >$tmp
grep '[ ]$' $tmp &&
$GREP '[ ]$' $tmp &&
diag 'Trailing whitespace.'
case $file in
*.test);;
*)
grep -E '[^<]class[ \t]+[A-Z]' $tmp &&
$GREP -E '[^<]class[ \t]+[A-Z]' $tmp &&
diag 'Use lower case class names.'
grep '[ ]if(' $tmp &&
$GREP '[ ]if(' $tmp &&
diag 'Missing space after "if"'
grep '[ ]if (.*).*{' $tmp &&
$GREP '[ ]if (.*).*{' $tmp &&
diag 'Opening { should be on its own line.'
grep '[ ]if (.*).*;' $tmp &&
$GREP '[ ]if (.*).*;' $tmp &&
diag 'if body should be on another line.'
grep '[ ]else.*;' $tmp &&
$GREP '[ ]else.*;' $tmp &&
diag 'else body should be on another line.'
grep '[ ]while(' $tmp &&
$GREP '[ ]while(' $tmp &&
diag 'Missing space after "while"'
grep '[ ]while (.*).*{' $tmp &&
$GREP '[ ]while (.*).*{' $tmp &&
diag 'Opening { should be on its own line.'
grep '[ ]while (.*).*[^)];' $tmp &&
$GREP '[ ]while (.*).*[^)];' $tmp &&
diag 'while body should be on another line.'
grep '[ ]for(' $tmp &&
$GREP '[ ]for(' $tmp &&
diag 'Missing space after "for"'
grep '[ ]for (.*).*{' $tmp &&
$GREP '[ ]for (.*).*{' $tmp &&
diag 'Opening { should be on its own line.'
grep '[ ]for (.*;.*;.*).*;' $tmp &&
$GREP '[ ]for (.*;.*;.*).*;' $tmp &&
diag 'for body should be on another line.'
grep '[ ]switch(' $tmp &&
$GREP '[ ]switch(' $tmp &&
diag 'Missing space after "switch"'
grep '[ ]switch (.*).*{' $tmp &&
$GREP '[ ]switch (.*).*{' $tmp &&
diag 'Opening { should be on its own line.'
grep 'namespace .*{' $tmp &&
$GREP 'namespace .*{' $tmp &&
diag 'Opening { should be on its own line.'
grep 'class .*{' $tmp &&
$GREP 'class .*{' $tmp &&
diag 'Opening { should be on its own line.'
grep '( ' $tmp &&
$GREP '( ' $tmp &&
diag 'No space after opening (.'
grep ' )' $tmp &&
$GREP ' )' $tmp &&
diag 'No space before closing ).'
grep '! ' $tmp &&
$GREP '! ' $tmp &&
diag 'No space after unary operators (!).'
grep ",[^ \" %'\\\\]" $tmp &&
$GREP ",[^ \" %'\\\\]" $tmp &&
diag 'Space after coma.'
# The 'r' allows operator&&
# The '.' allows &&...
grep '[^ r]&&[^ .]' $tmp &&
$GREP '[^ r]&&[^ .]' $tmp &&
diag 'Space around binary operators.'
# The 'r' allows operator||
grep '[^ r]||[^ ]' $tmp &&
$GREP '[^ r]||[^ ]' $tmp &&
diag 'Space around binary operators.'
# The 'r' allows operator==
grep '[^ r<>][!<>=]=[^ ]' $tmp &&
$GREP '[^ r<>][!<>=]=[^ ]' $tmp &&
diag 'Space around binary operators.'
# The 'r' allows operator<<=
grep '[^ r][<>][<>]=[^ ]' $tmp &&
$GREP '[^ r][<>][<>]=[^ ]' $tmp &&
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.'
grep 'operator[^(]* (' $tmp &&
$GREP 'operator[^(]* (' $tmp &&
diag 'No space before ('
grep '[ ]default:[^:].*;' $tmp &&
$GREP '[ ]default:[^:].*;' $tmp &&
diag 'Label should be on their own line.'
grep '[ ]case.*:[^:].*;' $tmp &&
$GREP '[ ]case.*:[^:].*;' $tmp &&
diag 'Label should be on their own line.'
grep '[ ];' $tmp &&
$GREP '[ ];' $tmp &&
diag 'No space before semicolon.'
grep -v 'for (.*;;)' $tmp | grep ';[^ ")'"']" &&
$GREP -v 'for (.*;;)' $tmp | $GREP ';[^ ")'"']" &&
diag 'Must have space or newline after semicolon.'
grep '}.*}' $tmp &&
$GREP '}.*}' $tmp &&
diag 'No two } on the same line.'
grep '{.*{' $tmp &&
$GREP '{.*{' $tmp &&
diag 'No two { on the same line.'
grep 'delete[ ]*[(][^(]*[)];' $tmp &&
$GREP 'delete[ ]*[(][^(]*[)];' $tmp &&
diag 'No useless parentheses after delete.'
grep 'return[ ]*[(][^(]*[)];' $tmp &&
$GREP 'return[ ]*[(][^(]*[)];' $tmp &&
diag 'No useless parentheses after return.'
grep 'NULL' $tmp &&
$GREP 'NULL' $tmp &&
diag 'Use 0 instead of NULL. NULL is not portable.'
# std::list::size() can be O(n). Better use empty() whenever
# 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.'
egrep 'assert\((0|!".*")\)' $tmp &&
e$GREP 'assert\((0|!".*")\)' $tmp &&
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.'
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"'
# 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()'
res=`perl -ne '$/ = undef;
......@@ -263,25 +264,25 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
case $file in
*.hh | *.hxx)
if egrep '(<<|>>)' $tmp >/dev/null; then
if e$GREP '(<<|>>)' $tmp >/dev/null; then
:
else
grep '#.*include.*<iostream>' $tmp &&
$GREP '#.*include.*<iostream>' $tmp &&
diag 'Avoid <iostream> in headers, better use <iosfwd>.'
fi
# Headers from src/priv/ are not installed, so may only be
# included from *.cc files or from other src/priv/ headers
# (in the latter case they do not have to specify the priv/
# 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.'
;;
*.cc)
if grep 'namespace$' $tmp >/dev/null; then
if $GREP 'namespace$' $tmp >/dev/null; then
:
else
# 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.'
fi
;;
......@@ -306,10 +307,10 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
# Strip comments.
sed 's,#.*,,' < $file > $tmp
grep '[ ]$' $tmp &&
$GREP '[ ]$' $tmp &&
diag 'Trailing whitespace.'
grep '\.libs/' $tmp &&
$GREP '\.libs/' $tmp &&
diag "Don't reference files in .libs/, use Libtool instead."
$fail && echo "$file" >>failures
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment