1
1
#! /usr/bin/env bash
2
+ # ------------------------------------------------------------------------------
3
+ # vim:ts=4:et
4
+ # This file is part of solidity.
5
+ #
6
+ # solidity is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # solidity is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with solidity. If not, see <http://www.gnu.org/licenses/>
18
+ #
19
+ # (c) 2016-2022 solidity contributors.
20
+ # ------------------------------------------------------------------------------
2
21
3
22
set -euo pipefail
4
23
IMPORT_TEST_TYPE=" ${1} "
36
55
37
56
function Ast_ImportExportEquivalence
38
57
{
39
- local nth_input_file=" $1 "
40
- IFS=" " read -r -a all_input_files <<< " $2"
41
-
58
+ local sol_file=" $1 "
59
+ local input_files=" $2 "
42
60
# save exported json as expected result (silently)
43
- $SOLC --combined-json ast --pretty-json --json-indent 4 " $nth_input_file " " ${all_input_files[@] }" > expected.json 2> /dev/null
61
+ $SOLC --combined-json ast --pretty-json --json-indent 4 " ${input_files } " > expected.json 2> /dev/null
44
62
# import it, and export it again as obtained result (silently)
45
63
if ! $SOLC --import-ast --combined-json ast --pretty-json --json-indent 4 expected.json > obtained.json 2> stderr.txt
46
64
then
47
65
# For investigating, use exit 1 here so the script stops at the
48
66
# first failing test
49
67
# exit 1
50
68
FAILED=$(( FAILED + 1 ))
51
- printError -e " ERROR: AST reimport failed for input file $nth_input_file "
69
+ printError -e " ERROR: AST reimport failed for input file $sol_file "
52
70
printError
53
71
printError " Compiler stderr:"
54
72
cat ./stderr.txt >&2
@@ -60,11 +78,10 @@ function Ast_ImportExportEquivalence
60
78
set +e
61
79
diff_files expected.json obtained.json
62
80
DIFF=$?
63
- set -euo pipefail
81
+ set -e
64
82
if [[ ${DIFF} != 0 ]]
65
83
then
66
84
FAILED=$(( FAILED + 1 ))
67
- return 2
68
85
fi
69
86
TESTED=$(( TESTED + 1 ))
70
87
rm expected.json obtained.json
@@ -73,15 +90,14 @@ function Ast_ImportExportEquivalence
73
90
74
91
function JsonEvmAsm_ImportExportEquivalence
75
92
{
76
- local nth_input_file=" $1 "
77
- IFS=" " read -r -a all_input_files <<< " $2"
78
-
93
+ local sol_file=" $1 "
94
+ local input_files=" $2 "
79
95
local outputs=( " asm" " bin" " bin-runtime" " opcodes" " srcmap" " srcmap-runtime" )
80
96
local _TESTED=1
81
- if ! $SOLC --combined-json " $( IFS=, ; echo " ${outputs[*]} " ) " --pretty-json --json-indent 4 " $nth_input_file " " ${all_input_files[@] }" > expected.json 2> expected.error
97
+ if ! $SOLC --combined-json " $( IFS=, ; echo " ${outputs[*]} " ) " --pretty-json --json-indent 4 " ${input_files } " > expected.json 2> expected.error
82
98
then
83
99
printError
84
- printError " $nth_input_file "
100
+ printError " $sol_file "
85
101
cat expected.error >&2
86
102
UNCOMPILABLE=$(( UNCOMPILABLE + 1 ))
87
103
return 0
@@ -90,16 +106,16 @@ function JsonEvmAsm_ImportExportEquivalence
90
106
do
91
107
for output in " ${outputs[@]} "
92
108
do
93
- jq --raw-output " .contracts.${contract} .\" ${output} \" " expected.json > " expected.${output} "
109
+ jq --raw-output " .contracts.${contract} .\" ${output} \" " expected.json > " expected.${output} .json "
94
110
done
95
111
96
- assembly=$( cat expected.asm)
112
+ assembly=$( cat expected.asm.json )
97
113
if [ " $assembly " != " " ] && [ " $assembly " != " null" ]
98
114
then
99
- if ! $SOLC --combined-json bin,bin-runtime,opcodes,asm,srcmap,srcmap-runtime --pretty-json --json-indent 4 --import-asm-json expected.asm > obtained.json 2> obtained.error
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
100
116
then
101
117
printError
102
- printError " $nth_input_file "
118
+ printError " $sol_file "
103
119
cat obtained.error >&2
104
120
FAILED=$(( FAILED + 1 ))
105
121
return 0
@@ -108,44 +124,41 @@ function JsonEvmAsm_ImportExportEquivalence
108
124
do
109
125
for obtained_contract in $( jq ' .contracts | keys | .[]' obtained.json 2> /dev/null)
110
126
do
111
- jq --raw-output " .contracts.${obtained_contract} .\" ${output} \" " obtained.json > " obtained.${output} "
127
+ jq --raw-output " .contracts.${obtained_contract} .\" ${output} \" " obtained.json > " obtained.${output} .json "
112
128
set +e
113
- diff_files " expected.${output} " " obtained.${output} "
114
- DIFF=$?
115
- set -euo pipefail
116
- if [[ ${DIFF} != 0 ]]
129
+ if ! diff_files " expected.${output} .json" " obtained.${output} .json"
117
130
then
118
131
_TESTED=
119
132
FAILED=$(( FAILED + 1 ))
120
133
return 0
121
134
fi
135
+ set -e
122
136
done
123
137
done
124
138
125
139
# direct export via --asm-json, if imported with --import-asm-json.
126
- if ! $SOLC --asm-json --import-asm-json expected.asm | tail -n+4 > obtained_direct_import_export.json 2> obtained_direct_import_export.error
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
127
141
then
128
142
printError
129
- printError " $nth_input_file "
143
+ printError " $sol_file "
130
144
cat obtained_direct_import_export.error >&2
131
145
FAILED=$(( FAILED + 1 ))
132
146
return 0
133
147
else
134
- for obtained_contract in $( jq ' .contracts | keys | .[]' obtained_direct_import_export.json 2> /dev/null)
135
- do
136
- jq --raw-output " .contracts.${obtained_contract} .\" asm\" " obtained_direct_import_export.json > obtained_direct_import_export.asm
137
- set +e
138
- diff_files " expected.asm" " obtained_direct_import_export.asm"
139
- DIFF=$?
140
- set -euo pipefail
141
- if [[ ${DIFF} != 0 ]]
142
- then
143
- _TESTED=
144
- FAILED=$(( FAILED + 1 ))
145
- return 0
146
- fi
147
- done
148
+ # reformat jsons - yeah, somehow its not generating the same format
149
+ # todo: fix that
150
+ jq . expected.asm.json > expected.asm.json.pretty
151
+ jq . obtained_direct_import_export.json > obtained_direct_import_export.json.pretty
152
+ set +e
153
+ if ! diff_files expected.asm.json.pretty obtained_direct_import_export.json.pretty
154
+ then
155
+ _TESTED=
156
+ FAILED=$(( FAILED + 1 ))
157
+ return 0
158
+ fi
159
+ set -e
148
160
fi
161
+
149
162
fi
150
163
fi
151
164
done
@@ -163,26 +176,20 @@ function JsonEvmAsm_ImportExportEquivalence
163
176
# $1 name of the file to be exported and imported
164
177
# $2 any files needed to do so that might be in parent directories
165
178
function testImportExportEquivalence {
166
- local nth_input_file=" $1 "
167
- IFS=" " read -r -a all_input_files <<< " $2"
168
-
169
- if [ -z ${all_input_files+x} ]
170
- then
171
- all_input_files=( " " )
172
- fi
173
-
174
- if $SOLC --bin " $nth_input_file " " ${all_input_files[@]} " > /dev/null 2>&1
179
+ local sol_file=" $1 "
180
+ local input_files=" $2 "
181
+ if $SOLC --bin " ${input_files} " > /dev/null 2>&1
175
182
then
176
- ! [[ -e stderr.txt ]] || { printError " stderr.txt already exists. Refusing to overwrite." ; exit 1 ; }
183
+ ! [[ -e stderr.txt ]] || { fail " stderr.txt already exists. Refusing to overwrite." ; }
177
184
178
185
if [[ $IMPORT_TEST_TYPE == " ast" ]]
179
186
then
180
- Ast_ImportExportEquivalence " $nth_input_file " " ${all_input_files[@] } "
187
+ Ast_ImportExportEquivalence " ${sol_file} " " ${input_files } "
181
188
elif [[ $IMPORT_TEST_TYPE == " evm-assembly" ]]
182
189
then
183
- JsonEvmAsm_ImportExportEquivalence " $nth_input_file " " ${all_input_files[@] } "
190
+ JsonEvmAsm_ImportExportEquivalence " ${sol_file} " " ${input_files } "
184
191
else
185
- fail " unknown import test type. aborting ."
192
+ fail " Unknown import test type. Aborting ."
186
193
fi
187
194
else
188
195
UNCOMPILABLE=$(( UNCOMPILABLE + 1 ))
@@ -201,7 +208,7 @@ check_executable jq --version
201
208
# AST tests on it. See https://github.com/boostorg/filesystem/issues/176
202
209
if [[ $IMPORT_TEST_TYPE == " ast" ]]
203
210
then
204
- TEST_DIRS=(" $SYNTAXTESTS_DIR " " $ASTJSONTESTS_DIR " )
211
+ TEST_DIRS=(" ${ SYNTAXTESTS_DIR} " " ${ ASTJSONTESTS_DIR} " )
205
212
elif [[ $IMPORT_TEST_TYPE == " evm-assembly" ]]
206
213
then
207
214
TEST_DIRS=(" ${SYNTAXTESTS_DIR} " " ${SEMANTICTESTS_DIR} " )
224
231
set +e
225
232
OUTPUT=$( " $SPLITSOURCES " " $solfile " )
226
233
SPLITSOURCES_RC=$?
227
- set -euo pipefail
234
+ set -e
228
235
if [ ${SPLITSOURCES_RC} == 0 ]
229
236
then
230
237
NSOURCES=$(( NSOURCES - 1 ))
231
- for i in $OUTPUT ;
238
+ # shellcheck disable=SC2034
239
+ for i in $OUTPUT
232
240
do
233
- testImportExportEquivalence " $i " " $OUTPUT "
234
241
NSOURCES=$(( NSOURCES + 1 ))
235
242
done
243
+ testImportExportEquivalence " $solfile " " ${OUTPUT[@]} "
236
244
elif [ ${SPLITSOURCES_RC} == 1 ]
237
245
then
238
- testImportExportEquivalence " $solfile " " "
246
+ testImportExportEquivalence " $solfile " " $solfile "
239
247
elif [ ${SPLITSOURCES_RC} == 2 ]
240
248
then
241
249
# The script will exit with return code 2, if an UnicodeDecodeError occurred.
242
250
# This is the case if e.g. some tests are using invalid utf-8 sequences. We will ignore
243
251
# these errors, but print the actual output of the script.
244
- printError " \n${OUTPUT} \n"
245
- testImportExportEquivalence " $solfile " " "
252
+ echo >&2
253
+ printError " ${OUTPUT} "
254
+ echo >&2
255
+ testImportExportEquivalence " $solfile " " $solfile "
246
256
else
247
257
# All other return codes will be treated as critical errors. The script will exit.
248
- printError " \nGot unexpected return code ${SPLITSOURCES_RC} from ${SPLITSOURCES} . Aborting."
249
- printError " \n${OUTPUT} \n"
258
+ echo >&2
259
+ printError " Got unexpected return code ${SPLITSOURCES_RC} from ${SPLITSOURCES} . Aborting."
260
+ echo >&2
261
+ printError " ${OUTPUT} "
262
+ echo >&2
250
263
251
264
cd " $WORKINGDIR "
252
265
# Delete temporary files
260
273
rm -rf " $FILETMP "
261
274
done
262
275
263
- echo " "
276
+ echo
264
277
265
- if [ " $ FAILED" = 0 ]
278
+ if (( FAILED == 0 ))
266
279
then
267
280
echo " SUCCESS: $TESTED tests passed, $FAILED failed, $UNCOMPILABLE could not be compiled ($NSOURCES sources total)."
268
281
else
0 commit comments