@@ -194,8 +194,8 @@ let indentOutputCode = code => {
194194}
195195
196196type error =
197- | ReScript ({ error : string } )
198- | Runtime ({rescript : string , js : string , error : string })
197+ | ReScriptError ( string )
198+ | RuntimeError ({rescript : string , js : string , error : string })
199199
200200let extractDocFromFile = file => {
201201 let toolsBin = Path .join ([Process .cwd (), "cli" , "rescript-tools" ])
@@ -292,7 +292,8 @@ let getCodeBlocks = example => {
292292 -> List .fromArray
293293 -> loop (list {})
294294 -> List .toArray
295- -> Array .join ("\n " )
295+ -> Belt .Array .reverse
296+ -> Array .join ("\n\n " )
296297}
297298
298299let main = async () => {
@@ -303,7 +304,6 @@ let main = async () => {
303304 // Ignore Js modules and RescriptTools for now
304305 -> Array .filter (f => ! String .startsWith (f , "Js" ) && ! String .startsWith (f , "RescriptTools" ))
305306 -> Array .filter (f => f -> String .endsWith (".res" ) || f -> String .endsWith (".resi" ))
306- // ->Array.filter(f => f == "Belt_HashMap.resi")
307307 -> Array .reduce ([], (acc , cur ) => {
308308 let isInterface = cur -> String .endsWith (".resi" )
309309
@@ -312,75 +312,56 @@ let main = async () => {
312312 // If .resi files exists append to array
313313 if ! isInterface && Fs .existsSync (resi ) {
314314 Array .concat (acc , [cur ++ "i" ])
315+ } else if ! Array .includes (acc , cur ) {
316+ Array .concat (acc , [cur ])
315317 } else {
316- let a = ! Array .includes (acc , cur ) ? Array .concat (acc , [cur ]) : acc
317- a
318+ acc
318319 }
319320 })
320321 -> Array .map (f => extractDocFromFile (Path .join (["runtime" , f ]))-> getExamples )
321322 -> Array .flat
322323
323- let results =
324+ let compilationResults =
324325 await modules
325326 -> Array .map (async example => {
326- let id = example .id -> String .replaceAll ("." , "_ " )
327+ let id = example .id -> String .replaceAll ("." , "__ " )
327328 let rescriptCode = example -> getCodeBlocks
328329 let jsCode = await compileTest (~id , ~code = rescriptCode )
329- // let id = `${id}_${Int.toString(int)}`
330- // let results =
331- // await [codes]
332- // ->Array.mapWithIndex(async (code, int) => {
333- // let id = `${id}_${Int.toString(int)}`
334- // (code, await compileTest(~id, ~code))
335- // })
336- // ->Promise.all
337330 (example , (rescriptCode , jsCode ))
338331 })
339332 -> Promise .all
340333
341- // let examples = results->Array.map(((example, result)) => {
342- // let (compiled, errors) = results->Array.reduce(([], []), (acc, (resCode, result)) => {
343- // let (oks, errors) = acc
344- // switch result {
345- // | Ok(jsCode) => ([...oks, (resCode, jsCode)], errors)
346- // | Error(output) => (oks, [...errors, ReScript({error: output})])
347- // }
348- // })
349- // (example, (compiled, errors))
350- // })
351-
352- let (compiled , notCompiled ) = results -> Array .reduce (([], []), (
334+ let (compiled , compilationErrors ) = compilationResults -> Array .reduce (([], []), (
353335 acc ,
354- (example , (rescriptCode , compiled )),
336+ (example , (rescriptCode , jsCode )),
355337 ) => {
356338 let (lhs , rhs ) = acc
357- switch compiled {
339+ switch jsCode {
358340 | Ok (jsCode ) => lhs -> Array .push ((example , rescriptCode , jsCode ))
359- | Error (err ) => rhs -> Array .push ((example , ReScript ({ error : err } )))
341+ | Error (err ) => rhs -> Array .push ((example , ReScriptError ( err )))
360342 }
361343 (lhs , rhs )
362344 })
363345
364- let exampleErrors =
365- await compiled
346+ let runtimeErrors =
347+ ( await compiled
366348 -> Array .filter ((({id }, _ , _ )) => ! Array .includes (ignoreRuntimeTests , id ))
367- -> Array .map (async ((example , compiled , errors )) => {
368- let nodeTests = await errors -> runtimeTests
349+ -> Array .map (async ((example , rescriptCode , jsCode )) => {
350+ let nodeTests = await jsCode -> runtimeTests
369351 switch nodeTests {
370352 | Ok (_ ) => None
371- | Error (err ) => Some (example , Runtime ({rescript : compiled , js : errors , error : err }))
353+ | Error (error ) => Some (example , RuntimeError ({rescript : rescriptCode , js : jsCode , error }))
372354 }
373355 })
374- -> Promise .all
375-
376- let exampleErrors = exampleErrors -> Array .filterMap (i =>
377- switch i {
378- | Some (i ) => Some (i )
379- | None => None
380- }
381- )
356+ -> Promise .all )
357+ -> Array .filterMap (i =>
358+ switch i {
359+ | Some (i ) => Some (i )
360+ | None => None
361+ }
362+ )
382363
383- let allErros = Array .concat (exampleErrors , notCompiled )
364+ let allErros = Array .concat (runtimeErrors , compilationErrors )
384365
385366 // Print Errors
386367 let () = allErros -> Array .forEach (((example , errors )) => {
@@ -391,18 +372,18 @@ let main = async () => {
391372 | other => other
392373 }
393374
394- // let errorMessage = errors->Array.map(err =>
395375 let a = switch errors {
396- | ReScript ({ error } ) =>
376+ | ReScriptError ( error ) =>
397377 let err =
398378 error
399379 -> String .split ("\n " )
380+ // Drop line of filename
400381 -> Array .filterWithIndex ((_ , i ) => i !== 2 )
401382 -> Array .join ("\n " )
402383
403384 ` ${"error" -> red}: failed to compile examples from ${kind} ${example.id-> cyan}
404385${err}`
405- | Runtime ({rescript , js , error }) =>
386+ | RuntimeError ({rescript , js , error }) =>
406387 let indent = String .repeat (" " , 2 )
407388
408389 ` ${"runtime error" -> red}: failed to run examples from ${kind} ${example.id-> cyan}
@@ -422,7 +403,6 @@ ${error->indentOutputCode}
422403 }
423404
424405 Process .stderrWrite (a )
425- // errorMessage->Array.forEach(e => Process.stderrWrite(e))
426406 })
427407
428408 let someError = allErros -> Array .length > 0
0 commit comments