Skip to content

Commit 1183530

Browse files
committed
Refactorings.
1 parent f5333b3 commit 1183530

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

scripts/ImportExportTest.sh

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,7 @@ function Ast_ImportExportEquivalence
7575
cat ./obtained.json >&2
7676
return 1
7777
fi
78-
set +e
79-
diff_files expected.json obtained.json
80-
DIFF=$?
81-
set -e
82-
if [[ ${DIFF} != 0 ]]
78+
if ! diff_files expected.json obtained.json
8379
then
8480
FAILED=$((FAILED + 1))
8581
fi
@@ -101,63 +97,67 @@ function JsonEvmAsm_ImportExportEquivalence
10197
cat expected.error >&2
10298
UNCOMPILABLE=$((UNCOMPILABLE + 1))
10399
return 0
104-
else
105-
for contract in $(jq '.contracts | keys | .[]' expected.json 2> /dev/null)
100+
fi
101+
102+
# Note that we have some test files, that only consists of free functions.
103+
# Those files doesn't define any contracts, so the resulting json does not define any
104+
# keys. In this case `jq` returns an error like `jq: error: null (null) has no keys`
105+
# to not get spammed by these errors, errors are redirected to /dev/null.
106+
for contract in $(jq '.contracts | keys | .[]' expected.json 2> /dev/null)
107+
do
108+
for output in "${outputs[@]}"
106109
do
107-
for output in "${outputs[@]}"
108-
do
109-
jq --raw-output ".contracts.${contract}.\"${output}\"" expected.json > "expected.${output}.json"
110-
done
110+
jq --raw-output ".contracts.${contract}.\"${output}\"" expected.json > "expected.${output}.json"
111+
done
111112

112-
assembly=$(cat expected.asm.json)
113-
if [ "$assembly" != "" ] && [ "$assembly" != "null" ]
113+
assembly=$(cat expected.asm.json)
114+
if [ "$assembly" != "" ] && [ "$assembly" != "null" ]
115+
then
116+
if ! "${SOLC}" --combined-json bin,bin-runtime,opcodes,asm,srcmap,srcmap-runtime --pretty-json --json-indent 4 --import-asm-json expected.asm.json > obtained.json 2> obtained.error
114117
then
115-
if ! "${SOLC}" --combined-json bin,bin-runtime,opcodes,asm,srcmap,srcmap-runtime --pretty-json --json-indent 4 --import-asm-json expected.asm.json > obtained.json 2> obtained.error
116-
then
117-
printError
118-
printError "$sol_file"
119-
cat obtained.error >&2
120-
FAILED=$((FAILED + 1))
121-
return 0
122-
else
123-
for output in "${outputs[@]}"
124-
do
125-
for obtained_contract in $(jq '.contracts | keys | .[]' obtained.json 2> /dev/null)
126-
do
127-
jq --raw-output ".contracts.${obtained_contract}.\"${output}\"" obtained.json > "obtained.${output}.json"
128-
if ! diff_files "expected.${output}.json" "obtained.${output}.json"
129-
then
130-
_TESTED=
131-
FAILED=$((FAILED + 1))
132-
return 0
133-
fi
134-
done
135-
done
118+
printError
119+
printError "$sol_file"
120+
cat obtained.error >&2
121+
FAILED=$((FAILED + 1))
122+
return 0
123+
fi
136124

137-
# direct export via --asm-json, if imported with --import-asm-json.
138-
if ! "${SOLC}" --asm-json --import-asm-json expected.asm.json --pretty-json --json-indent 4 | tail -n+4 > obtained_direct_import_export.json 2> obtained_direct_import_export.error
125+
for output in "${outputs[@]}"
126+
do
127+
for obtained_contract in $(jq '.contracts | keys | .[]' obtained.json 2> /dev/null)
128+
do
129+
jq --raw-output ".contracts.${obtained_contract}.\"${output}\"" obtained.json > "obtained.${output}.json"
130+
if ! diff_files "expected.${output}.json" "obtained.${output}.json"
139131
then
140-
printError
141-
printError "$sol_file"
142-
cat obtained_direct_import_export.error >&2
132+
_TESTED=
143133
FAILED=$((FAILED + 1))
144134
return 0
145-
else
146-
# reformat jsons using jq.
147-
jq . expected.asm.json > expected.asm.json.pretty
148-
jq . obtained_direct_import_export.json > obtained_direct_import_export.json.pretty
149-
if ! diff_files expected.asm.json.pretty obtained_direct_import_export.json.pretty
150-
then
151-
_TESTED=
152-
FAILED=$((FAILED + 1))
153-
return 0
154-
fi
155135
fi
136+
done
137+
done
156138

157-
fi
139+
# direct export via --asm-json, if imported with --import-asm-json.
140+
if ! "${SOLC}" --asm-json --import-asm-json expected.asm.json --pretty-json --json-indent 4 | tail -n+4 > obtained_direct_import_export.json 2> obtained_direct_import_export.error
141+
then
142+
printError
143+
printError "$sol_file"
144+
cat obtained_direct_import_export.error >&2
145+
FAILED=$((FAILED + 1))
146+
return 0
158147
fi
159-
done
160-
fi
148+
149+
# reformat jsons using jq.
150+
jq . expected.asm.json > expected.asm.json.pretty
151+
jq . obtained_direct_import_export.json > obtained_direct_import_export.json.pretty
152+
if ! diff_files expected.asm.json.pretty obtained_direct_import_export.json.pretty
153+
then
154+
_TESTED=
155+
FAILED=$((FAILED + 1))
156+
return 0
157+
fi
158+
fi
159+
done
160+
161161
if [ -n "${_TESTED}" ]
162162
then
163163
TESTED=$((TESTED + 1))

0 commit comments

Comments
 (0)