From 5f12ff617876ad89179468dece929cd38082b632 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 12 Jun 2018 04:35:44 -0400 Subject: [PATCH] lang: Add indentation test to parser This adds a test case to catch some common typos. --- test.sh | 1 + test/test-vet.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 test/test-vet.sh diff --git a/test.sh b/test.sh index 6326d16b..40c3b5a4 100755 --- a/test.sh +++ b/test.sh @@ -43,6 +43,7 @@ function skip-testsuite() # used at the end to tell if everything went fine failures='' +run-testsuite ./test/test-vet.sh run-testsuite ./test/test-misc.sh run-testsuite ./test/test-gofmt.sh run-testsuite ./test/test-yamlfmt.sh diff --git a/test/test-vet.sh b/test/test-vet.sh new file mode 100755 index 00000000..ed446aa6 --- /dev/null +++ b/test/test-vet.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# vet a few random things + +echo running "$0" + +#ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir! +ROOT=$(dirname "${BASH_SOURCE}")/.. +cd "${ROOT}" +. test/util.sh + +failures='' +function run-test() +{ + $@ || failures=$( [ -n "$failures" ] && echo "$failures\\n$@" || echo "$@" ) +} + +function parser-indentation() { + # the $ before the \t magically makes grep match the tab somehow... + if grep $'\t|' "$1"; then # indent the pipe too + return 1 + fi + if grep ' |' "$1"; then # indent the pipe too (no spaces!) + return 1 + fi + if grep '^ ' "$1"; then # format with tabs, no leading spaces + return 1 + fi + + return 0 +} + +# loop through individual *.y files +for file in `find . -maxdepth 3 -type f -name '*.y' -not -path './old/*' -not -path './tmp/*'`; do + run-test parser-indentation "$file" +done + +if [[ -n "$failures" ]]; then + echo 'FAIL' + echo 'The following tests have failed:' + echo -e "$failures" + echo + exit 1 +fi +echo 'PASS'