Skip to content

Commit 2a591d9

Browse files
committed
Clean up doc tests script, use array helpers instead of AsyncIterator
1 parent 92ea433 commit 2a591d9

File tree

11 files changed

+493
-663
lines changed

11 files changed

+493
-663
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ jobs:
132132
- name: Checkout
133133
uses: actions/checkout@v4
134134

135-
# Default is too slow, 256
135+
# Default is too slow, 256
136136
- name: Increase file descriptors limit (macOS only)
137137
if: runner.os == 'macOS'
138138
run: sudo launchctl limit maxfiles 6000 10000
@@ -257,7 +257,7 @@ jobs:
257257
- name: "Windows: set SHELLOPTS=igncr"
258258
if: runner.os == 'Windows'
259259
run: echo "SHELLOPTS=igncr" >>"$GITHUB_ENV"
260-
260+
261261
- name: Build compiler
262262
if: runner.os != 'Linux'
263263
run: opam exec -- dune build --display quiet --profile release
@@ -326,11 +326,8 @@ jobs:
326326
- name: Run tests
327327
run: node scripts/test.js -all
328328

329-
- name: Docstrins tests
330-
if: runner.os == 'macOS'
331-
env:
332-
UV_THREADPOOL_SIZE: 8
333-
run: node tests/docstrings_examples/DocTest.res.mjs --ignore-runtime-tests "Array.toReversed, Array.toSorted, Promise.withResolvers, Set.union, Set.isSupersetOf, Set.isSubsetOf, Set.isDisjointFrom, Set.intersection, Set.symmetricDifference, Set.difference"
329+
- name: Docstrings tests
330+
run: node tests/docstrings_examples/DocTest.res.mjs
334331

335332
- name: Check for diffs in tests folder
336333
run: git diff --ignore-cr-at-eol --exit-code tests
@@ -353,7 +350,7 @@ jobs:
353350
with:
354351
path: ./tests/benchmark-cache
355352
key: syntax-benchmark-v1
356-
353+
357354
- name: Create new benchmark data and comment on alert
358355
# Do not run for PRs created from other repos as those won't be able to write to the pull request
359356
if: ${{ matrix.benchmarks && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.repository.full_name) }}
@@ -374,7 +371,7 @@ jobs:
374371
with:
375372
path: ./tests/benchmark-cache
376373
key: syntax-benchmark-v1
377-
374+
378375
- name: Build playground compiler
379376
if: matrix.build_playground
380377
run: |
@@ -411,7 +408,7 @@ jobs:
411408
needs:
412409
- build-compiler
413410
- build-rewatch
414-
411+
415412
runs-on: ubuntu-latest
416413

417414
steps:

scripts/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ async function runTests() {
138138
});
139139
// Ignore some tests not supported by node v18
140140
// cp.execSync(
141-
// `node ${path.join("tests", "docstrings_examples", "DocTest.res.mjs")} --ignore-runtime-tests "Array.toReversed, Array.toSorted, Promise.withResolvers, Set.union, Set.isSupersetOf, Set.isSubsetOf, Set.isDisjointFrom, Set.intersection, Set.symmetricDifference, Set.difference"`,
141+
// `node ${path.join("tests", "docstrings_examples", "DocTest.res.mjs")}"`,
142142
// {
143143
// cwd: path.join(__dirname, ".."),
144144
// stdio: [0, 1, 2],
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
let splitIntoChunks = (arr, ~chunkSize) => {
2+
let chunks = []
3+
let length = arr->Array.length
4+
let startRef = ref(0)
5+
6+
while startRef.contents < length {
7+
let end = startRef.contents + chunkSize
8+
let chunk = arr->Array.slice(~start=startRef.contents, ~end)
9+
10+
chunks->Array.push(chunk)
11+
startRef := end
12+
}
13+
14+
chunks
15+
}
16+
17+
let forEachAsyncParallel = async (arr, f) => {
18+
let _: array<unit> = await Promise.all(arr->Array.map(f))
19+
}
20+
21+
let forEachAsyncSerially = async (arr, f) =>
22+
for i in 0 to arr->Array.length - 1 {
23+
await f(arr->Array.getUnsafe(i))
24+
}
25+
26+
let forEachAsyncInBatches = (arr, ~batchSize, f) =>
27+
arr
28+
->splitIntoChunks(~chunkSize=batchSize)
29+
->forEachAsyncSerially(chunk => chunk->forEachAsyncParallel(f))
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
4+
function splitIntoChunks(arr, chunkSize) {
5+
let chunks = [];
6+
let length = arr.length;
7+
let startRef = 0;
8+
while (startRef < length) {
9+
let end = startRef + chunkSize | 0;
10+
let chunk = arr.slice(startRef, end);
11+
chunks.push(chunk);
12+
startRef = end;
13+
};
14+
return chunks;
15+
}
16+
17+
async function forEachAsyncParallel(arr, f) {
18+
await Promise.all(arr.map(f));
19+
}
20+
21+
async function forEachAsyncSerially(arr, f) {
22+
for (let i = 0, i_finish = arr.length; i < i_finish; ++i) {
23+
await f(arr[i]);
24+
}
25+
}
26+
27+
function forEachAsyncInBatches(arr, batchSize, f) {
28+
return forEachAsyncSerially(splitIntoChunks(arr, batchSize), chunk => forEachAsyncParallel(chunk, f));
29+
}
30+
31+
export {
32+
splitIntoChunks,
33+
forEachAsyncParallel,
34+
forEachAsyncSerially,
35+
forEachAsyncInBatches,
36+
}
37+
/* No side effect */

0 commit comments

Comments
 (0)