Skip to content

Commit

Permalink
lang: Add indentation test to parser
Browse files Browse the repository at this point in the history
This adds a test case to catch some common typos.
  • Loading branch information
purpleidea committed Jun 12, 2018
1 parent 6e20e48 commit 5f12ff6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions test/test-vet.sh
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 5f12ff6

Please sign in to comment.