@@ -44,7 +44,13 @@ function parseFile(filename, recover, env) {
44
44
let args = [ "-print" , "ml" ] ;
45
45
if ( recover ) args . push ( "-recover" ) ;
46
46
args . push ( filename ) ;
47
- return env ? cp . spawnSync ( parser , args , { env } ) : cp . spawnSync ( parser , args ) ;
47
+ let result = env ? cp . spawnSync ( parser , args , { env } ) : cp . spawnSync ( parser , args ) ;
48
+
49
+ return {
50
+ result : result . stdout . toString ( ) ,
51
+ status : result . status ,
52
+ errorOutput : result . stderr
53
+ }
48
54
}
49
55
50
56
function parseOcamlFileToNapkin ( filename ) {
@@ -154,7 +160,11 @@ function printFile(filename) {
154
160
155
161
case "reason" :
156
162
parserSrc = "re" ;
157
- return parseReasonFileToNapkin ( filename , 80 ) ;
163
+ return {
164
+ result : parseReasonFileToNapkin ( filename , 80 ) ,
165
+ status : 0 ,
166
+ errorOutput : ""
167
+ } ;
158
168
break ;
159
169
160
170
case "rescript" :
@@ -173,7 +183,13 @@ function printFile(filename) {
173
183
174
184
args . push ( filename ) ;
175
185
176
- return cp . spawnSync ( parser , args ) . stdout . toString ( "utf8" ) ;
186
+ let result = cp . spawnSync ( parser , args ) ;
187
+
188
+ return {
189
+ result : result . stdout . toString ( "utf8" ) ,
190
+ status : result . status ,
191
+ errorOutput : result . stderr
192
+ }
177
193
}
178
194
179
195
/* Parser error output format:
@@ -196,16 +212,27 @@ global.runPrinter = (dirname) => {
196
212
}
197
213
198
214
test ( base , ( ) => {
199
- let napkin = printFile ( filename ) ;
200
- expect ( napkin ) . toMatchSnapshot ( ) ;
215
+ let { result, errorOutput, status} = printFile ( filename ) ;
216
+ if ( status > 0 ) {
217
+ let msg = `Test from file: ${ filename } failed with error output:
218
+
219
+ ------------ BEGIN ------------
220
+ ${ errorOutput }
221
+ ------------- END -------------
222
+
223
+ Make sure the test input is syntactically valid.` ;
224
+ fail ( msg ) ;
225
+ } else {
226
+ expect ( result ) . toMatchSnapshot ( ) ;
227
+ }
201
228
202
229
if ( process . env . ROUNDTRIP_TEST ) {
203
230
let intf = isInterface ( filename ) ;
204
231
let sexpAst = parseFileToSexp ( filename ) ;
205
- let napkin2 = parseNapkinStdinToNapkin ( napkin , intf , 80 ) ;
206
- let napkinSexpAst = parseNapkinStdinToSexp ( napkin , intf ) ;
207
- expect ( sexpAst ) . toEqual ( napkinSexpAst ) ;
208
- expect ( napkin ) . toEqual ( napkin2 ) ;
232
+ let result2 = parseNapkinStdinToNapkin ( result , intf , 80 ) ;
233
+ let resultSexpAst = parseNapkinStdinToSexp ( result , intf ) ;
234
+ expect ( sexpAst ) . toEqual ( resultSexpAst ) ;
235
+ expect ( result ) . toEqual ( result2 ) ;
209
236
}
210
237
} ) ;
211
238
} ) ;
@@ -219,20 +246,31 @@ global.runParser = (dirname, recover = false, showError = false, env) => {
219
246
}
220
247
221
248
test ( base , ( ) => {
222
- let res = parseFile ( filename , recover , env ) ;
223
- let parsetree = res . stdout . toString ( ) ;
224
- let output = "" ;
225
- if ( showError ) {
226
- output += `=====Parsetree==========================================\n` ;
227
- output += `${ parsetree } \n` ;
228
- output += `=====Errors=============================================\n` ;
229
- output += `${ makeReproducibleFilename ( res . stderr . toString ( ) ) } \n` ;
230
- output += `========================================================` ;
249
+ let { result, errorOutput, status} = parseFile ( filename , recover , env ) ;
250
+ if ( status > 0 ) {
251
+ let msg = `Test from file: ${ filename } failed with error output:
252
+
253
+ ------------ BEGIN ------------
254
+ ${ errorOutput }
255
+ ------------- END -------------
256
+
257
+ Make sure the test input is syntactically valid or run your test suite with 'recover' set to true.` ;
258
+ fail ( msg ) ;
231
259
} else {
232
- output = parsetree ;
260
+ let parsetree = result ;
261
+ let output = "" ;
262
+ if ( showError ) {
263
+ output += `=====Parsetree==========================================\n` ;
264
+ output += `${ parsetree } \n` ;
265
+ output += `=====Errors=============================================\n` ;
266
+ output += `${ makeReproducibleFilename ( errorOutput . toString ( ) ) } \n` ;
267
+ output += `========================================================` ;
268
+ } else {
269
+ output = parsetree ;
270
+ }
271
+
272
+ expect ( output ) . toMatchSnapshot ( ) ;
233
273
}
234
-
235
- expect ( output ) . toMatchSnapshot ( ) ;
236
274
} ) ;
237
275
} ) ;
238
276
} ;
0 commit comments