Skip to content

Commit 95ea79b

Browse files
committed
Bring back check for unavailable functions
1 parent 26b646c commit 95ea79b

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ jobs:
313313
run: node scripts/test.js -all
314314

315315
- name: Docstrings tests
316-
run: node tests/docstrings_examples/DocTest.res.mjs
316+
# Ignore functions that are not available on Node 18
317+
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"
317318

318319
- name: Check for diffs in tests folder
319320
run: git diff --ignore-cr-at-eol --exit-code tests

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")}"`,
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"`,
142142
// {
143143
// cwd: path.join(__dirname, ".."),
144144
// stdio: [0, 1, 2],

tests/docstrings_examples/DocTest.res

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ type error =
1515

1616
let bscBin = Path.join(["cli", "bsc"])
1717

18+
let parsed = Util.parseArgs({
19+
args: Process.argv->Array.sliceToEnd(~start=2),
20+
options: dict{"ignore-runtime-tests": {Util.type_: "string"}},
21+
})
22+
23+
let ignoreRuntimeTests = switch parsed.values->Dict.get("ignore-runtime-tests") {
24+
| Some(v) =>
25+
v
26+
->String.split(",")
27+
->Array.map(s => s->String.trim)
28+
| None => []
29+
}
30+
1831
let getOutput = buffer =>
1932
buffer
2033
->Array.map(e => e->Buffer.toString)
@@ -172,7 +185,7 @@ let compileExamples = async examples => {
172185
(compiled, compilationErrors)
173186
}
174187

175-
let runtimeTests = async code => {
188+
let runTest = async code => {
176189
let {stdout, stderr, code: exitCode} = await SpawnAsync.run(
177190
~command="node",
178191
~args=["-e", code, "--input-type", "commonjs"],
@@ -196,11 +209,13 @@ let runtimeTests = async code => {
196209
let runExamples = async compiled => {
197210
Console.log(`Running ${compiled->Array.length->Int.toString} compiled examples...`)
198211

212+
let tests = compiled->Array.filter((({id}, _, _)) => !(ignoreRuntimeTests->Array.includes(id)))
213+
199214
let runtimeErrors = []
200-
await compiled->ArrayUtils.forEachAsyncInBatches(~batchSize, async compiled => {
215+
await tests->ArrayUtils.forEachAsyncInBatches(~batchSize, async compiled => {
201216
let (example, rescriptCode, jsCode) = compiled
202217

203-
switch await runtimeTests(jsCode) {
218+
switch await runTest(jsCode) {
204219
| Ok(_) => ()
205220
| Error(error) =>
206221
let runtimeError = RuntimeError({rescript: rescriptCode, js: jsCode, error})

tests/docstrings_examples/DocTest.res.mjs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as Path from "path";
88
import * as $$Array from "rescript/lib/es6/Array.js";
99
import * as $$Error from "rescript/lib/es6/Error.js";
1010
import * as Belt_List from "rescript/lib/es6/Belt_List.js";
11+
import * as Nodeutil from "node:util";
1112
import * as ArrayUtils from "./ArrayUtils.res.mjs";
1213
import * as Belt_Array from "rescript/lib/es6/Belt_Array.js";
1314
import * as Pervasives from "rescript/lib/es6/Pervasives.js";
@@ -17,6 +18,19 @@ import * as RescriptTools_Docgen from "rescript/lib/es6/RescriptTools_Docgen.js"
1718

1819
let bscBin = Path.join("cli", "bsc");
1920

21+
let parsed = Nodeutil.parseArgs({
22+
args: process.argv.slice(2),
23+
options: {
24+
"ignore-runtime-tests": {
25+
type: "string"
26+
}
27+
}
28+
});
29+
30+
let v = parsed.values["ignore-runtime-tests"];
31+
32+
let ignoreRuntimeTests = v !== undefined ? v.split(",").map(s => s.trim()) : [];
33+
2034
function getOutput(buffer) {
2135
return buffer.map(e => e.toString()).join("");
2236
}
@@ -38,7 +52,7 @@ async function extractDocFromFile(file) {
3852
RE_EXN_ID: "Assert_failure",
3953
_1: [
4054
"DocTest.res",
41-
35,
55+
48,
4256
9
4357
],
4458
Error: new Error()
@@ -250,7 +264,7 @@ async function compileExamples(examples) {
250264
];
251265
}
252266

253-
async function runtimeTests(code) {
267+
async function runTest(code) {
254268
let match = await SpawnAsync.run("node", [
255269
"-e",
256270
code,
@@ -303,10 +317,11 @@ async function runtimeTests(code) {
303317

304318
async function runExamples(compiled) {
305319
console.log("Running " + compiled.length.toString() + " compiled examples...");
320+
let tests = compiled.filter(param => !ignoreRuntimeTests.includes(param[0].id));
306321
let runtimeErrors = [];
307-
await ArrayUtils.forEachAsyncInBatches(compiled, batchSize, async compiled => {
322+
await ArrayUtils.forEachAsyncInBatches(tests, batchSize, async compiled => {
308323
let jsCode = compiled[2];
309-
let error = await runtimeTests(jsCode);
324+
let error = await runTest(jsCode);
310325
if (error.TAG === "Ok") {
311326
return;
312327
}

0 commit comments

Comments
 (0)