Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

aarlt
Copy link
Member

@aarlt aarlt commented Mar 16, 2022

Replaces part of #12704.
Moved to #12834.

  • replaces scripts/ASTImportTest.sh with scripts/ImportExportTest.sh
  • scripts/ImportExportTest.sh is already prepared to test asm-json import/export, but right now these tests are just not triggered.

@aarlt aarlt force-pushed the import-export-script branch from 8ce386d to 083d79a Compare March 16, 2022 16:52
@aarlt aarlt changed the base branch from develop to asm-json-export March 21, 2022 16:39
@aarlt aarlt marked this pull request as draft March 21, 2022 16:40
@aarlt aarlt force-pushed the asm-json-export branch 5 times, most recently from e4acc25 to b9504ee Compare March 22, 2022 16:00
@aarlt aarlt force-pushed the import-export-script branch from 083d79a to 6fe5e7e Compare March 22, 2022 22:03
@aarlt aarlt force-pushed the asm-json-export branch 2 times, most recently from f3dd7cd to 1a0988e Compare March 23, 2022 20:58
@aarlt aarlt force-pushed the import-export-script branch from 6fe5e7e to 24bebf5 Compare March 23, 2022 20:58
@aarlt aarlt force-pushed the import-export-script branch from 24bebf5 to ebac6c5 Compare March 23, 2022 21:10
Base automatically changed from asm-json-export to develop March 24, 2022 11:13
Copy link
Contributor

@wechman wechman left a 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
Copy link
Contributor

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?

Copy link
Member Author

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}
Copy link
Contributor

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"?

Copy link
Member Author

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}".

Copy link
Member

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}.

Comment on lines +159 to +174
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
Copy link
Contributor

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?

Copy link
Member Author

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 {
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

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.

@aarlt
Copy link
Member Author

aarlt commented Mar 28, 2022

Moved to #12834. Closing.

@aarlt aarlt closed this Mar 28, 2022
Copy link
Member

@cameel cameel left a 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
Copy link
Member

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.

Comment on lines +68 to +70
set +e
DIFF="$(diff expected.json obtained.json)"
set +e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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}
Copy link
Member

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" ]
Copy link
Member

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.

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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}
Copy link
Member

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
Copy link
Member

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?

Suggested change
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" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [ "${IMPORT_TEST_TYPE}" == "ast" ]
if [[ $IMPORT_TEST_TYPE == "ast" ]]

Comment on lines +240 to +241
echo "unknown import test type. aborting. please specify $0 [ast|evm-assembly]."
exit 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")
Copy link
Member

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:

Suggested change
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")

@aarlt
Copy link
Member Author

aarlt commented Mar 28, 2022

Oh, I was in the middle of reviewing this...
Looks like I'll need to move my comments to the new PR.

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

@cameel
Copy link
Member

cameel commented Mar 28, 2022

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants