From d4a36f2ba528618ce0caebd524247dd6feabd48a Mon Sep 17 00:00:00 2001 From: Daniel Aarno Date: Sun, 7 Jan 2018 15:33:10 +0000 Subject: [PATCH 1/2] Use make check to run tests (instead of custom logic). This way the list/number of tests only has to be updated in one place. Conflicts: tests/runtests.sh --- tests/runtests.sh | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/tests/runtests.sh b/tests/runtests.sh index b0ad68f..caec752 100755 --- a/tests/runtests.sh +++ b/tests/runtests.sh @@ -1,29 +1,7 @@ #!/bin/bash -let "suc = 0" -let "fail = 0" -NUMTEST=79 +# Always run in script-dir +DIR=`dirname $0` +cd $DIR -for (( tno = 1 ; $tno <= $NUMTEST ; tno = $tno + 1 )); do - ./testCheck.sh $tno - if [ "$?" -eq "0" ]; then - echo "OK" - let "suc = $(($suc + 1))" - else - echo "FAIL" - let "fail = $(($fail + 1))" - fi -done - -let "total = $(($suc + $fail))" -echo "======================" -echo "| TESTS DONE |" -echo "======================" -echo " TOTAL: $total" -echo " OK: $suc" -echo "FAILED: $fail" - -if [ $fail -ne 0 ]; then - exit 1 -fi - +make check From 3adc1d1ff708051e897d6647a99c6f5fefee6e13 Mon Sep 17 00:00:00 2001 From: Daniel Aarno Date: Sun, 7 Jan 2018 15:32:23 +0000 Subject: [PATCH 2/2] Pre-commit check for including test files in Makefile Script to be called from pre-commit hook to make sure any new test files were added to Makefile.am Example pre-commit hook (in .git/hooks): function pyhook { CMD="./scripts/$1.py" $CMD local status=$? if [ $status -ne 0 ]; then echo echo "Pre-commit failed" exit 1 fi } pyhook check_tests_enabled --- scripts/check_tests_enabled.py | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 scripts/check_tests_enabled.py diff --git a/scripts/check_tests_enabled.py b/scripts/check_tests_enabled.py new file mode 100755 index 0000000..1600197 --- /dev/null +++ b/scripts/check_tests_enabled.py @@ -0,0 +1,49 @@ +#!/usr/bin/python + +# Copyright (c) 2017 Google Inc. +# All rights reserved. +# +# See the file COPYING in the top directory of this distribution for +# more information. +# +# THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +import glob +import os +import sys +import re + +ignored_files = frozenset(['testCheck.sh']) + +def get_test_files(path): + return map(os.path.basename, + glob.glob(os.path.join(path, 'test*.sh'))) + +def get_test_cases(path): + with file(os.path.join(path, 'Makefile.am')) as f: + lines = [] + for line in f: + m = re.match(r'.*(test\d+\.sh).*', line.strip()) + if m: + lines.append(m.group(1)) + + return lines + +def main(): + test_files = set(get_test_files('./tests')) - ignored_files + test_cases = set(get_test_cases('./tests')) + diff = test_files - test_cases + if diff: + print 'The following files are not in Makefile.am' + print diff + sys.exit(1) + +if __name__ == '__main__': + main() +