1
1
import tape from 'tape' ;
2
2
import spawn from 'tape-spawn' ;
3
+ import rimraf from 'rimraf' ;
3
4
import * as path from 'path' ;
4
5
import solc from '../' ;
5
6
7
+ const dist = path . resolve ( __dirname , '..' ) ;
8
+ const solcjs = path . join ( dist , 'solc.js' ) ;
9
+
10
+ function clean ( ) {
11
+ rimraf . sync ( `${ dist } /*{.bin,.abi}` ) ;
12
+ }
13
+
6
14
tape ( 'CLI' , function ( t ) {
7
15
t . test ( '--version' , function ( st ) {
8
- const spt = spawn ( st , './solc.js --version' ) ;
16
+ const spt = spawn ( st , `node ${ solcjs } --version` ) ;
9
17
spt . stdout . match ( solc . version ( ) + '\n' ) ;
10
18
spt . stdout . match ( / ^ \s * [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + ( - [ a - z A - Z 0 - 9 . ] + ) ? \+ c o m m i t \. [ 0 - 9 a - f ] + ( [ a - z A - Z 0 - 9 . - ] + ) ? \s * $ / ) ;
11
19
spt . stderr . empty ( ) ;
12
20
spt . end ( ) ;
13
21
} ) ;
14
22
15
23
t . test ( 'no parameters' , function ( st ) {
16
- const spt = spawn ( st , './solc.js' ) ;
24
+ const spt = spawn ( st , `node ${ solcjs } ` ) ;
17
25
spt . stderr . match ( / ^ M u s t p r o v i d e a f i l e / ) ;
18
26
spt . end ( ) ;
19
27
} ) ;
20
28
21
29
t . test ( 'no mode specified' , function ( st ) {
22
- const spt = spawn ( st , './solc.js test/resources/fixtureSmoke.sol' ) ;
30
+ const spt = spawn ( st , `node ${ solcjs } test/resources/fixtureSmoke.sol` ) ;
23
31
spt . stderr . match ( / ^ I n v a l i d o p t i o n s e l e c t e d / ) ;
24
32
spt . end ( ) ;
25
33
} ) ;
26
34
27
35
t . test ( '--bin' , function ( st ) {
28
- const spt = spawn ( st , './solc.js --bin test/resources/fixtureSmoke.sol' ) ;
36
+ const spt = spawn ( st , `node ${ solcjs } --bin test/resources/fixtureSmoke.sol` ) ;
29
37
spt . stderr . empty ( ) ;
30
38
spt . succeeds ( ) ;
31
39
spt . end ( ) ;
40
+ st . teardown ( ( ) => { clean ( ) ; } ) ;
32
41
} ) ;
33
42
34
43
t . test ( '--bin --optimize' , function ( st ) {
35
- const spt = spawn ( st , './solc.js --bin --optimize test/resources/fixtureSmoke.sol' ) ;
44
+ const spt = spawn ( st , `node ${ solcjs } --bin --optimize test/resources/fixtureSmoke.sol` ) ;
36
45
spt . stderr . empty ( ) ;
37
46
spt . succeeds ( ) ;
38
47
spt . end ( ) ;
48
+ st . teardown ( ( ) => { clean ( ) ; } ) ;
39
49
} ) ;
40
50
41
51
t . test ( '--bin --optimize-runs 666' , function ( st ) {
42
- const spt = spawn ( st , './solc.js --bin --optimize-runs 666 test/resources/fixtureSmoke.sol' ) ;
52
+ const spt = spawn ( st , `node ${ solcjs } --bin --optimize-runs 666 test/resources/fixtureSmoke.sol` ) ;
43
53
spt . stderr . empty ( ) ;
44
54
spt . succeeds ( ) ;
45
55
spt . end ( ) ;
56
+ st . teardown ( ( ) => { clean ( ) ; } ) ;
46
57
} ) ;
47
58
48
59
t . test ( '--bin --optimize-runs not-a-number' , function ( st ) {
49
- const spt = spawn ( st , './solc.js --bin --optimize-runs not-a-number test/resources/fixtureSmoke.sol' ) ;
60
+ const spt = spawn ( st , `node ${ solcjs } --bin --optimize-runs not-a-number test/resources/fixtureSmoke.sol` ) ;
50
61
spt . stderr . match ( / ^ e r r o r : o p t i o n ' - - o p t i m i z e - r u n s < o p t i m i z e - r u n s > ' a r g u m e n t ' n o t - a - n u m b e r ' i s i n v a l i d / ) ;
51
62
spt . end ( ) ;
52
63
} ) ;
53
64
54
65
t . test ( 'invalid file specified' , function ( st ) {
55
- const spt = spawn ( st , './solc.js --bin test/fileNotFound.sol' ) ;
66
+ const spt = spawn ( st , `node ${ solcjs } --bin test/fileNotFound.sol` ) ;
56
67
spt . stderr . match ( / ^ E r r o r r e a d i n g / ) ;
57
68
spt . end ( ) ;
58
69
} ) ;
59
70
60
71
t . test ( 'incorrect source source' , function ( st ) {
61
- const spt = spawn ( st , './solc.js --bin test/resources/fixtureIncorrectSource.sol' ) ;
72
+ const spt = spawn ( st , `node ${ solcjs } --bin test/resources/fixtureIncorrectSource.sol` ) ;
62
73
spt . stderr . match ( / S y n t a x E r r o r : I n v a l i d p r a g m a " c o n t r a c t " / ) ;
63
74
spt . end ( ) ;
64
75
} ) ;
65
76
66
77
t . test ( '--abi' , function ( st ) {
67
- const spt = spawn ( st , './solc.js --abi test/resources/fixtureSmoke.sol' ) ;
78
+ const spt = spawn ( st , `node ${ solcjs } --abi test/resources/fixtureSmoke.sol` ) ;
68
79
spt . stderr . empty ( ) ;
69
80
spt . succeeds ( ) ;
70
81
spt . end ( ) ;
82
+ st . teardown ( ( ) => { clean ( ) ; } ) ;
71
83
} ) ;
72
84
73
85
t . test ( '--bin --abi' , function ( st ) {
74
- const spt = spawn ( st , './solc.js --bin --abi test/resources/fixtureSmoke.sol' ) ;
86
+ const spt = spawn ( st , `node ${ solcjs } --bin --abi test/resources/fixtureSmoke.sol` ) ;
75
87
spt . stderr . empty ( ) ;
76
88
spt . succeeds ( ) ;
77
89
spt . end ( ) ;
90
+ st . teardown ( ( ) => { clean ( ) ; } ) ;
78
91
} ) ;
79
92
80
93
t . test ( 'no base path' , function ( st ) {
81
94
const spt = spawn (
82
95
st ,
83
- './solc.js --bin ' +
84
- ' test/resources/importA.sol ' +
85
- ' ./test/resources//importA.sol ' +
86
- path . resolve ( 'test/resources/importA.sol' )
96
+ `node ${ solcjs } --bin \
97
+ test/resources/importA.sol \
98
+ ./test/resources//importA.sol \
99
+ ${ path . resolve ( 'test/resources/importA.sol' ) } `
87
100
) ;
88
101
spt . stderr . empty ( ) ;
89
102
spt . succeeds ( ) ;
90
103
spt . end ( ) ;
104
+ st . teardown ( ( ) => { clean ( ) ; } ) ;
91
105
} ) ;
92
106
93
107
t . test ( 'relative base path' , function ( st ) {
@@ -96,65 +110,69 @@ tape('CLI', function (t) {
96
110
// by the import callback when it appends the base path back.
97
111
const spt = spawn (
98
112
st ,
99
- './solc.js --bin --base-path test/resources ' +
100
- ' test/resources/importA.sol ' +
101
- ' ./test/resources//importA.sol ' +
102
- path . resolve ( 'test/resources/importA.sol' )
113
+ `node ${ solcjs } --bin --base-path test/resources \
114
+ test/resources/importA.sol \
115
+ ./test/resources//importA.sol \
116
+ ${ path . resolve ( 'test/resources/importA.sol' ) } `
103
117
) ;
104
118
spt . stderr . empty ( ) ;
105
119
spt . succeeds ( ) ;
106
120
spt . end ( ) ;
121
+ st . teardown ( ( ) => { clean ( ) ; } ) ;
107
122
} ) ;
108
123
109
124
t . test ( 'relative non canonical base path' , function ( st ) {
110
125
const spt = spawn (
111
126
st ,
112
- './solc.js --bin --base-path ./test/resources ' +
113
- ' test/resources/importA.sol ' +
114
- ' ./test/resources//importA.sol ' +
115
- path . resolve ( 'test/resources/importA.sol' )
127
+ `node ${ solcjs } --bin --base-path ./test/resources \
128
+ test/resources/importA.sol \
129
+ ./test/resources//importA.sol \
130
+ ${ path . resolve ( 'test/resources/importA.sol' ) } `
116
131
) ;
117
132
spt . stderr . empty ( ) ;
118
133
spt . succeeds ( ) ;
119
134
spt . end ( ) ;
135
+ st . teardown ( ( ) => { clean ( ) ; } ) ;
120
136
} ) ;
121
137
122
138
t . test ( 'absolute base path' , function ( st ) {
123
139
const spt = spawn (
124
140
st ,
125
- './solc.js --bin --base-path ' + path . resolve ( 'test/resources' ) + ' ' +
126
- ' test/resources/importA.sol ' +
127
- ' ./test/resources//importA.sol ' +
128
- path . resolve ( 'test/resources/importA.sol' )
141
+ `node ${ solcjs } --bin --base-path ${ path . resolve ( 'test/resources' ) } \
142
+ test/resources/importA.sol \
143
+ ./test/resources//importA.sol \
144
+ ${ path . resolve ( 'test/resources/importA.sol' ) } `
129
145
) ;
130
146
spt . stderr . empty ( ) ;
131
147
spt . succeeds ( ) ;
132
148
spt . end ( ) ;
149
+ st . teardown ( ( ) => { clean ( ) ; } ) ;
133
150
} ) ;
134
151
135
152
t . test ( 'include paths' , function ( st ) {
136
153
const spt = spawn (
137
154
st ,
138
- './solc.js --bin ' +
139
- ' test/resources/importCallback/base/contractB.sol ' +
140
- ' test/resources/importCallback/includeA/libY.sol ' +
141
- ' ./test/resources/importCallback/includeA//libY.sol ' +
142
- path . resolve ( 'test/resources/importCallback/includeA/libY.sol' ) + ' ' +
143
- ' --base-path test/resources/importCallback/base ' +
144
- ' --include-path test/resources/importCallback/includeA ' +
145
- ' --include-path ' + path . resolve ( 'test/resources/importCallback/includeB/' )
155
+ `node ${ solcjs } --bin \
156
+ test/resources/importCallback/base/contractB.sol \
157
+ test/resources/importCallback/includeA/libY.sol \
158
+ ./test/resources/importCallback/includeA//libY.sol \
159
+ ${ path . resolve ( 'test/resources/importCallback/includeA/libY.sol' ) } \
160
+ --base-path test/resources/importCallback/base \
161
+ --include-path test/resources/importCallback/includeA \
162
+ --include-path ${ path . resolve ( 'test/resources/importCallback/includeB/' ) } `
146
163
) ;
147
164
spt . stderr . empty ( ) ;
148
165
spt . succeeds ( ) ;
149
166
spt . end ( ) ;
167
+ st . teardown ( ( ) => { clean ( ) ; } ) ;
150
168
} ) ;
151
169
152
170
t . test ( 'include paths without base path' , function ( st ) {
153
171
const spt = spawn (
154
172
st ,
155
- './solc.js --bin ' +
156
- ' test/resources/importCallback/contractC.sol ' +
157
- ' --include-path test/resources/importCallback/includeA'
173
+ `node ${ solcjs } --bin \
174
+ test/resources/importCallback/contractC.sol \
175
+ --include-path test/resources/importCallback/includeA`
158
176
) ;
159
177
spt . stderr . match ( / - - i n c l u d e - p a t h o p t i o n r e q u i r e s a n o n - e m p t y b a s e p a t h \. / ) ;
160
178
spt . fails ( ) ;
@@ -164,10 +182,10 @@ tape('CLI', function (t) {
164
182
t . test ( 'empty include paths' , function ( st ) {
165
183
const spt = spawn (
166
184
st ,
167
- './solc.js --bin ' +
168
- ' test/resources/importCallback/contractC.sol ' +
169
- ' --base-path test/resources/importCallback/base ' +
170
- ' --include-path='
185
+ `node ${ solcjs } --bin \
186
+ test/resources/importCallback/contractC.sol \
187
+ --base-path test/resources/importCallback/base \
188
+ --include-path=`
171
189
) ;
172
190
spt . stderr . match ( / E m p t y v a l u e s a r e n o t a l l o w e d i n - - i n c l u d e - p a t h \. / ) ;
173
191
spt . fails ( ) ;
@@ -190,7 +208,7 @@ tape('CLI', function (t) {
190
208
}
191
209
}
192
210
} ;
193
- const spt = spawn ( st , './solc.js --standard-json' ) ;
211
+ const spt = spawn ( st , `node ${ solcjs } --standard-json` ) ;
194
212
spt . stdin . setEncoding ( 'utf-8' ) ;
195
213
spt . stdin . write ( JSON . stringify ( input ) ) ;
196
214
spt . stdin . end ( ) ;
@@ -219,7 +237,7 @@ tape('CLI', function (t) {
219
237
}
220
238
}
221
239
} ;
222
- const spt = spawn ( st , './solc.js --standard-json --base-path test/resources' ) ;
240
+ const spt = spawn ( st , `node ${ solcjs } --standard-json --base-path test/resources` ) ;
223
241
spt . stdin . setEncoding ( 'utf-8' ) ;
224
242
spt . stdin . write ( JSON . stringify ( input ) ) ;
225
243
spt . stdin . end ( ) ;
@@ -245,10 +263,10 @@ tape('CLI', function (t) {
245
263
} ;
246
264
const spt = spawn (
247
265
st ,
248
- './solc.js --standard-json ' +
249
- ' --base-path test/resources/importCallback/base ' +
250
- ' --include-path test/resources/importCallback/includeA ' +
251
- ' --include-path ' + path . resolve ( 'test/resources/importCallback/includeB/' )
266
+ `node ${ solcjs } --standard-json \
267
+ --base-path test/resources/importCallback/base \
268
+ --include-path test/resources/importCallback/includeA \
269
+ --include-path ${ path . resolve ( 'test/resources/importCallback/includeB/' ) } `
252
270
) ;
253
271
spt . stdin . setEncoding ( 'utf-8' ) ;
254
272
spt . stdin . write ( JSON . stringify ( input ) ) ;
0 commit comments