@@ -53,7 +53,7 @@ if [[ "$(find . -maxdepth 0 -type d -empty)" == "" ]]; then
53
53
fail " Test directory not empty. Skipping!"
54
54
fi
55
55
56
- function Ast_ImportExportEquivalence
56
+ function ast_import_export_equivalence
57
57
{
58
58
local sol_file=" $1 "
59
59
local input_files=" $2 "
@@ -84,7 +84,7 @@ function Ast_ImportExportEquivalence
84
84
rm -f stderr.txt
85
85
}
86
86
87
- function JsonEvmAsm_ImportExportEquivalence
87
+ function json_evm_asm_import_export_equivalence
88
88
{
89
89
local sol_file=" $1 "
90
90
local input_files=" $2 "
@@ -111,106 +111,94 @@ function JsonEvmAsm_ImportExportEquivalence
111
111
done
112
112
113
113
assembly=$( cat expected.asm.json)
114
- if [ " $assembly " != " " ] && [ " $assembly " != " null" ]
114
+ [[ $assembly != " " && $assembly != " null" ]] || continue
115
+
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
115
117
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
117
- then
118
- printError
119
- printError " $sol_file "
120
- cat obtained.error >&2
121
- FAILED=$(( FAILED + 1 ))
122
- return 0
123
- fi
118
+ printError
119
+ printError " $sol_file "
120
+ cat obtained.error >&2
121
+ FAILED=$(( FAILED + 1 ))
122
+ return 0
123
+ fi
124
124
125
- for output in " ${outputs[@]} "
125
+ for output in " ${outputs[@]} "
126
+ do
127
+ for obtained_contract in $( jq ' .contracts | keys | .[]' obtained.json 2> /dev/null)
126
128
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"
131
- then
132
- _TESTED=
133
- FAILED=$(( FAILED + 1 ))
134
- return 0
135
- fi
136
- done
129
+ jq --raw-output " .contracts.${obtained_contract} .\" ${output} \" " obtained.json > " obtained.${output} .json"
130
+ if ! diff_files " expected.${output} .json" " obtained.${output} .json"
131
+ then
132
+ _TESTED=
133
+ FAILED=$(( FAILED + 1 ))
134
+ return 0
135
+ fi
137
136
done
137
+ done
138
138
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
147
- 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
147
+ fi
148
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
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
158
157
fi
159
158
done
160
159
161
- if [ -n " ${ _TESTED} " ]
160
+ if [[ $ _TESTED == " " ] ]
162
161
then
163
162
TESTED=$(( TESTED + 1 ))
164
163
fi
165
164
}
166
165
167
- # function tests whether exporting and importing again leaves the JSON ast unchanged
166
+ # function tests whether exporting and importing again is equivalent.
168
167
# Results are recorded by adding to FAILED or UNCOMPILABLE.
169
- # Also, in case of a mismatch a diff and the respective ASTs are printed
168
+ # Also, in case of a mismatch a diff is printed
170
169
# Expected parameters:
171
170
# $1 name of the file to be exported and imported
172
171
# $2 any files needed to do so that might be in parent directories
173
172
function testImportExportEquivalence {
174
173
local sol_file=" $1 "
175
174
local input_files=" $2 "
176
- if $SOLC --bin " ${input_files} " > /dev/null 2>&1
175
+ if " $SOLC " --bin " ${input_files} " > /dev/null 2>&1
177
176
then
178
- ! [[ -e stderr.txt ]] || { fail " stderr.txt already exists. Refusing to overwrite." ; }
179
-
180
- if [[ $IMPORT_TEST_TYPE == " ast" ]]
181
- then
182
- Ast_ImportExportEquivalence " ${sol_file} " " ${input_files} "
183
- elif [[ $IMPORT_TEST_TYPE == " evm-assembly" ]]
184
- then
185
- JsonEvmAsm_ImportExportEquivalence " ${sol_file} " " ${input_files} "
186
- else
187
- fail " Unknown import test type. Aborting."
188
- fi
177
+ ! [[ -e stderr.txt ]] || fail " stderr.txt already exists. Refusing to overwrite."
178
+ case " $IMPORT_TEST_TYPE " in
179
+ ast) ast_import_export_equivalence " ${sol_file} " " ${input_files} " ;;
180
+ evm-assembly) json_evm_asm_import_export_equivalence " ${sol_file} " " ${input_files} " ;;
181
+ * ) fail " Unknown import test type. Aborting." ;;
182
+ esac
189
183
else
190
184
UNCOMPILABLE=$(( UNCOMPILABLE + 1 ))
191
185
fi
192
186
}
193
187
194
188
WORKINGDIR=$PWD
195
- NSOURCES=0
196
189
197
190
command_available " ${SOLC} " --version
198
191
command_available jq --version
199
192
200
- # for solfile in $(find $DEV_DIR -name *.sol)
193
+ case " $IMPORT_TEST_TYPE " in
194
+ ast) TEST_DIRS=(" ${SYNTAXTESTS_DIR} " " ${ASTJSONTESTS_DIR} " ) ;;
195
+ evm-assembly) TEST_DIRS=(" ${SYNTAXTESTS_DIR} " " ${SEMANTICTESTS_DIR} " ) ;;
196
+ * ) fail " Unknown import test type. Aborting. Please specify ${0} [ast|evm-assembly]." ;;
197
+ esac
198
+
201
199
# boost_filesystem_bug specifically tests a local fix for a boost::filesystem
202
200
# bug. Since the test involves a malformed path, there is no point in running
203
- # AST tests on it. See https://github.com/boostorg/filesystem/issues/176
204
- if [[ $IMPORT_TEST_TYPE == " ast" ]]
205
- then
206
- TEST_DIRS=(" ${SYNTAXTESTS_DIR} " " ${ASTJSONTESTS_DIR} " )
207
- elif [[ $IMPORT_TEST_TYPE == " evm-assembly" ]]
208
- then
209
- TEST_DIRS=(" ${SYNTAXTESTS_DIR} " " ${SEMANTICTESTS_DIR} " )
210
- else
211
- fail " Unknown import test type. Aborting. Please specify ${0} [ast|evm-assembly]."
212
- fi
213
-
201
+ # tests on it. See https://github.com/boostorg/filesystem/issues/176
214
202
IMPORT_TEST_FILES=$( find " ${TEST_DIRS[@]} " -name " *.sol" -and -not -name " boost_filesystem_bug.sol" )
215
203
216
204
NSOURCES=" $( echo " $IMPORT_TEST_FILES " | wc -l) "
227
215
OUTPUT=$( " $SPLITSOURCES " " $solfile " )
228
216
SPLITSOURCES_RC=$?
229
217
set -e
230
- if [ ${SPLITSOURCES_RC} == 0 ]
218
+ if [[ ${SPLITSOURCES_RC} == 0 ] ]
231
219
then
232
- OIFS=${IFS}
233
220
IFS=' ' read -ra OUTPUT_ARRAY <<< " ${OUTPUT}"
234
- IFS=${OIFS}
235
221
NSOURCES=$(( NSOURCES - 1 + ${# OUTPUT_ARRAY[@]} ))
236
- testImportExportEquivalence " $solfile " " ${OUTPUT [@]} "
222
+ testImportExportEquivalence " $solfile " " ${OUTPUT_ARRAY [@]} "
237
223
elif [ ${SPLITSOURCES_RC} == 1 ]
238
224
then
239
225
testImportExportEquivalence " $solfile " " $solfile "
242
228
# The script will exit with return code 2, if an UnicodeDecodeError occurred.
243
229
# This is the case if e.g. some tests are using invalid utf-8 sequences. We will ignore
244
230
# these errors, but print the actual output of the script.
245
- echo >&2
246
- printError " \n${OUTPUT[*]} \n"
247
- echo >&2
231
+ printError " \n\n${OUTPUT} \n\n"
248
232
testImportExportEquivalence " $solfile " " $solfile "
249
233
else
250
234
# All other return codes will be treated as critical errors. The script will exit.
251
- echo >&2
252
- printError " \nGot unexpected return code ${SPLITSOURCES_RC} from ${SPLITSOURCES} . Aborting."
253
- echo >&2
254
- printError " \n${OUTPUT[*]} \n"
255
- echo >&2
235
+ printError " \n\nGot unexpected return code ${SPLITSOURCES_RC} from ${SPLITSOURCES} . Aborting."
236
+ printError " \n\n${OUTPUT} \n\n"
256
237
257
238
cd " $WORKINGDIR "
258
239
# Delete temporary files
0 commit comments