summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-11-12 11:22:01 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-11-21 16:34:39 +0000
commit604611aceb217649d0e08f635d24e1b3e83b1028 (patch)
treef3125221c37433408488a80545277bb52f0c89ab
parent0b3ec68ce46f638e79e52f9f97f26727d9c4daa1 (diff)
downloadmorph-604611aceb217649d0e08f635d24e1b3e83b1028.tar.gz
tests: Run style check before slower tests
It turns out that only the check-copyright-year script was exiting properly, but it was not doing the deferred exit that other tests were doing. Other tests would set errors=1, then later check the result and exit if it's non-zero, however the errors variable was set in a sub-shell, since it was on the right-hand side of a pipe.
-rwxr-xr-xcheck81
-rwxr-xr-xscripts/check-silliness63
2 files changed, 85 insertions, 59 deletions
diff --git a/check b/check
index 160515f1..c0d1683d 100755
--- a/check
+++ b/check
@@ -42,6 +42,28 @@ case "$PYTHONPATH" in
esac
export PYTHONPATH
+# Run the style checks
+
+errors=0
+if [ -d .git ];
+then
+ echo "Checking copyright statements"
+ if ! (git ls-files -z | xargs -0r scripts/check-copyright-year); then
+ errors=1
+ fi
+
+ echo 'Checking source code for silliness'
+ if ! (git ls-files |
+ grep -v '\.gz$' |
+ grep -Ev 'tests[^/]*/.*\.std(out|err)' |
+ grep -vF 'tests.build/build-system-autotools.script' |
+ xargs -r scripts/check-silliness); then
+ errors=1
+ fi
+fi
+if [ "$errors" != 0 ]; then
+ exit "$errors"
+fi
# Clean up artifacts from previous (possibly failed) runs, build,
# and run the tests.
@@ -97,62 +119,3 @@ then
else
echo "NOT RUNNING tests.as-root (requires PyYAML)"
fi
-
-if [ -d .git ];
-then
- echo "Checking copyright statements"
- git ls-files | xargs scripts/check-copyright-year
-
- echo 'Checking source code for silliness'
- git ls-files |
- grep -v '\.gz$' |
- grep -Ev 'tests[^/]*/.*\.std(out|err)' |
- grep -vF 'tests.build/build-system-autotools.script' |
- while read x
- do
- if tr -cd '\t' < "$x" | grep . > /dev/null
- then
- echo "ERROR: $x contains TAB characters" 1>&2
- grep -n -F "$(printf "\t")" "$x" 1>&2
- errors=1
- fi
-
- case "$x" in
- # Excluding yarn files since it's not possible to split up the
- # IMPLEMENTS lines of them
- *.yarn) ;;
- *)
- if awk 'length > 79' "$x" | grep . > /dev/null
- then
- echo "ERROR: $x has lines longer than 79 chars" 1>&2
- awk 'length > 79 { print NR, $0 }' "$x" 1>&2
- errors=1
- fi
- ;;
- esac
-
- case "$x" in
- *.py)
- if head -1 "$x" | grep '^#!' > /dev/null
- then
- echo "ERROR: $x has a hashbang" 1>&2
- errors=1
- fi
- if grep except: "$x"
- then
- echo "ERROR: $x has a bare except:" 1>&2
- errors=1
- fi
- ;;
- esac
- done
-
- echo 'Checking for executable *.py files'
- find . -type f -name '*.py' -perm +111 |
- while read x
- do
- echo "ERROR: $x is executable" 1>&2
- errors=1
- done
-fi
-exit $errors
diff --git a/scripts/check-silliness b/scripts/check-silliness
new file mode 100755
index 00000000..f956e647
--- /dev/null
+++ b/scripts/check-silliness
@@ -0,0 +1,63 @@
+#!/bin/sh
+#
+# Does the file contain any of the code constructs deemed silly?
+#
+# Copyright (C) 2013 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+errors=0
+
+for x; do
+ if tr -cd '\t' < "$x" | grep . > /dev/null
+ then
+ echo "ERROR: $x contains TAB characters" 1>&2
+ grep -n -F "$(printf "\t")" "$x" 1>&2
+ errors=1
+ fi
+
+ case "$x" in
+ # Excluding yarn files since it's not possible to split up the
+ # IMPLEMENTS lines of them
+ *.yarn) ;;
+ *)
+ if awk 'length > 79' "$x" | grep . > /dev/null
+ then
+ echo "ERROR: $x has lines longer than 79 chars" 1>&2
+ awk 'length > 79 { print NR, $0 }' "$x" 1>&2
+ errors=1
+ fi
+ ;;
+ esac
+
+ case "$x" in
+ *.py)
+ if head -1 "$x" | grep '^#!' > /dev/null
+ then
+ echo "ERROR: $x has a hashbang" 1>&2
+ errors=1
+ fi
+ if [ -x "$x" ]; then
+ echo "ERROR: $x is executable" 1>&2
+ errors=1
+ fi
+ if grep except: "$x"
+ then
+ echo "ERROR: $x has a bare except:" 1>&2
+ errors=1
+ fi
+ ;;
+ esac
+done
+exit "$errors"