Skip to content

Commit 4d973c8

Browse files
authored
Build tests/tests with rewatch (#8137)
* execBuild -> execBuildLegacy etc. * Build tests/tests with rewatch
1 parent b73a0c8 commit 4d973c8

File tree

40 files changed

+152
-112
lines changed

40 files changed

+152
-112
lines changed

lib_dev/process.js

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as child_process from "node:child_process";
22
import * as fs from "node:fs/promises";
33
import * as path from "node:path";
4-
import { bsc_exe, rescript_legacy_exe } from "#cli/bins";
4+
import { bsc_exe, rescript_exe, rescript_legacy_exe } from "#cli/bins";
55

66
/**
77
* @typedef {{
@@ -29,10 +29,13 @@ export const {
2929
yarn,
3030
mocha,
3131
bsc,
32-
rescript,
3332
execBin,
33+
rescript,
3434
execBuild,
3535
execClean,
36+
rescriptLegacy,
37+
execBuildLegacy,
38+
execCleanLegacy,
3639
} = setup();
3740

3841
/**
@@ -156,58 +159,98 @@ export function setup(cwd = process.cwd()) {
156159
return exec("npx", ["mocha", ...args], options);
157160
},
158161

162+
/**
163+
* `bsc` CLI
164+
*
165+
* @param {string[]} [args]
166+
* @param {ExecOptions} [options]
167+
* @return {Promise<ExecResult>}
168+
*/
169+
bsc(args = [], options = {}) {
170+
return exec(bsc_exe, args, options);
171+
},
172+
159173
/**
160174
* `rescript` CLI
161175
*
162176
* @param {(
163177
* | "build"
164178
* | "clean"
165179
* | "format"
166-
* | "dump"
167180
* | (string & {})
168181
* )} command
169182
* @param {string[]} [args]
170183
* @param {ExecOptions} [options]
171184
* @return {Promise<ExecResult>}
172185
*/
173186
rescript(command, args = [], options = {}) {
174-
const cliPath = path.join(
175-
import.meta.dirname,
176-
"../cli/rescript-legacy.js",
177-
);
187+
const cliPath = path.join(import.meta.dirname, "../cli/rescript.js");
178188
return exec("node", [cliPath, command, ...args].filter(Boolean), options);
179189
},
180190

181191
/**
182-
* `bsc` CLI
192+
* Execute ReScript `build` command directly
183193
*
184194
* @param {string[]} [args]
185195
* @param {ExecOptions} [options]
186196
* @return {Promise<ExecResult>}
187197
*/
188-
bsc(args = [], options = {}) {
189-
return exec(bsc_exe, args, options);
198+
execBuild(args = [], options = {}) {
199+
return exec(rescript_exe, ["build", ...args], options);
190200
},
191201

192202
/**
193-
* Execute ReScript `build` command directly
203+
* Execute ReScript `clean` command directly
194204
*
195205
* @param {string[]} [args]
196206
* @param {ExecOptions} [options]
197207
* @return {Promise<ExecResult>}
198208
*/
199-
execBuild(args = [], options = {}) {
209+
execClean(args = [], options = {}) {
210+
return exec(rescript_exe, ["clean", ...args], options);
211+
},
212+
213+
/**
214+
* `rescript` legacy CLI
215+
*
216+
* @param {(
217+
* | "build"
218+
* | "clean"
219+
* | "format"
220+
* | "dump"
221+
* | (string & {})
222+
* )} command
223+
* @param {string[]} [args]
224+
* @param {ExecOptions} [options]
225+
* @return {Promise<ExecResult>}
226+
*/
227+
rescriptLegacy(command, args = [], options = {}) {
228+
const cliPath = path.join(
229+
import.meta.dirname,
230+
"../cli/rescript-legacy.js",
231+
);
232+
return exec("node", [cliPath, command, ...args].filter(Boolean), options);
233+
},
234+
235+
/**
236+
* Execute ReScript legacy `build` command directly
237+
*
238+
* @param {string[]} [args]
239+
* @param {ExecOptions} [options]
240+
* @return {Promise<ExecResult>}
241+
*/
242+
execBuildLegacy(args = [], options = {}) {
200243
return exec(rescript_legacy_exe, ["build", ...args], options);
201244
},
202245

203246
/**
204-
* Execute ReScript `clean` command directly
247+
* Execute ReScript legacy `clean` command directly
205248
*
206249
* @param {string[]} [args]
207250
* @param {ExecOptions} [options]
208251
* @return {Promise<ExecResult>}
209252
*/
210-
execClean(args = [], options = {}) {
253+
execCleanLegacy(args = [], options = {}) {
211254
return exec(rescript_legacy_exe, ["clean", ...args], options);
212255
},
213256

scripts/test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,8 @@ if (ounitTest) {
7373
}
7474

7575
if (mochaTest) {
76-
await execClean([], {
77-
cwd: compilerTestDir,
78-
stdio: "inherit",
79-
});
80-
76+
// No need to clean beforehand, rewatch detects changes to the compiler binary
77+
// and rebuilds automatically in that case.
8178
await execBuild([], {
8279
cwd: compilerTestDir,
8380
stdio: "inherit",
@@ -87,7 +84,7 @@ if (mochaTest) {
8784
[
8885
"-t",
8986
"10000",
90-
"tests/tests/**/*_test.mjs",
87+
"tests/tests/src/**/*_test.mjs",
9188
// Ignore the preserve_jsx_test.mjs file.
9289
// I can't run because Mocha doesn't support jsx.
9390
// We also want to keep the output as is.

tests/build_tests/build_warn_as_error/input.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as assert from "node:assert";
22
import { setup } from "#dev/process";
33

4-
const { execBuild, execClean } = setup(import.meta.dirname);
4+
const { execBuildLegacy, execCleanLegacy } = setup(import.meta.dirname);
55

6-
const o1 = await execBuild();
6+
const o1 = await execBuildLegacy();
77

88
const first_message = o1.stdout
99
.split("\n")
@@ -15,7 +15,7 @@ if (!first_message) {
1515
}
1616

1717
// Second build using -warn-error +110
18-
const o2 = await execBuild(["-warn-error", "+110"]);
18+
const o2 = await execBuildLegacy(["-warn-error", "+110"]);
1919

2020
const second_message = o2.stdout
2121
.split("\n")
@@ -28,7 +28,7 @@ if (!second_message) {
2828

2929
// Third build, without -warn-error +110
3030
// The result should not be a warning as error
31-
const o3 = await execBuild();
31+
const o3 = await execBuildLegacy();
3232

3333
const third_message = o3.stdout
3434
.split("\n")
@@ -39,4 +39,4 @@ if (!third_message) {
3939
assert.fail(o3.stdout);
4040
}
4141

42-
await execClean();
42+
await execCleanLegacy();

tests/build_tests/case/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as assert from "node:assert";
22
import { setup } from "#dev/process";
33
import { normalizeNewlines } from "#dev/utils";
44

5-
const { execBuild } = setup(import.meta.dirname);
5+
const { execBuildLegacy } = setup(import.meta.dirname);
66

7-
const { stderr } = await execBuild();
7+
const { stderr } = await execBuildLegacy();
88

99
if (
1010
![

tests/build_tests/case2/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import * as assert from "node:assert";
44
import { setup } from "#dev/process";
55
import { normalizeNewlines } from "#dev/utils";
66

7-
const { execBuild } = setup(import.meta.dirname);
7+
const { execBuildLegacy } = setup(import.meta.dirname);
88

9-
const { stderr } = await execBuild();
9+
const { stderr } = await execBuildLegacy();
1010

1111
if (
1212
![

tests/build_tests/case3/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import fs from "node:fs/promises";
55
import path from "node:path";
66
import { setup } from "#dev/process";
77

8-
const { execBuild } = setup(import.meta.dirname);
8+
const { execBuildLegacy } = setup(import.meta.dirname);
99

10-
await execBuild();
10+
await execBuildLegacy();
1111

1212
const o = await fs.readFile(path.join("src", "hello.res.js"), "ascii");
1313
assert.ok(/HelloGen\.f/.test(o));

tests/build_tests/cli_compile_status/input.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import * as assert from "node:assert";
44
import { setup } from "#dev/process";
55
import { normalizeNewlines } from "#dev/utils";
66

7-
const { rescript } = setup(import.meta.dirname);
7+
const { rescriptLegacy } = setup(import.meta.dirname);
88

99
// Shows compile time for `rescript build` command
10-
let out = await rescript("build");
10+
let out = await rescriptLegacy("build");
1111
assert.match(
1212
normalizeNewlines(out.stdout),
1313
/>>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/,
1414
);
1515

1616
// Shows compile time for `rescript` command
17-
out = await rescript("build");
17+
out = await rescriptLegacy("build");
1818
assert.match(
1919
normalizeNewlines(out.stdout),
2020
/>>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/,
@@ -24,7 +24,7 @@ assert.match(
2424
// Because we can't be sure that -verbose is a valid argument
2525
// And bsb won't fail with a usage message.
2626
// It works this way not only for -verbose, but any other arg, including -h/--help/-help
27-
out = await rescript("build", ["-verbose"]);
27+
out = await rescriptLegacy("build", ["-verbose"]);
2828

2929
assert.match(
3030
normalizeNewlines(out.stdout),

tests/build_tests/cli_help/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as assert from "node:assert";
44
import { setup } from "#dev/process";
55
import { normalizeNewlines } from "#dev/utils";
66

7-
const { rescript } = setup(import.meta.dirname);
7+
const { rescriptLegacy } = setup(import.meta.dirname);
88

99
const cliHelp =
1010
"Usage: rescript <options> <subcommand>\n" +
@@ -69,7 +69,7 @@ const dumpHelp =
6969
* @param {{ stdout: string; stderr: string; status: number; }} expected
7070
*/
7171
async function test(params, expected) {
72-
const out = await rescript("", params);
72+
const out = await rescriptLegacy("", params);
7373

7474
assert.equal(normalizeNewlines(out.stdout), expected.stdout);
7575
assert.equal(normalizeNewlines(out.stderr), expected.stderr);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as assert from "node:assert";
22
import { setup } from "#dev/process";
33

4-
const { execClean, execBuild } = setup(import.meta.dirname);
4+
const { execCleanLegacy, execBuildLegacy } = setup(import.meta.dirname);
55

6-
await execClean();
7-
await execBuild();
6+
await execCleanLegacy();
7+
await execBuildLegacy();
88

99
const x = await import("./src/demo.res.js");
1010
assert.equal(x.v, 42);

tests/build_tests/cycle/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import * as fs from "node:fs/promises";
55
import * as path from "node:path";
66
import { setup } from "#dev/process";
77

8-
const { execBuild } = setup(import.meta.dirname);
8+
const { execBuildLegacy } = setup(import.meta.dirname);
99

10-
const output = await execBuild();
10+
const output = await execBuildLegacy();
1111

1212
assert.match(output.stdout, /dependency cycle/);
1313

0 commit comments

Comments
 (0)