@@ -86,7 +86,7 @@ let prepareCompiler = () => {
86
86
87
87
prepareCompiler ()
88
88
89
- type docTest = {
89
+ type example = {
90
90
id : string ,
91
91
kind : string ,
92
92
name : string ,
@@ -95,7 +95,7 @@ type docTest = {
95
95
96
96
let createFileInTempDir = id => Path .join2 (OS .tmpdir (), id )
97
97
98
- let testCodeBlock = async (id , _kind , code ) => {
98
+ let testCode = async (~ id , ~ code ) => {
99
99
let tempFileName = createFileInTempDir (id )
100
100
101
101
let () = await Fs .writeFile (tempFileName ++ ".res" , code )
@@ -132,7 +132,7 @@ let testCodeBlock = async (id, _kind, code) => {
132
132
}
133
133
}
134
134
135
- let extractDoc = file => {
135
+ let extractDocFromFile = file => {
136
136
let toolsBin = Path .join ([Path .dirname (dirname ), "node_modules" , ".bin" , "rescript-tools" ])
137
137
let spawn = ChildProcess .spawnSync (toolsBin , ["doc" , file ])
138
138
@@ -142,8 +142,8 @@ let extractDoc = file => {
142
142
-> Docgen .decodeFromJson
143
143
}
144
144
145
- let getDocstrings = ({items }: Docgen .doc ) => {
146
- let rec loop = (items : list <Docgen .item >, acc : list <docTest >) => {
145
+ let getExamples = ({items }: Docgen .doc ) => {
146
+ let rec loop = (items : list <Docgen .item >, acc : list <example >) => {
147
147
switch items {
148
148
| list {Value ({docstrings , id , name }), ... rest } =>
149
149
loop (rest , list {{id , name , docstrings , kind : "value" }, ... acc })
@@ -218,27 +218,21 @@ let getCodeBlocks = example => {
218
218
-> List .toArray
219
219
}
220
220
221
- let tests =
222
- extractDoc ("src/RescriptCore.res" )
223
- -> getDocstrings
224
- -> Array .map (doc => (doc , doc -> getCodeBlocks ))
225
- -> Array .filter (((_ , b )) => Array .length (b ) > 0 )
226
-
227
- let moduleTestsResults =
228
- await tests
229
- -> Array .map (async ((docTest , codeblocks )) => {
221
+ let results =
222
+ await extractDocFromFile ("src/RescriptCore.res" )
223
+ -> getExamples
224
+ -> Array .map (async example => {
225
+ let id = example .id -> String .replaceAll ("." , "_" )
226
+ let codes = example -> getCodeBlocks
230
227
let results =
231
- await codeblocks
232
- -> Array .map (async code => {
233
- let id = docTest .id -> String .replaceAll ("." , "_" )
234
- await testCodeBlock (id , docTest .kind , code )
235
- })
228
+ await codes
229
+ -> Array .map (async code => await testCode (~id , ~code ))
236
230
-> Promise .all
237
- (docTest , results )
231
+ (example , results )
238
232
})
239
233
-> Promise .all
240
234
241
- let errors = moduleTestsResults -> Belt .Array .keepMap (((test , results )) => {
235
+ let errors = results -> Belt .Array .keepMap (((example , results )) => {
242
236
let errors = results -> Belt .Array .keepMap (result =>
243
237
switch result {
244
238
| Ok () => None
@@ -247,7 +241,7 @@ let errors = moduleTestsResults->Belt.Array.keepMap(((test, results)) => {
247
241
)
248
242
249
243
if Array .length (errors ) > 0 {
250
- Some ((test , errors ))
244
+ Some ((example , errors ))
251
245
} else {
252
246
None
253
247
}
@@ -278,4 +272,4 @@ let () = errors->Array.forEach(((test, errors)) => {
278
272
Process .stderrWrite (message )
279
273
})
280
274
281
- Process .exit (errors -> Array .length )
275
+ Process .exit (errors -> Array .length == 0 ? 0 : 1 )
0 commit comments