OSX: Fix readlink issues and that ASTImportTest.sh silently ignores errors.

This commit is contained in:
Alexander Arlt 2020-08-31 19:04:38 -05:00
parent af482558cf
commit 5f7b4a2e05
3 changed files with 70 additions and 19 deletions

View File

@ -1,10 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
# Bash script to test the ast-import option of the compiler by # Bash script to test the ast-import option of the compiler by
# first exporting a .sol file to JSON, then loading it into the compiler # first exporting a .sol file to JSON, then loading it into the compiler
# and exporting it again. The second JSON should be identical to the first # and exporting it again. The second JSON should be identical to the first
READLINK=readlink
REPO_ROOT=$(readlink -f "$(dirname "$0")"/..) if [[ "$OSTYPE" == "darwin"* ]]; then
READLINK=greadlink
fi
REPO_ROOT=$(${READLINK} -f "$(dirname "$0")"/..)
SOLIDITY_BUILD_DIR=${SOLIDITY_BUILD_DIR:-${REPO_ROOT}/build} SOLIDITY_BUILD_DIR=${SOLIDITY_BUILD_DIR:-${REPO_ROOT}/build}
SOLC=${SOLIDITY_BUILD_DIR}/solc/solc SOLC=${SOLIDITY_BUILD_DIR}/solc/solc
SPLITSOURCES=${REPO_ROOT}/scripts/splitSources.py SPLITSOURCES=${REPO_ROOT}/scripts/splitSources.py
@ -83,8 +88,11 @@ do
FILETMP=$(mktemp -d) FILETMP=$(mktemp -d)
cd $FILETMP cd $FILETMP
set +e
OUTPUT=$($SPLITSOURCES $solfile) OUTPUT=$($SPLITSOURCES $solfile)
if [ $? != 1 ] SPLITSOURCES_RC=$?
set -e
if [ ${SPLITSOURCES_RC} == 0 ]
then then
# echo $OUTPUT # echo $OUTPUT
NSOURCES=$((NSOURCES - 1)) NSOURCES=$((NSOURCES - 1))
@ -93,9 +101,26 @@ do
testImportExportEquivalence $i $OUTPUT testImportExportEquivalence $i $OUTPUT
NSOURCES=$((NSOURCES + 1)) NSOURCES=$((NSOURCES + 1))
done done
elif [ ${SPLITSOURCES_RC} == 1 ]
else then
testImportExportEquivalence $solfile testImportExportEquivalence $solfile
elif [ ${SPLITSOURCES_RC} == 2 ]
then
# The script will exit with return code 2, if an UnicodeDecodeError occurred.
# This is the case if e.g. some tests are using invalid utf-8 sequences. We will ignore
# these errors, but print the actual output of the script.
echo -e "\n${OUTPUT}\n"
testImportExportEquivalence $solfile
else
# All other return codes will be treated as critical errors. The script will exit.
echo -e "\nGot unexpected return code ${SPLITSOURCES_RC} from ${SPLITSOURCES}. Aborting."
echo -e "\n${OUTPUT}\n"
cd $WORKINGDIR
# Delete temporary files
rm -rf $FILETMP
exit 1
fi fi
cd $WORKINGDIR cd $WORKINGDIR

View File

@ -11,10 +11,20 @@
import sys import sys
import os import os
import traceback
hasMultipleSources = False hasMultipleSources = False
createdSources = [] createdSources = []
def uncaught_exception_hook(exc_type, exc_value, exc_traceback):
# The script `scripts/ASTImportTest.sh` will interpret return code 3
# as a critical error (because of the uncaught exception) and will
# terminate further execution.
print("Unhandled exception: %s", "".join(traceback.format_exception(exc_type, exc_value, exc_traceback)))
sys.exit(3)
def extractSourceName(line): def extractSourceName(line):
if line.find("/") > -1: if line.find("/") > -1:
filePath = line[13: line.rindex("/")] filePath = line[13: line.rindex("/")]
@ -23,6 +33,7 @@ def extractSourceName(line):
return filePath, srcName return filePath, srcName
return False, line[line.find(":")+2 : line.find(" ====")] return False, line[line.find(":")+2 : line.find(" ====")]
# expects the first line of lines to be "==== Source: sourceName ====" # expects the first line of lines to be "==== Source: sourceName ===="
# writes the following source into a file named sourceName # writes the following source into a file named sourceName
def writeSourceToFile(lines): def writeSourceToFile(lines):
@ -45,18 +56,29 @@ def writeSourceToFile(lines):
writeSourceToFile(lines[1+idx:]) writeSourceToFile(lines[1+idx:])
break break
if __name__ == '__main__': if __name__ == '__main__':
filePath = sys.argv[1] filePath = sys.argv[1]
# decide if file has multiple sources sys.excepthook = uncaught_exception_hook
lines = open(filePath, mode='r', encoding='utf8').read().splitlines()
if lines[0][:12] == "==== Source:":
hasMultipleSources = True
writeSourceToFile(lines)
if hasMultipleSources: try:
srcString = "" # decide if file has multiple sources
for src in createdSources: lines = open(filePath, mode='r', encoding='utf8').read().splitlines()
srcString += src + ' ' if lines[0][:12] == "==== Source:":
print(srcString) hasMultipleSources = True
else: writeSourceToFile(lines)
sys.exit(1)
if hasMultipleSources:
srcString = ""
for src in createdSources:
srcString += src + ' '
print(srcString)
sys.exit(0)
else:
sys.exit(1)
except UnicodeDecodeError as ude:
print("UnicodeDecodeError in '" + filePath + "': " + str(ude))
print("This is expected for some tests containing invalid utf8 sequences. "
"Exception will be ignored.")
sys.exit(2)

View File

@ -2,7 +2,11 @@
set -e set -e
ROOT_DIR=$(readlink -f "$(dirname "$0")"/..) READLINK=readlink
if [[ "$OSTYPE" == "darwin"* ]]; then
READLINK=greadlink
fi
ROOT_DIR=$(${READLINK} -f "$(dirname "$0")"/..)
WORKDIR="${ROOT_DIR}/build/antlr" WORKDIR="${ROOT_DIR}/build/antlr"
ANTLR_JAR="${ROOT_DIR}/build/deps/antlr4.jar" ANTLR_JAR="${ROOT_DIR}/build/deps/antlr4.jar"
ANTLR_JAR_URI="https://www.antlr.org/download/antlr-4.8-complete.jar" ANTLR_JAR_URI="https://www.antlr.org/download/antlr-4.8-complete.jar"
@ -54,7 +58,7 @@ failed_count=0
test_file() test_file()
{ {
local SOL_FILE local SOL_FILE
SOL_FILE="$(readlink -m "${1}")" SOL_FILE="$(${READLINK} -m "${1}")"
local cur=${2} local cur=${2}
local max=${3} local max=${3}
local solOrYul=${4} local solOrYul=${4}