Files
mgmt/test/test-vet.sh
James Shubin 5f12ff6178 lang: Add indentation test to parser
This adds a test case to catch some common typos.
2018-06-12 17:40:18 -04:00

45 lines
956 B
Bash
Executable File

#!/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'