-
Notifications
You must be signed in to change notification settings - Fork 6.2k
scripts/ImportExportTest.sh: replace scripts/ASTImportTest.sh. #12809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
8ce386d
to
083d79a
Compare
e4acc25
to
b9504ee
Compare
083d79a
to
6fe5e7e
Compare
f3dd7cd
to
1a0988e
Compare
6fe5e7e
to
24bebf5
Compare
24bebf5
to
ebac6c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have at least one test with asm-json before a merge.
fi | ||
set +e | ||
DIFF="$(diff expected.json obtained.json)" | ||
set +e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be set -e
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's true! That seem to be a typo! Thx!
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
READLINK=greadlink | ||
fi | ||
IMPORT_TEST_TYPE=${1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is ${1}
somehow better than "$1"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, not really.. but you're right, this should be "${1}"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're equivalent but ${}
ensures that the text after the variable name won't be interpreted as a part of that name. Personally, I use the "$x"
form only there's nothing else inside the quotes. If there's extra text, other variables, etc., I always use ${x}
.
jq --raw-output ".contracts.${obtained_contract}.\"asm\"" obtained_direct_import_export.json > obtained_direct_import_export.asm | ||
set +e | ||
DIFF="$(diff expected.asm obtained_direct_import_export.asm)" | ||
set -e | ||
if [ "$DIFF" != "" ] | ||
then | ||
if [ "$DIFFVIEW" == "" ] | ||
then | ||
echo -e "ERROR: JSONS differ for $1: \n $DIFF \n" | ||
echo "Expected:" | ||
cat expected.asm | ||
echo "Obtained:" | ||
cat obtained_direct_import_export.asm | ||
else | ||
# Use user supplied diff view binary | ||
$DIFFVIEW expected.asm obtained_direct_import_export.asm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like duplication of lines 124-143. Could you take out this code to the helper function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True! I will add some helpers.
# Expected parameters: | ||
# $1 name of the file to be exported and imported | ||
# $2 any files needed to do so that might be in parent directories | ||
function testImportExportEquivalence { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to have this function divided into smaller pieces since it is quite big by now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree!
exit 1 | ||
fi | ||
|
||
# function tests whether exporting and importing again leaves the JSON ast unchanged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comment may require an update.
Moved to #12834. Closing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I was in the middle of reviewing this...
Looks like I'll need to move my comments to the new PR.
@@ -1,155 +0,0 @@ | |||
#!/usr/bin/env bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you do the file rename in a separate commit? I think this would help git detect that it's still basically the same script and show a better diff.
set +e | ||
DIFF="$(diff expected.json obtained.json)" | ||
set +e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set +e | |
DIFF="$(diff expected.json obtained.json)" | |
set +e | |
DIFF="$(diff expected.json obtained.json || true)" |
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
READLINK=greadlink | ||
fi | ||
IMPORT_TEST_TYPE=${1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're equivalent but ${}
ensures that the text after the variable name won't be interpreted as a part of that name. Personally, I use the "$x"
form only there's nothing else inside the quotes. If there's extra text, other variables, etc., I always use ${x}
.
then | ||
! [[ -e stderr.txt ]] || { echo "stderr.txt already exists. Refusing to overwrite."; exit 1; } | ||
|
||
if [ "${IMPORT_TEST_TYPE}" == "ast" ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the modern Bash variant.
if [ "${IMPORT_TEST_TYPE}" == "ast" ] | |
if [[ $IMPORT_TEST_TYPE == "ast" ]] |
Same in the elif
below.
SOLTMPDIR=$(mktemp -d) | ||
( | ||
cd "$SOLTMPDIR" | ||
if ! "$REPO_ROOT/scripts/ASTImportTest.sh" | ||
if ! "$REPO_ROOT/scripts/ImportExportTest.sh" ast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ! "$REPO_ROOT/scripts/ImportExportTest.sh" ast | |
if ! "$REPO_ROOT/scripts/importExportTest.sh" ast |
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
READLINK=greadlink | ||
fi | ||
IMPORT_TEST_TYPE=${1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd put commandline argument processing as the first thing in the script. Just after set -e
.
@@ -0,0 +1,302 @@ | |||
#!/usr/bin/env bash | |||
|
|||
set -e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this script work with these?
set -e | |
set -euo pipefail |
I wanted to do that last time I was going through these scripts but I did not have time to test each one individually and make sure it does not break anything. Now that you're rewriting it, it looks like a good opportunity to try this.
# boost_filesystem_bug specifically tests a local fix for a boost::filesystem | ||
# bug. Since the test involves a malformed path, there is no point in running | ||
# AST tests on it. See https://github.com/boostorg/filesystem/issues/176 | ||
if [ "${IMPORT_TEST_TYPE}" == "ast" ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if [ "${IMPORT_TEST_TYPE}" == "ast" ] | |
if [[ $IMPORT_TEST_TYPE == "ast" ]] |
echo "unknown import test type. aborting. please specify $0 [ast|evm-assembly]." | ||
exit 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo "unknown import test type. aborting. please specify $0 [ast|evm-assembly]." | |
exit 1 | |
fail "Unknown import test type. Aborting. Please specify ${0} [ast|evm-assembly]." |
# AST tests on it. See https://github.com/boostorg/filesystem/issues/176 | ||
if [ "${IMPORT_TEST_TYPE}" == "ast" ] | ||
then | ||
IMPORT_TEST_FILES=$(find "${SYNTAXTESTS_DIR}" "${ASTJSONTESTS_DIR}" -name "*.sol" -and -not -name "boost_filesystem_bug.sol") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid repeating the whole command, you could just set the list of dirs here:
IMPORT_TEST_FILES=$(find "${SYNTAXTESTS_DIR}" "${ASTJSONTESTS_DIR}" -name "*.sol" -and -not -name "boost_filesystem_bug.sol") | |
TEST_DIRS=("$SYNTAXTESTS_DIR" "$ASTJSONTESTS_DIR") |
Then have this for both cases:
IMPORT_TEST_FILES=$(find "${TEST_DIRS[@]}" -name "*.sol" -and -not -name "boost_filesystem_bug.sol")
Oh!! Sorry for that! I think there is no need to move the comments.. I will try to integrate your feedback from here on the other PR.. I hope it will not create too much confusion |
Well, you did say on the meeting that you'll be moving this to a bigger PR where tests actually test something so it's my fault. But no worries. Just copying them fortunately was not that bad. They're all in #12834 now (except 1 or 2 that were basically just responses to other comments). |
Replaces part of #12704.
Moved to #12834.
scripts/ASTImportTest.sh
withscripts/ImportExportTest.sh
scripts/ImportExportTest.sh
is already prepared to test asm-json import/export, but right now these tests are just not triggered.