scripts/ImportExportTest.sh: replace scripts/ASTImportTest.sh. - #12809
scripts/ImportExportTest.sh: replace scripts/ASTImportTest.sh.#12809aarlt wants to merge 1 commit into
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
wechman
left a comment
There was a problem hiding this comment.
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.
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.
Is ${1} somehow better than "$1"?
There was a problem hiding this comment.
Nope, not really.. but you're right, this should be "${1}".
There was a problem hiding this comment.
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.
Looks like duplication of lines 124-143. Could you take out this code to the helper function?
There was a problem hiding this comment.
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.
It would be great to have this function divided into smaller pieces since it is quite big by now.
| exit 1 | ||
| fi | ||
|
|
||
| # function tests whether exporting and importing again leaves the JSON ast unchanged |
There was a problem hiding this comment.
I think the comment may require an update.
|
Moved to #12834. Closing. |
cameel
left a comment
There was a problem hiding this comment.
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.
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.
| 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.
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.
Let's use the modern Bash variant.
| if [ "${IMPORT_TEST_TYPE}" == "ast" ] | |
| if [[ $IMPORT_TEST_TYPE == "ast" ]] |
Same in the elif below.
| ( | ||
| cd "$SOLTMPDIR" | ||
| if ! "$REPO_ROOT/scripts/ASTImportTest.sh" | ||
| if ! "$REPO_ROOT/scripts/ImportExportTest.sh" ast |
There was a problem hiding this comment.
| 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.
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.
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.
| 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.
| 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.
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.shwithscripts/ImportExportTest.shscripts/ImportExportTest.shis already prepared to test asm-json import/export, but right now these tests are just not triggered.