From 3bd071d4e4e75de435b88c6649d904677fee0edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 17 Nov 2020 17:39:43 +0100 Subject: [PATCH] Simplify error handling --- scripts/ASTImportTest.sh | 32 +++++++------------------------- scripts/splitSources.py | 12 +----------- test/stopAfterParseTests.sh | 25 +++++-------------------- 3 files changed, 13 insertions(+), 56 deletions(-) diff --git a/scripts/ASTImportTest.sh b/scripts/ASTImportTest.sh index d6d21ab1c..c1c808476 100755 --- a/scripts/ASTImportTest.sh +++ b/scripts/ASTImportTest.sh @@ -104,32 +104,14 @@ do FILETMP=$(mktemp -d) cd "$FILETMP" - set +e + # NOTE: The command returns the name of the input file if it's not a multi-source file OUTPUT=$("$SPLITSOURCES" "$solfile") - SPLITSOURCES_RC=$? - set -e - if [ ${SPLITSOURCES_RC} == 0 ] - then - # echo $OUTPUT - NSOURCES=$((NSOURCES - 1)) - for i in $OUTPUT; - do - testImportExportEquivalence "$i" "$OUTPUT" - NSOURCES=$((NSOURCES + 1)) - done - elif [ ${SPLITSOURCES_RC} == 1 ] - then - 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." - - cd "$WORKINGDIR" - # Delete temporary files - rm -rf "$FILETMP" - - exit 1 - fi + NSOURCES=$((NSOURCES - 1)) + while IFS="" read -r current_file_name + do + testImportExportEquivalence "$current_file_name" "$OUTPUT" + NSOURCES=$((NSOURCES + 1)) + done <<< "$OUTPUT" cd "$WORKINGDIR" # Delete temporary files diff --git a/scripts/splitSources.py b/scripts/splitSources.py index e20f59141..dd2db8d73 100755 --- a/scripts/splitSources.py +++ b/scripts/splitSources.py @@ -17,14 +17,6 @@ hasMultipleSources = False 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)), file=sys.stderr) - sys.exit(3) - - def extractSourceName(line): if line.find("/") > -1: filePath = line[13: line.rindex("/")] @@ -57,7 +49,6 @@ def writeSourceToFile(lines): if __name__ == '__main__': filePath = sys.argv[1] - sys.excepthook = uncaught_exception_hook # decide if file has multiple sources with open(filePath, mode='rb', encoding='utf8', newline='') as f: @@ -71,6 +62,5 @@ if __name__ == '__main__': for src in createdSources: srcString += src + ' ' print(srcString) - sys.exit(0) else: - sys.exit(1) + print(filePath) diff --git a/test/stopAfterParseTests.sh b/test/stopAfterParseTests.sh index 77d1c6601..9c9738ea9 100755 --- a/test/stopAfterParseTests.sh +++ b/test/stopAfterParseTests.sh @@ -38,27 +38,12 @@ function testFile } while read -r file; do - set +e - OUTPUT=$($SPLITSOURCES "$file") - RETURN_CODE=$? - set -e - FAILED=0 + # NOTE: The command returns the name of the input file if it's not a multi-source file + OUTPUT="$($SPLITSOURCES "$file")" - if [ $RETURN_CODE -eq 0 ] - then - # shellcheck disable=SC2086 - testFile $OUTPUT - FAILED=$? - rm -r "${FILETMP:?}"/* - elif [ $RETURN_CODE -eq 1 ] - then - testFile "$file" - FAILED=$? - else - # NOTE: The split script is expected to print error details to stderr in this case. - echo "$SPLITSOURCES exited with code $RETURN_CODE while processing $file." - exit 3 - fi + testFile "$OUTPUT" + FAILED=$? + rm -r "${FILETMP:?}"/* 2> /dev/null || true if [ $FAILED -eq 1 ] then