@@ -75,11 +75,7 @@ function Ast_ImportExportEquivalence
75
75
cat ./obtained.json >&2
76
76
return 1
77
77
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
83
79
then
84
80
FAILED=$(( FAILED + 1 ))
85
81
fi
@@ -101,63 +97,67 @@ function JsonEvmAsm_ImportExportEquivalence
101
97
cat expected.error >&2
102
98
UNCOMPILABLE=$(( UNCOMPILABLE + 1 ))
103
99
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[@]} "
106
109
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
111
112
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
114
117
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
136
124
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"
139
131
then
140
- printError
141
- printError " $sol_file "
142
- cat obtained_direct_import_export.error >&2
132
+ _TESTED=
143
133
FAILED=$(( FAILED + 1 ))
144
134
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
155
135
fi
136
+ done
137
+ done
156
138
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
158
147
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
+
161
161
if [ -n " ${_TESTED} " ]
162
162
then
163
163
TESTED=$(( TESTED + 1 ))
0 commit comments