Skip to content

Commit

Permalink
compare_compilers.sh script improvements (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli authored Feb 26, 2023
1 parent a84f66c commit 1d421a5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
id: check-need-valgrind
run: |
git fetch https://github.com/Akuli/jou main
if git diff --name-only FETCH_HEAD HEAD | grep -E '(linux\.yml|\.c|\.h)$'; then
if git diff --name-only FETCH_HEAD HEAD | grep -E '(\.c|\.h)$'; then
echo doit=yes >> $GITHUB_OUTPUT
else
echo doit=no >> $GITHUB_OUTPUT
Expand All @@ -39,10 +39,10 @@ jobs:
exit 1
fi
tokenizers:
compare-compilers:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: sudo apt install -y llvm-13-dev clang-13 make valgrind
- run: LLVM_CONFIG=llvm-config-13 make
- run: ./tokenizers.sh
- run: ./compare_compilers.sh
6 changes: 3 additions & 3 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ jobs:
- run: cd "test dir" && ./runtests.sh --verbose
shell: bash

tokenizers:
compare-compilers:
needs: build
runs-on: windows-latest
steps:
Expand All @@ -141,7 +141,7 @@ jobs:
with:
name: windows-zip
- run: unzip jou.zip
- run: mv tokenizers.sh self_hosted jou
- run: mv compare_compilers.sh self_hosted tests jou
shell: bash
- run: (cd jou && ./tokenizers.sh)
- run: (cd jou && ./compare_compilers.sh)
shell: bash
35 changes: 27 additions & 8 deletions tokenizers.sh → compare_compilers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
# They should be able to tokenize each Jou file in exactly the same way.
# If tokenizing a Jou file fails, both tokenizers should fail with the same error message.

if [ $# = 0 ]; then
fix=no
elif [ $# = 1 ] && [ "$1" = --fix ]; then
fix=yes
else
echo "Usage: $0 [--fix]" >&2
exit 2
fi

if [[ "$OS" =~ Windows ]]; then
dotexe=.exe
else
Expand All @@ -26,21 +35,31 @@ for file in $(find examples tests -name '*.jou' | sort); do
if grep -qxF $file self_hosted/tokenizes_wrong.txt; then
# The file is skipped, so the two compilers should behave differently
if diff tmp/tokenizers/compiler_written_in_c.txt tmp/tokenizers/self_hosted.txt >/dev/null; then
echo " Error: Tokenizers behave the same even though the file is listed in self_hosted/tokenizes_wrong.txt."
echo " To fix this error, delete the \"$file\" line from self_hosted/tokenizes_wrong.txt."
#grep -vxF $file self_hosted/tokenizes_wrong.txt > /tmp/x; mv /tmp/x self_hosted/tokenizes_wrong.txt
exit 1
if [ $fix = yes ]; then
echo " Deleting $file from self_hosted/tokenizes_wrong.txt"
grep -vxF $file self_hosted/tokenizes_wrong.txt > tmp/tokenizers/newlist.txt
mv tmp/tokenizers/newlist.txt self_hosted/tokenizes_wrong.txt
else
echo " Error: Tokenizers behave the same even though the file is listed in self_hosted/tokenizes_wrong.txt."
echo " To fix this error, delete the \"$file\" line from self_hosted/tokenizes_wrong.txt (or run again with --fix)."
exit 1
fi
else
echo " Tokenizers behave differently as expected (listed in self_hosted/tokenizes_wrong.txt)"
fi
else
if diff -u --color=always tmp/tokenizers/compiler_written_in_c.txt tmp/tokenizers/self_hosted.txt; then
echo " Tokenizers behave the same as expected"
else
echo " Error: Tokenizers behave differently when given \"$file\"."
echo " You can silence this error by adding \"$file\" to self_hosted/tokenizes_wrong.txt."
echo " Ideally the tokenizers would behave in the same way for all files, but we aren't there yet."
exit 1
if [ $fix = yes ]; then
echo " Adding $file to self_hosted/tokenizes_wrong.txt"
echo $file >> self_hosted/tokenizes_wrong.txt
else
echo " Error: Tokenizers behave differently when given \"$file\"."
echo " Ideally the tokenizers would behave in the same way for all files, but we aren't there yet."
echo " To silence this error, add \"$file\" to self_hosted/tokenizes_wrong.txt (or run again with --fix)."
exit 1
fi
fi
fi
done
Expand Down

0 comments on commit 1d421a5

Please sign in to comment.