-
-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lang: Add indentation test to parser
This adds a test case to catch some common typos.
- Loading branch information
1 parent
6e20e48
commit 5f12ff6
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |