diff --git a/lib_dev/process.js b/lib_dev/process.js index 8f0173ad39..469c653ffc 100644 --- a/lib_dev/process.js +++ b/lib_dev/process.js @@ -1,7 +1,7 @@ import * as child_process from "node:child_process"; import * as fs from "node:fs/promises"; import * as path from "node:path"; -import { bsc_exe, rescript_exe, rescript_legacy_exe } from "#cli/bins"; +import { bsc_exe, rescript_exe } from "#cli/bins"; /** * @typedef {{ @@ -33,9 +33,6 @@ export const { rescript, execBuild, execClean, - rescriptLegacy, - execBuildLegacy, - execCleanLegacy, } = setup(); /** @@ -210,50 +207,6 @@ export function setup(cwd = process.cwd()) { return exec(rescript_exe, ["clean", ...args], options); }, - /** - * `rescript` legacy CLI - * - * @param {( - * | "build" - * | "clean" - * | "format" - * | "dump" - * | (string & {}) - * )} command - * @param {string[]} [args] - * @param {ExecOptions} [options] - * @return {Promise} - */ - rescriptLegacy(command, args = [], options = {}) { - const cliPath = path.join( - import.meta.dirname, - "../cli/rescript-legacy.js", - ); - return exec("node", [cliPath, command, ...args].filter(Boolean), options); - }, - - /** - * Execute ReScript legacy `build` command directly - * - * @param {string[]} [args] - * @param {ExecOptions} [options] - * @return {Promise} - */ - execBuildLegacy(args = [], options = {}) { - return exec(rescript_legacy_exe, ["build", ...args], options); - }, - - /** - * Execute ReScript legacy `clean` command directly - * - * @param {string[]} [args] - * @param {ExecOptions} [options] - * @return {Promise} - */ - execCleanLegacy(args = [], options = {}) { - return exec(rescript_legacy_exe, ["clean", ...args], options); - }, - /** * Execute any binary or wrapper. * It should support Windows as well diff --git a/scripts/test.js b/scripts/test.js index 1f69ab5528..c0a4537b39 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -122,16 +122,14 @@ if (bsbTest) { if (!fs.existsSync(path.join(testDir, "input.js"))) { console.warn(`input.js does not exist in ${testDir}`); } else { - console.log(`testing ${file}`); - // note existsSync test already ensure that it is a directory const out = await node("input.js", [], { cwd: testDir }); - console.log(out.stdout); + process.stdout.write(out.stdout); if (out.status === 0) { - console.log("✅ success in", file); + console.log(`✅ success in ${file}`); } else { - console.log(`❌ error in ${file} with stderr:\n`, out.stderr); + console.log(`❌ error in ${file} with stderr:\n${out.stderr}`); hasError = true; } } diff --git a/tests/build_tests/build_warn_as_error/input.js b/tests/build_tests/build_warn_as_error/input.js index bd0e9f9473..1c69b4224f 100644 --- a/tests/build_tests/build_warn_as_error/input.js +++ b/tests/build_tests/build_warn_as_error/input.js @@ -1,14 +1,12 @@ import * as assert from "node:assert"; +import { stripVTControlCharacters } from "node:util"; import { setup } from "#dev/process"; const { execBuild, execClean } = setup(import.meta.dirname); const o1 = await execBuild(); -// biome-ignore lint/suspicious/noControlCharactersInRegex: strip ANSI color codes from output -const stripAnsi = s => s.replace(/\x1b\[[0-9;]*m/g, ""); - -const first_message = stripAnsi(o1.stderr) +const first_message = stripVTControlCharacters(o1.stderr) .split("\n") .map(s => s.trim()) .find(s => s === "Warning number 110"); @@ -20,7 +18,7 @@ if (!first_message) { // Second build using --warn-error +110 const o2 = await execBuild(["--warn-error", "+110"]); -const second_message = stripAnsi(o2.stderr) +const second_message = stripVTControlCharacters(o2.stderr) .split("\n") .map(s => s.trim()) .find(s => s === "Warning number 110 (configured as error)"); @@ -33,7 +31,7 @@ if (!second_message) { // The result should not be a warning as error const o3 = await execBuild(); -const third_message = stripAnsi(o3.stderr) +const third_message = stripVTControlCharacters(o3.stderr) .split("\n") .map(s => s.trim()) .find(s => s === "Warning number 110 (configured as error)"); diff --git a/tests/build_tests/case3/input.js b/tests/build_tests/case3/input.js index a95d2a5faa..d2a494dc42 100644 --- a/tests/build_tests/case3/input.js +++ b/tests/build_tests/case3/input.js @@ -5,9 +5,10 @@ import fs from "node:fs/promises"; import path from "node:path"; import { setup } from "#dev/process"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -await execBuildLegacy(); +await execClean(); +await execBuild(); const o = await fs.readFile(path.join("src", "hello.res.js"), "ascii"); assert.ok(/HelloGen\.f/.test(o)); diff --git a/tests/build_tests/cli_compile_status/input.js b/tests/build_tests/cli_compile_status/input.js index b736a3129a..5c377e5a38 100755 --- a/tests/build_tests/cli_compile_status/input.js +++ b/tests/build_tests/cli_compile_status/input.js @@ -4,30 +4,30 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { rescriptLegacy } = setup(import.meta.dirname); +const { rescript } = setup(import.meta.dirname); -// Shows compile time for `rescript build` command -let out = await rescriptLegacy("build"); +// Shows build output for `rescript build` command +let out = await rescript("build"); +// Timing text only appears with TTY/progress output; plain output omits it. assert.match( normalizeNewlines(out.stdout), - />>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/, + /Parsed \d+ source files( in [0-9.]+s)?/, ); - -// Shows compile time for `rescript` command -out = await rescriptLegacy("build"); assert.match( normalizeNewlines(out.stdout), - />>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/, + /Compiled \d+ modules( in [0-9.]+s)?/, ); -// Doesn't show compile time for `rescript build -verbose` command -// Because we can't be sure that -verbose is a valid argument -// And bsb won't fail with a usage message. -// It works this way not only for -verbose, but any other arg, including -h/--help/-help -out = await rescriptLegacy("build", ["-verbose"]); - +// Shows build output for `rescript` command +out = await rescript(""); +assert.match( + normalizeNewlines(out.stdout), + /Parsed \d+ source files( in [0-9.]+s)?/, +); assert.match( normalizeNewlines(out.stdout), - /Package stack: test {2}\nDependency Finished\n/, + /Compiled \d+ modules( in [0-9.]+s)?/, ); -assert.match(normalizeNewlines(out.stdout), /ninja.exe"? -C lib[\\/]bs ?\n/); + +out = await rescript("build", ["-v"]); +assert.match(normalizeNewlines(out.stdout), /Created project context/); diff --git a/tests/build_tests/cli_help/input.js b/tests/build_tests/cli_help/input.js index 6e0068e2a8..479effb4e7 100755 --- a/tests/build_tests/cli_help/input.js +++ b/tests/build_tests/cli_help/input.js @@ -1,78 +1,109 @@ // @ts-check import * as assert from "node:assert"; +import { stripVTControlCharacters } from "node:util"; import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { rescriptLegacy } = setup(import.meta.dirname); +const { rescript } = setup(import.meta.dirname); const cliHelp = - "Usage: rescript \n" + + "ReScript - Fast, Simple, Fully Typed JavaScript from the Future\n" + "\n" + - "`rescript` is equivalent to `rescript build`\n" + + "Usage: rescript [OPTIONS] \n" + "\n" + - "Options:\n" + - " -v, -version display version number\n" + - " -h, -help display help\n" + + "Commands:\n" + + " build Build the project (default command)\n" + + " watch Build, then start a watcher\n" + + " clean Clean the build artifacts\n" + + " format Format ReScript files\n" + + " compiler-args Print the compiler arguments for a ReScript source file\n" + + " help Print this message or the help of the given subcommand(s)\n" + "\n" + - "Subcommands:\n" + - " build\n" + - " clean\n" + - " format\n" + - " dump\n" + - " help\n" + + "Options:\n" + + " -v, --verbose... Increase logging verbosity\n" + + " -q, --quiet... Decrease logging verbosity\n" + + " -h, --help Print help\n" + + " -V, --version Print version\n" + "\n" + - "Run `rescript -h` for subcommand help. Examples:\n" + - " rescript build -h\n" + - " rescript format -h\n"; + "Notes:\n" + + " - If no command is provided, the build command is run by default. See `rescript help build` for more information.\n" + + " - To create a new ReScript project, or to add ReScript to an existing project, use https://github.com/rescript-lang/create-rescript-app.\n" + + " - For the legacy (pre-v12) build system, run `rescript-legacy`.\n"; const buildHelp = - "Usage: rescript build -- \n" + + "Build the project (default command)\n" + "\n" + - "`rescript build` builds the project with dependencies\n" + + "Usage: rescript build [OPTIONS] [FOLDER]\n" + "\n" + - "`rescript build -- -h` for Ninja options (internal usage only; unstable)\n" + + "Arguments:\n" + + " [FOLDER] Path to the project or subproject. This folder must contain a rescript.json file [default: .]\n" + "\n" + "Options:\n" + - " -w Watch mode\n" + - " -ws [host]:port set up host & port for WebSocket build notifications\n" + - " -verbose Set the output to be verbose\n" + - " -with-deps *deprecated* This is the default behavior now. This option will be removed in a future release\n" + - ' -warn-error Warning numbers and whether to turn them into errors, e.g., "+8+32-102"\n'; + " -f, --filter Filter source files by regex. E.g., filter out test files for compilation while doing feature work\n" + + " -v, --verbose... Increase logging verbosity\n" + + " -a, --after-build Run an additional command after build. E.g., play a sound or run a test suite when done compiling\n" + + " -q, --quiet... Decrease logging verbosity\n" + + ' --warn-error Override warning configuration from rescript.json. Example: --warn-error "+3+8+11+12+26+27+31+32+33+34+35+39+44+45+110"\n' + + " -n, --no-timing [] Disable output timing [default: false] [possible values: true, false]\n" + + " -h, --help Print help\n"; const cleanHelp = - "Usage: rescript clean \n" + + "Clean the build artifacts\n" + + "\n" + + "Usage: rescript clean [OPTIONS] [FOLDER]\n" + "\n" + - "`rescript clean` cleans build artifacts\n" + + "Arguments:\n" + + " [FOLDER] Path to the project or subproject. This folder must contain a rescript.json file [default: .]\n" + "\n" + "Options:\n" + - " -verbose Set the output to be verbose\n" + - " -with-deps *deprecated* This is the default behavior now. This option will be removed in a future release\n"; + " -v, --verbose... Increase logging verbosity\n" + + " -q, --quiet... Decrease logging verbosity\n" + + " -h, --help Print help\n"; const formatHelp = - "Usage: rescript format [files]\n" + + "Format ReScript files\n" + "\n" + - "`rescript format` formats the current directory\n" + + "Usage: rescript format [OPTIONS] [FILES]...\n" + + "\n" + + "Arguments:\n" + + " [FILES]... Files to format. If no files are provided, all files are formatted\n" + "\n" + "Options:\n" + - " -stdin [.res|.resi] Read the code from stdin and print\n" + - " the formatted code to stdout in ReScript syntax\n" + - " -all Format the whole project \n" + - " -check Check formatting for file or the whole project. Use `-all` to check the whole project\n"; - -const dumpHelp = - "Usage: rescript dump [target]\n" + - "`rescript dump` dumps the information for the target\n"; + " -c, --check Check formatting status without applying changes\n" + + " -v, --verbose... Increase logging verbosity\n" + + " -q, --quiet... Decrease logging verbosity\n" + + " -s, --stdin Read the code from stdin and print the formatted code to stdout [possible values: .res, .resi]\n" + + " -h, --help Print help\n"; + +const compilerArgsHelp = + "Print the compiler arguments for a ReScript source file\n" + + "\n" + + "Usage: rescript compiler-args [OPTIONS] \n" + + "\n" + + "Arguments:\n" + + " Path to a ReScript source file (.res or .resi)\n" + + "\n" + + "Options:\n" + + " -v, --verbose... Increase logging verbosity\n" + + " -q, --quiet... Decrease logging verbosity\n" + + " -h, --help Print help\n"; /** * @param {string[]} params * @param {{ stdout: string; stderr: string; status: number; }} expected */ async function test(params, expected) { - const out = await rescriptLegacy("", params); - - assert.equal(normalizeNewlines(out.stdout), expected.stdout); - assert.equal(normalizeNewlines(out.stderr), expected.stderr); + const out = await rescript("", params); + + assert.equal( + normalizeNewlines(stripVTControlCharacters(out.stdout)), + expected.stdout, + ); + assert.equal( + normalizeNewlines(stripVTControlCharacters(out.stderr)), + expected.stderr, + ); assert.equal(out.status, expected.status); } @@ -98,9 +129,16 @@ await test(["--help", "-w"], { stdout: cliHelp, stderr: "", status: 0 }); await test(["build", "-h"], { stdout: buildHelp, stderr: "", status: 0 }); // Exits with build help with unknown arg -await test(["build", "-foo"], { +await test(["build", "--foo"], { stdout: "", - stderr: `Error: Unknown option "-foo".\n${buildHelp}`, + stderr: + "error: unexpected argument '--foo' found\n" + + "\n" + + " tip: to pass '--foo' as a value, use '-- --foo'\n" + + "\n" + + "Usage: rescript build [OPTIONS] [FOLDER]\n" + + "\n" + + "For more information, try '--help'.\n", status: 2, }); @@ -114,16 +152,17 @@ await test(["-h"], { stdout: cliHelp, stderr: "", status: 0 }); await test(["help"], { stdout: cliHelp, stderr: "", status: 0 }); // Exits with cli help with unknown command -await test(["built"], { - stdout: "", - stderr: `Error: Unknown command "built".\n${cliHelp}`, - status: 2, -}); - -// Exits with build help with unknown args -await test(["-foo"], { +// Exits with build usage on unknown args +await test(["--foo"], { stdout: "", - stderr: `Error: Unknown option "-foo".\n${buildHelp}`, + stderr: + "error: unexpected argument '--foo' found\n" + + "\n" + + " tip: to pass '--foo' as a value, use '-- --foo'\n" + + "\n" + + "Usage: rescript build [OPTIONS] [FOLDER]\n" + + "\n" + + "For more information, try '--help'.\n", status: 2, }); @@ -138,9 +177,16 @@ await test(["clean", "--help"], { await test(["clean", "-h"], { stdout: cleanHelp, stderr: "", status: 0 }); // Exits with clean help with unknown arg -await test(["clean", "-foo"], { +await test(["clean", "--foo"], { stdout: "", - stderr: `Error: Unknown option "-foo".\n${cleanHelp}`, + stderr: + "error: unexpected argument '--foo' found\n" + + "\n" + + " tip: to pass '--foo' as a value, use '-- --foo'\n" + + "\n" + + "Usage: rescript clean [OPTIONS] [FOLDER]\n" + + "\n" + + "For more information, try '--help'.\n", status: 2, }); @@ -158,12 +204,16 @@ await test(["format", "-h"], { status: 0, }); -// Shows dump help with --help arg -await test(["dump", "--help"], { - stdout: dumpHelp, +// Shows compiler-args help with --help arg +await test(["compiler-args", "--help"], { + stdout: compilerArgsHelp, stderr: "", status: 0, }); -// Shows dump help with -h arg -await test(["dump", "-h"], { stdout: dumpHelp, stderr: "", status: 0 }); +// Shows compiler-args help with -h arg +await test(["compiler-args", "-h"], { + stdout: compilerArgsHelp, + stderr: "", + status: 0, +}); diff --git a/tests/build_tests/custom_namespace/input.js b/tests/build_tests/custom_namespace/input.js index 35a776cda4..718d172356 100644 --- a/tests/build_tests/custom_namespace/input.js +++ b/tests/build_tests/custom_namespace/input.js @@ -1,10 +1,10 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -const { execCleanLegacy, execBuildLegacy } = setup(import.meta.dirname); +const { execClean, execBuild } = setup(import.meta.dirname); -await execCleanLegacy(); -await execBuildLegacy(); +await execClean(); +await execBuild(); const x = await import("./src/demo.res.js"); assert.equal(x.v, 42); diff --git a/tests/build_tests/cycle/input.js b/tests/build_tests/cycle/input.js index 52d30d646b..acb3b692c8 100644 --- a/tests/build_tests/cycle/input.js +++ b/tests/build_tests/cycle/input.js @@ -1,16 +1,14 @@ // @ts-check import * as assert from "node:assert"; -import * as fs from "node:fs/promises"; -import * as path from "node:path"; +import { stripVTControlCharacters } from "node:util"; import { setup } from "#dev/process"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -const output = await execBuildLegacy(); +const output = await execBuild(); +const stderr = stripVTControlCharacters(output.stderr); -assert.match(output.stdout, /dependency cycle/); - -const compilerLogFile = path.join("lib", "bs", ".compiler.log"); -const compilerLog = await fs.readFile(compilerLogFile, "utf8"); -assert.match(compilerLog, /dependency cycle/); +assert.match(stderr, /circular dependency/); +assert.match(stderr, /B \(src[\\/]b\.res\)/); +await execClean(); diff --git a/tests/build_tests/cycle1/input.js b/tests/build_tests/cycle1/input.js index 91e21111aa..8423853bc0 100644 --- a/tests/build_tests/cycle1/input.js +++ b/tests/build_tests/cycle1/input.js @@ -1,17 +1,14 @@ // @ts-check import * as assert from "node:assert"; -import * as fs from "node:fs/promises"; -import * as path from "node:path"; +import { stripVTControlCharacters } from "node:util"; import { setup } from "#dev/process"; -const { execBuildLegacy, execCleanLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -await execCleanLegacy(); -const output = await execBuildLegacy(); +await execClean(); +const output = await execBuild(); +const stderr = stripVTControlCharacters(output.stderr); -assert.match(output.stdout, /is dangling/); - -const compilerLogFile = path.join("lib", "bs", ".compiler.log"); -const compilerLog = await fs.readFile(compilerLogFile, "utf8"); -assert.match(compilerLog, /is dangling/); +assert.match(stderr, /dangling/i); +await execClean(); diff --git a/tests/build_tests/devonly/input.js b/tests/build_tests/devonly/input.js index 8300ab09a5..50a4ceabd1 100644 --- a/tests/build_tests/devonly/input.js +++ b/tests/build_tests/devonly/input.js @@ -2,6 +2,6 @@ import { setup } from "#dev/process"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild } = setup(import.meta.dirname); -await execBuildLegacy(); +await execBuild(); diff --git a/tests/build_tests/exports/input.js b/tests/build_tests/exports/input.js index 50a4ceabd1..dd8449f36b 100644 --- a/tests/build_tests/exports/input.js +++ b/tests/build_tests/exports/input.js @@ -2,6 +2,7 @@ import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); await execBuild(); +await execClean(); diff --git a/tests/build_tests/gpr_978/input.js b/tests/build_tests/gpr_978/input.js index da8924057d..59db5484d0 100644 --- a/tests/build_tests/gpr_978/input.js +++ b/tests/build_tests/gpr_978/input.js @@ -1,15 +1,12 @@ // @ts-check import * as assert from "node:assert"; -import * as fs from "node:fs/promises"; -import * as path from "node:path"; +import { stripVTControlCharacters } from "node:util"; import { setup } from "#dev/process"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -const output = await execBuildLegacy(); -assert.match(output.stdout, /M is exported twice/); - -const compilerLogFile = path.join("lib", "bs", ".compiler.log"); -const compilerLog = await fs.readFile(compilerLogFile, "utf8"); -assert.match(compilerLog, /M is exported twice/); +const output = await execBuild(); +const stderr = stripVTControlCharacters(output.stderr); +assert.match(stderr, /M is exported twice/); +await execClean(); diff --git a/tests/build_tests/hyphen2/input.js b/tests/build_tests/hyphen2/input.js index 8300ab09a5..dd8449f36b 100644 --- a/tests/build_tests/hyphen2/input.js +++ b/tests/build_tests/hyphen2/input.js @@ -2,6 +2,7 @@ import { setup } from "#dev/process"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -await execBuildLegacy(); +await execBuild(); +await execClean(); diff --git a/tests/build_tests/in_source/input.js b/tests/build_tests/in_source/input.js deleted file mode 100644 index 7b5a81ea09..0000000000 --- a/tests/build_tests/in_source/input.js +++ /dev/null @@ -1,9 +0,0 @@ -// @ts-check - -import * as assert from "node:assert"; -import { setup } from "#dev/process"; - -const { execBuildLegacy } = setup(import.meta.dirname); - -const output = await execBuildLegacy(["-regen"]); -assert.match(output.stderr, /detected two module formats/); diff --git a/tests/build_tests/in_source/input.sh b/tests/build_tests/in_source/input.sh deleted file mode 100644 index a8e88ce227..0000000000 --- a/tests/build_tests/in_source/input.sh +++ /dev/null @@ -1 +0,0 @@ -rescript build -regen \ No newline at end of file diff --git a/tests/build_tests/in_source/rescript.json b/tests/build_tests/in_source/rescript.json deleted file mode 100644 index fc69fdc991..0000000000 --- a/tests/build_tests/in_source/rescript.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "x", - "sources": ".", - "package-specs": [ - { - "module": "commonjs", - "in-source": true - }, - { - "module": "esmodule", - "in-source": true - } - ] -} diff --git a/tests/build_tests/install/input.js b/tests/build_tests/install/input.js deleted file mode 100644 index 3cb39bb44e..0000000000 --- a/tests/build_tests/install/input.js +++ /dev/null @@ -1,20 +0,0 @@ -// @ts-check - -import * as assert from "node:assert"; -import { existsSync } from "node:fs"; -import * as path from "node:path"; -import { setup } from "#dev/process"; - -const { execBuildLegacy, execCleanLegacy } = setup(import.meta.dirname); - -await execCleanLegacy(); -await execBuildLegacy(["-install"]); - -let fooExists = existsSync(path.join("lib", "ocaml", "Foo.cmi")); -assert.ok(!fooExists); - -await execBuildLegacy(); -await execBuildLegacy(["-install"]); - -fooExists = existsSync(path.join("lib", "ocaml", "Foo.cmi")); -assert.ok(fooExists); diff --git a/tests/build_tests/install/rescript.json b/tests/build_tests/install/rescript.json deleted file mode 100644 index 331cb861e3..0000000000 --- a/tests/build_tests/install/rescript.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "install", - "sources": { - "dir": "src", - "subdirs": true - }, - "package-specs": { - "module": "esmodule", - "in-source": true, - "suffix": ".res.js" - }, - "dependencies": [], - "warnings": { "error": "+101" } -} diff --git a/tests/build_tests/install/src/Foo.res b/tests/build_tests/install/src/Foo.res deleted file mode 100644 index 95d72e3b10..0000000000 --- a/tests/build_tests/install/src/Foo.res +++ /dev/null @@ -1 +0,0 @@ -let main = () => Js.log("hello") diff --git a/tests/build_tests/install/src/Foo.res.js b/tests/build_tests/install/src/Foo.res.js deleted file mode 100644 index 6078c7d3cf..0000000000 --- a/tests/build_tests/install/src/Foo.res.js +++ /dev/null @@ -1,11 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - - -function main() { - console.log("hello"); -} - -export { - main, -} -/* No side effect */ diff --git a/tests/build_tests/jsx_settings_inheritance/input.js b/tests/build_tests/jsx_settings_inheritance/input.js index 03decbf153..6d8beddd22 100644 --- a/tests/build_tests/jsx_settings_inheritance/input.js +++ b/tests/build_tests/jsx_settings_inheritance/input.js @@ -2,7 +2,7 @@ import { setup } from "#dev/process"; -const { execBuildLegacy, execCleanLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -await execCleanLegacy(); -await execBuildLegacy(); +await execClean(); +await execBuild(); diff --git a/tests/build_tests/nested/input.js b/tests/build_tests/nested/input.js index ccd0bce50d..16b721cac2 100644 --- a/tests/build_tests/nested/input.js +++ b/tests/build_tests/nested/input.js @@ -5,11 +5,14 @@ import * as fs from "node:fs/promises"; import * as path from "node:path"; import { setup } from "#dev/process"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -await execBuildLegacy(); +await execBuild(); -const content = await fs.readFile(path.join("src", "demo.js"), "utf8"); +const content = await fs.readFile( + path.join(import.meta.dirname, "src", "demo.js"), + "utf8", +); assert.equal(content.match(/A00_a1_main/g)?.length, 3); assert.equal(content.match(/B00_b1_main/g)?.length, 3); @@ -20,3 +23,4 @@ assert.equal(content.match(/b0_main/g)?.length, 1); const mod = await import("./src/demo.js"); assert.equal(mod.v, 4, "nested"); +await execClean(); diff --git a/tests/build_tests/nnest/input.js b/tests/build_tests/nnest/input.js index 3d346a4475..bef91995b4 100644 --- a/tests/build_tests/nnest/input.js +++ b/tests/build_tests/nnest/input.js @@ -5,11 +5,14 @@ import * as fs from "node:fs/promises"; import * as path from "node:path"; import { setup } from "#dev/process"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -await execBuildLegacy(); +await execBuild(); -const content = await fs.readFile(path.join("src", "demo.js"), "utf8"); +const content = await fs.readFile( + path.join(import.meta.dirname, "src", "demo.js"), + "utf8", +); assert.equal(content.match(/A0_a1_main/g)?.length, 3); assert.equal(content.match(/B0_b1_main/g)?.length, 3); @@ -20,3 +23,4 @@ assert.equal(content.match(/b0_main/g)?.length, 1); const mod = await import("./src/demo.js"); assert.equal(mod.v, 4, "nested"); +await execClean(); diff --git a/tests/build_tests/not_undefined_attribute/input.res b/tests/build_tests/not_undefined_attribute/demo.res similarity index 100% rename from tests/build_tests/not_undefined_attribute/input.res rename to tests/build_tests/not_undefined_attribute/demo.res diff --git a/tests/build_tests/not_undefined_attribute/input.js b/tests/build_tests/not_undefined_attribute/input.js index 98455836ac..b37a4d14e2 100644 --- a/tests/build_tests/not_undefined_attribute/input.js +++ b/tests/build_tests/not_undefined_attribute/input.js @@ -1,23 +1,16 @@ // @ts-check import * as assert from "node:assert"; +import { stripVTControlCharacters } from "node:util"; import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -const out = await execBuildLegacy(); +const out = await execBuild(); +const stderr = normalizeNewlines(stripVTControlCharacters(out.stderr)); -assert.equal( - normalizeNewlines(out.stdout.slice(out.stdout.indexOf("input.res:2:1-12"))), - `input.res:2:1-12 - - 1 │ @notUndefined - 2 │ type t = int - 3 │ - - @notUndefined can only be used on abstract types - -FAILED: cannot make progress due to previous errors. -`, -); +assert.ok(stderr.includes("demo.res:2:1-12")); +assert.ok(stderr.includes("@notUndefined can only be used on abstract types")); +assert.ok(stderr.includes("Failed to Compile")); +await execClean(); diff --git a/tests/build_tests/ns/input.js b/tests/build_tests/ns/input.js index 8300ab09a5..50a4ceabd1 100755 --- a/tests/build_tests/ns/input.js +++ b/tests/build_tests/ns/input.js @@ -2,6 +2,6 @@ import { setup } from "#dev/process"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild } = setup(import.meta.dirname); -await execBuildLegacy(); +await execBuild(); diff --git a/tests/build_tests/post-build/input.js b/tests/build_tests/post-build/input.js index 83fd43098f..97c5c5c5ea 100644 --- a/tests/build_tests/post-build/input.js +++ b/tests/build_tests/post-build/input.js @@ -3,7 +3,7 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); if (process.platform === "win32") { console.log("Skipping test on Windows"); @@ -15,3 +15,5 @@ const out = await execBuild(); if (out.status !== 0) { assert.fail(out.stdout + out.stderr); } + +await execClean(); diff --git a/tests/build_tests/react_ppx/input.js b/tests/build_tests/react_ppx/input.js index 8300ab09a5..50a4ceabd1 100644 --- a/tests/build_tests/react_ppx/input.js +++ b/tests/build_tests/react_ppx/input.js @@ -2,6 +2,6 @@ import { setup } from "#dev/process"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild } = setup(import.meta.dirname); -await execBuildLegacy(); +await execBuild(); diff --git a/tests/build_tests/rerror/input.js b/tests/build_tests/rerror/input.js index ddcbd1ad7d..44a9f982e0 100644 --- a/tests/build_tests/rerror/input.js +++ b/tests/build_tests/rerror/input.js @@ -1,17 +1,19 @@ // @ts-check import * as assert from "node:assert"; +import { stripVTControlCharacters } from "node:util"; import { setup } from "#dev/process"; -const { execBuildLegacy, execCleanLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -await execCleanLegacy(); -const output = await execBuildLegacy([]); +await execClean(); +const output = await execBuild(); +const stderr = stripVTControlCharacters(output.stderr); // verify the output is in reason syntax -const u = output.stdout.match(/=>/g); +const u = stderr.match(/=>/g); -const lines = output.stdout +const lines = stderr .split(/\r?\n/) .map(x => x.trim()) .filter(Boolean); @@ -19,10 +21,10 @@ const lines = output.stdout let test = false; for (let i = 0; i < lines.length; i++) { if (lines[i] === "We've found a bug for you!") { - console.log(`line ${i} found`); assert.match(lines[i + 1], /src[\\/]demo.res:1:21-23/); test = true; } } assert.ok(test); assert.equal(u?.length, 2); +await execClean(); diff --git a/tests/build_tests/scoped_ppx/.gitignore b/tests/build_tests/scoped_ppx/.gitignore deleted file mode 100644 index 1e5a96ef36..0000000000 --- a/tests/build_tests/scoped_ppx/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.merlin -!node_modules \ No newline at end of file diff --git a/tests/build_tests/scoped_ppx/input.js b/tests/build_tests/scoped_ppx/input.js deleted file mode 100644 index ff1426845f..0000000000 --- a/tests/build_tests/scoped_ppx/input.js +++ /dev/null @@ -1,19 +0,0 @@ -// @ts-check - -import * as assert from "node:assert"; -import { setup } from "#dev/process"; - -const { execBuildLegacy } = setup(import.meta.dirname); - -if (process.platform === "win32") { - console.log("Skipping test on Windows"); - process.exit(0); -} - -await execBuildLegacy(); -const output = await execBuildLegacy(["--", "-t", "commands", "src/hello.ast"]); - -assert.match( - output.stdout, - /-ppx '.*\/test\.js -hello' -ppx '.*\/test\.js -heyy' -ppx .*test\.js/, -); diff --git a/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/package.json b/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/package.json deleted file mode 100644 index 5bbefffbab..0000000000 --- a/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "commonjs" -} diff --git a/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/test.js b/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/test.js deleted file mode 100755 index e0ec31c3e2..0000000000 --- a/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/test.js +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env node - -// @ts-check - -const fs = require('node:fs') - -const file_in = process.argv[process.argv.length - 2] -const file_out = process.argv[process.argv.length - 1] - -fs.createReadStream(file_in) - .pipe(fs.createWriteStream(file_out)) diff --git a/tests/build_tests/scoped_ppx/rescript.json b/tests/build_tests/scoped_ppx/rescript.json deleted file mode 100644 index 42483ad370..0000000000 --- a/tests/build_tests/scoped_ppx/rescript.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ppx-flags": [ - ["@hongbo/ppx1/test.js", "-hello"], - ["@hongbo/ppx1/test.js", "-heyy"], - "@hongbo/ppx1/test.js" - ], - "sources": { - "dir": "src" - }, - "name": "hello" -} diff --git a/tests/build_tests/scoped_ppx/src/hello.res b/tests/build_tests/scoped_ppx/src/hello.res deleted file mode 100644 index ab49c6303b..0000000000 --- a/tests/build_tests/scoped_ppx/src/hello.res +++ /dev/null @@ -1 +0,0 @@ -let v = 1 diff --git a/tests/build_tests/transitive_dependency/input.js b/tests/build_tests/transitive_dependency/input.js index d13102583a..765a1f4c7a 100644 --- a/tests/build_tests/transitive_dependency/input.js +++ b/tests/build_tests/transitive_dependency/input.js @@ -2,14 +2,25 @@ import * as assert from "node:assert"; import { existsSync } from "node:fs"; +import * as path from "node:path"; import { setup } from "#dev/process"; -const { execBuildLegacy, execCleanLegacy } = setup("./a"); -await execCleanLegacy(); -const output = await execBuildLegacy(); -console.log(output); +const { execBuild, execClean } = setup(path.join(import.meta.dirname, "a")); +await execClean(); +await execBuild(); assert.ok( - !existsSync("./node_modules/c/lib/es6/tests/test.res.js"), + !existsSync( + path.join( + import.meta.dirname, + "a", + "node_modules", + "c", + "lib", + "es6", + "tests", + "test.res.js", + ), + ), "dev files of module 'c' were built by 'a' even though 'c' is not a dependency of 'a'", ); diff --git a/tests/build_tests/unboxed_bool_with_const/input.js b/tests/build_tests/unboxed_bool_with_const/input.js index 337065eed9..623e0ab097 100644 --- a/tests/build_tests/unboxed_bool_with_const/input.js +++ b/tests/build_tests/unboxed_bool_with_const/input.js @@ -1,25 +1,20 @@ // @ts-check import * as assert from "node:assert"; +import { stripVTControlCharacters } from "node:util"; import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -const out = await execBuildLegacy(); +const out = await execBuild(); +const stderr = normalizeNewlines(stripVTControlCharacters(out.stderr)); -assert.equal( - normalizeNewlines(out.stdout.slice(out.stdout.indexOf("Main.res:3:3-14"))), - `Main.res:3:3-14 - - 1 │ @unboxed - 2 │ type t<'a> = - 3 │ | Bool(bool) - 4 │ | @as(false) False - 5 │ | @as(true) True - - This untagged variant definition is invalid: At most one case can be a boolean type. - -FAILED: cannot make progress due to previous errors. -`, +assert.ok(stderr.includes("Main.res:3:3-14")); +assert.ok( + stderr.includes( + "This untagged variant definition is invalid: At most one case can be a boolean type.", + ), ); +assert.ok(stderr.includes("Failed to Compile")); +await execClean(); diff --git a/tests/build_tests/uncurried-always/input.js b/tests/build_tests/uncurried-always/input.js index 03decbf153..dd8449f36b 100644 --- a/tests/build_tests/uncurried-always/input.js +++ b/tests/build_tests/uncurried-always/input.js @@ -2,7 +2,7 @@ import { setup } from "#dev/process"; -const { execBuildLegacy, execCleanLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -await execCleanLegacy(); -await execBuildLegacy(); +await execBuild(); +await execClean(); diff --git a/tests/build_tests/unicode/input.js b/tests/build_tests/unicode/input.js index 44f701627d..c6cdc701f8 100644 --- a/tests/build_tests/unicode/input.js +++ b/tests/build_tests/unicode/input.js @@ -1,21 +1,19 @@ // @ts-check -import * as assert from "node:assert"; import * as fs from "node:fs/promises"; import * as path from "node:path"; import { setup } from "#dev/process"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); if (process.platform === "win32") { console.log("Skipping test on Windows"); process.exit(0); } -await execBuildLegacy(); -const content = await fs.readFile( - path.join("lib", "bs", ".sourcedirs.json"), - "utf-8", -); +await execBuild(); -assert.ok(JSON.parse(content).dirs.some(x => x.includes("📕annotation"))); +await fs.access( + path.join(import.meta.dirname, "lib", "bs", "src", "📕annotation", "a.js"), +); +await execClean(); diff --git a/tests/build_tests/unicode/rescript.json b/tests/build_tests/unicode/rescript.json index a8065db935..b5bd5c237a 100644 --- a/tests/build_tests/unicode/rescript.json +++ b/tests/build_tests/unicode/rescript.json @@ -1,7 +1,7 @@ { "name": "unicode", "sources": { - "dir": ".", + "dir": "src", "subdirs": true } } diff --git "a/tests/build_tests/unicode/\360\237\223\225annotation/a.res" "b/tests/build_tests/unicode/src/\360\237\223\225annotation/a.res" similarity index 100% rename from "tests/build_tests/unicode/\360\237\223\225annotation/a.res" rename to "tests/build_tests/unicode/src/\360\237\223\225annotation/a.res" diff --git "a/tests/build_tests/unicode/\360\237\223\227block/b.res" "b/tests/build_tests/unicode/src/\360\237\223\227block/b.res" similarity index 100% rename from "tests/build_tests/unicode/\360\237\223\227block/b.res" rename to "tests/build_tests/unicode/src/\360\237\223\227block/b.res" diff --git "a/tests/build_tests/unicode/\360\237\223\231inline/c.res" "b/tests/build_tests/unicode/src/\360\237\223\231inline/c.res" similarity index 100% rename from "tests/build_tests/unicode/\360\237\223\231inline/c.res" rename to "tests/build_tests/unicode/src/\360\237\223\231inline/c.res" diff --git a/tests/build_tests/warn_legacy_config/input.js b/tests/build_tests/warn_legacy_config/input.js index caa8c1e192..ab47cb886f 100644 --- a/tests/build_tests/warn_legacy_config/input.js +++ b/tests/build_tests/warn_legacy_config/input.js @@ -3,10 +3,9 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -const output = await execBuildLegacy(); -assert.match( - output.stdout, - /^Warning: bsconfig.json is deprecated. Migrate it to rescript.json/, -); +const output = await execBuild(); +assert.notEqual(output.status, 0); +assert.match(output.stderr, /no package\.json or rescript\.json file/i); +await execClean(); diff --git a/tests/build_tests/weird_deps/input.js b/tests/build_tests/weird_deps/input.js index 6e6f7a4cc5..1675283d2e 100644 --- a/tests/build_tests/weird_deps/input.js +++ b/tests/build_tests/weird_deps/input.js @@ -2,21 +2,10 @@ import * as assert from "node:assert"; import { setup } from "#dev/process"; -import { normalizeNewlines } from "#dev/utils"; +const { execBuild, execClean } = setup(import.meta.dirname); -const { execBuildLegacy } = setup(import.meta.dirname); - -const out = await execBuildLegacy(); -if (out.stdout !== "") { - assert.fail(out.stdout); -} else { - assert.equal( - normalizeNewlines(out.stderr), - [ - 'File "rescript.json", line 1', - "Error: package weird not found or built", - "- Did you install it?", - "", - ].join("\n"), - ); -} +const out = await execBuild(); +assert.notEqual(out.status, 0); +assert.match(out.stderr, /could not build package tree/i); +assert.match(out.stderr, /dependency 'weird'/i); +await execClean(); diff --git a/tests/build_tests/weird_devdeps/input.js b/tests/build_tests/weird_devdeps/input.js index cc30a015b8..d98217346b 100644 --- a/tests/build_tests/weird_devdeps/input.js +++ b/tests/build_tests/weird_devdeps/input.js @@ -1,22 +1,12 @@ // @ts-check import * as assert from "node:assert"; -import * as os from "node:os"; import { setup } from "#dev/process"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -const out = await execBuildLegacy(); -if (out.stdout !== "") { - assert.fail(out.stdout); -} else { - assert.equal( - out.stderr, - [ - 'File "rescript.json", line 1', - "Error: package weird not found or built", - "- Did you install it?", - "", - ].join(os.EOL), - ); -} +const out = await execBuild(); +assert.notEqual(out.status, 0); +assert.match(out.stderr, /could not build package tree/i); +assert.match(out.stderr, /dependency 'weird'/i); +await execClean(); diff --git a/tests/build_tests/weird_names/input.js b/tests/build_tests/weird_names/input.js index 92fcaf7f26..8eb69b1529 100644 --- a/tests/build_tests/weird_names/input.js +++ b/tests/build_tests/weird_names/input.js @@ -4,9 +4,9 @@ import * as assert from "node:assert"; import * as path from "node:path"; import { setup } from "#dev/process"; -const { execBuildLegacy } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); -const out = await execBuildLegacy(); +const out = await execBuild(); if (out.stderr !== "") { assert.fail(out.stderr); @@ -24,6 +24,7 @@ const files = [ for (const f of files) { const { name } = path.parse(f); - const mod = await import(`./lib/es6/src/${name}.js`); + const mod = await import(`./src/${name}.js`); assert.deepEqual(mod.a, 1); } +await execClean(); diff --git a/tests/build_tests/weird_names_not_found_bug/input.js b/tests/build_tests/weird_names_not_found_bug/input.js index 9861ed7731..ed8ab223c6 100644 --- a/tests/build_tests/weird_names_not_found_bug/input.js +++ b/tests/build_tests/weird_names_not_found_bug/input.js @@ -1,14 +1,11 @@ import * as assert from "node:assert"; +import { stripVTControlCharacters } from "node:util"; import { setup } from "#dev/process"; -const { execBuildLegacy } = await setup(import.meta.dirname); +const { execBuild, execClean } = await setup(import.meta.dirname); -const out = await execBuildLegacy(); +const out = await execBuild(); +const stderr = stripVTControlCharacters(out.stderr); -if (out.stderr !== "") { - assert.fail(out.stderr); -} - -if (!out.stdout.includes(`The module or file Demo can't be found.`)) { - assert.fail(out.stdout); -} +assert.ok(stderr.includes(`The module or file Demo can't be found.`)); +await execClean(); diff --git a/tests/build_tests/x-y/input.js b/tests/build_tests/x-y/input.js index 50a4ceabd1..dd8449f36b 100644 --- a/tests/build_tests/x-y/input.js +++ b/tests/build_tests/x-y/input.js @@ -2,6 +2,7 @@ import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); await execBuild(); +await execClean(); diff --git a/tests/build_tests/xpkg/input.js b/tests/build_tests/xpkg/input.js deleted file mode 100644 index 2d745b93b8..0000000000 --- a/tests/build_tests/xpkg/input.js +++ /dev/null @@ -1,9 +0,0 @@ -// @ts-check - -import * as assert from "node:assert"; -import { setup } from "#dev/process"; - -const { execBuildLegacy } = await setup(import.meta.dirname); - -const output = await execBuildLegacy(["-regen"]); -assert.match(output.stderr, /reserved package name/); diff --git a/tests/build_tests/xpkg/rescript.json b/tests/build_tests/xpkg/rescript.json deleted file mode 100644 index 50b8ac6da2..0000000000 --- a/tests/build_tests/xpkg/rescript.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "_", - "sources": "." -}