Skip to content

Commit b1363f0

Browse files
authored
Remove usage of legacy build system from build tests (#8179)
1 parent d6504c2 commit b1363f0

51 files changed

Lines changed: 272 additions & 422 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib_dev/process.js

Lines changed: 1 addition & 48 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_exe, rescript_legacy_exe } from "#cli/bins";
4+
import { bsc_exe, rescript_exe } from "#cli/bins";
55

66
/**
77
* @typedef {{
@@ -33,9 +33,6 @@ export const {
3333
rescript,
3434
execBuild,
3535
execClean,
36-
rescriptLegacy,
37-
execBuildLegacy,
38-
execCleanLegacy,
3936
} = setup();
4037

4138
/**
@@ -210,50 +207,6 @@ export function setup(cwd = process.cwd()) {
210207
return exec(rescript_exe, ["clean", ...args], options);
211208
},
212209

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 = {}) {
243-
return exec(rescript_legacy_exe, ["build", ...args], options);
244-
},
245-
246-
/**
247-
* Execute ReScript legacy `clean` command directly
248-
*
249-
* @param {string[]} [args]
250-
* @param {ExecOptions} [options]
251-
* @return {Promise<ExecResult>}
252-
*/
253-
execCleanLegacy(args = [], options = {}) {
254-
return exec(rescript_legacy_exe, ["clean", ...args], options);
255-
},
256-
257210
/**
258211
* Execute any binary or wrapper.
259212
* It should support Windows as well

scripts/test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,14 @@ if (bsbTest) {
122122
if (!fs.existsSync(path.join(testDir, "input.js"))) {
123123
console.warn(`input.js does not exist in ${testDir}`);
124124
} else {
125-
console.log(`testing ${file}`);
126-
127125
// note existsSync test already ensure that it is a directory
128126
const out = await node("input.js", [], { cwd: testDir });
129-
console.log(out.stdout);
127+
process.stdout.write(out.stdout);
130128

131129
if (out.status === 0) {
132-
console.log("✅ success in", file);
130+
console.log(`✅ success in ${file}`);
133131
} else {
134-
console.log(`❌ error in ${file} with stderr:\n`, out.stderr);
132+
console.log(`❌ error in ${file} with stderr:\n${out.stderr}`);
135133
hasError = true;
136134
}
137135
}

tests/build_tests/build_warn_as_error/input.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import * as assert from "node:assert";
2+
import { stripVTControlCharacters } from "node:util";
23
import { setup } from "#dev/process";
34

45
const { execBuild, execClean } = setup(import.meta.dirname);
56

67
const o1 = await execBuild();
78

8-
// biome-ignore lint/suspicious/noControlCharactersInRegex: strip ANSI color codes from output
9-
const stripAnsi = s => s.replace(/\x1b\[[0-9;]*m/g, "");
10-
11-
const first_message = stripAnsi(o1.stderr)
9+
const first_message = stripVTControlCharacters(o1.stderr)
1210
.split("\n")
1311
.map(s => s.trim())
1412
.find(s => s === "Warning number 110");
@@ -20,7 +18,7 @@ if (!first_message) {
2018
// Second build using --warn-error +110
2119
const o2 = await execBuild(["--warn-error", "+110"]);
2220

23-
const second_message = stripAnsi(o2.stderr)
21+
const second_message = stripVTControlCharacters(o2.stderr)
2422
.split("\n")
2523
.map(s => s.trim())
2624
.find(s => s === "Warning number 110 (configured as error)");
@@ -33,7 +31,7 @@ if (!second_message) {
3331
// The result should not be a warning as error
3432
const o3 = await execBuild();
3533

36-
const third_message = stripAnsi(o3.stderr)
34+
const third_message = stripVTControlCharacters(o3.stderr)
3735
.split("\n")
3836
.map(s => s.trim())
3937
.find(s => s === "Warning number 110 (configured as error)");

tests/build_tests/case3/input.js

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

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

10-
await execBuildLegacy();
10+
await execClean();
11+
await execBuild();
1112

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

tests/build_tests/cli_compile_status/input.js

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

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

9-
// Shows compile time for `rescript build` command
10-
let out = await rescriptLegacy("build");
9+
// Shows build output for `rescript build` command
10+
let out = await rescript("build");
11+
// Timing text only appears with TTY/progress output; plain output omits it.
1112
assert.match(
1213
normalizeNewlines(out.stdout),
13-
/>>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/,
14+
/Parsed \d+ source files( in [0-9.]+s)?/,
1415
);
15-
16-
// Shows compile time for `rescript` command
17-
out = await rescriptLegacy("build");
1816
assert.match(
1917
normalizeNewlines(out.stdout),
20-
/>>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/,
18+
/Compiled \d+ modules( in [0-9.]+s)?/,
2119
);
2220

23-
// Doesn't show compile time for `rescript build -verbose` command
24-
// Because we can't be sure that -verbose is a valid argument
25-
// And bsb won't fail with a usage message.
26-
// It works this way not only for -verbose, but any other arg, including -h/--help/-help
27-
out = await rescriptLegacy("build", ["-verbose"]);
28-
21+
// Shows build output for `rescript` command
22+
out = await rescript("");
23+
assert.match(
24+
normalizeNewlines(out.stdout),
25+
/Parsed \d+ source files( in [0-9.]+s)?/,
26+
);
2927
assert.match(
3028
normalizeNewlines(out.stdout),
31-
/Package stack: test {2}\nDependency Finished\n/,
29+
/Compiled \d+ modules( in [0-9.]+s)?/,
3230
);
33-
assert.match(normalizeNewlines(out.stdout), /ninja.exe"? -C lib[\\/]bs ?\n/);
31+
32+
out = await rescript("build", ["-v"]);
33+
assert.match(normalizeNewlines(out.stdout), /Created project context/);

0 commit comments

Comments
 (0)