From bab23ad6b82678881c3c7be329bf17b5c104b626 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 27 Nov 2026 06:16:42 +0000 Subject: [PATCH 1/4] Run all build system tests from make test-build make test-build ran only the integration suite. The unit tests and the isolated scripts ran only in CI, where each command was spelled out in ci.yml. tests/build_tests/Makefile now has a target per suite (unit, snapshots, verbose, interactive, isolated, integration) and test for all of them; make test-build runs that after building the runtime, and CI calls the single targets. scripts/test.js -build, which runs the projects and the error tests, is now -projects. The integration suite's check for leftover processes matched any process that named the executable in its arguments. Started from make with an absolute path, it found make and itself. It now counts only processes that run the executable. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kbf3gLP8xKdoF8ZA2WZNCo Signed-off-by: Christoph Knittel --- .github/workflows/ci.yml | 30 +++++++----------- CONTRIBUTING.md | 4 +-- Makefile | 2 +- build_system/AGENTS.md | 8 ++--- build_system/README.md | 7 +++-- changes/make-test-build-all.internal.md | 1 + scripts/test.js | 10 +++--- tests/build_tests/Makefile | 41 +++++++++++++++++++++++++ tests/build_tests/README.md | 9 +++--- tests/build_tests/integration/suite.sh | 18 +++++++++-- 10 files changed, 88 insertions(+), 42 deletions(-) create mode 100644 changes/make-test-build-all.internal.md create mode 100644 tests/build_tests/Makefile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebabab77f8..2c0fc5fa39 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -191,7 +191,7 @@ jobs: # The format check gives the same result everywhere; it runs on Linux # only, where it is fastest. - name: Run tests - run: node scripts/test.js ${{ runner.os == 'Linux' && '-all' || '-ounit -mocha -build -docstrings' }} + run: node scripts/test.js ${{ runner.os == 'Linux' && '-all' || '-ounit -mocha -projects -docstrings' }} - name: Check for diffs in tests folder run: git diff --ignore-cr-at-eol --exit-code tests @@ -230,13 +230,8 @@ jobs: if: ${{ !matrix.skip_build_system_integration_tests }} timeout-minutes: 20 run: | - . tests/build_tests/isolated/process_watchdog.sh - start_process_watchdog - bash tests/build_tests/isolated/check_integration_test_coverage.sh - bash tests/build_tests/isolated/check_config_acceptance.sh \ - packages/@rescript/${{ matrix.node-target }}/bin/rescript.exe - bash tests/build_tests/isolated/check_command_validation.sh \ - packages/@rescript/${{ matrix.node-target }}/bin/rescript.exe + make -C tests/build_tests snapshots \ + RESCRIPT="$PWD/packages/@rescript/${{ matrix.node-target }}/bin/rescript.exe" shell: bash - name: Run build system interactive output tests @@ -246,25 +241,21 @@ jobs: if: matrix.node-target == 'linux-arm64' || matrix.node-target == 'darwin-arm64' timeout-minutes: 15 run: | - bash tests/build_tests/isolated/check_interactive_output.sh \ - packages/@rescript/${{ matrix.node-target }}/bin/rescript.exe + make -C tests/build_tests interactive \ + RESCRIPT="$PWD/packages/@rescript/${{ matrix.node-target }}/bin/rescript.exe" shell: bash - name: Run build system verbose output tests if: ${{ !matrix.skip_build_system_integration_tests }} timeout-minutes: 10 run: | - bash tests/build_tests/isolated/check_verbose_output.sh \ - packages/@rescript/${{ matrix.node-target }}/bin/rescript.exe + make -C tests/build_tests verbose \ + RESCRIPT="$PWD/packages/@rescript/${{ matrix.node-target }}/bin/rescript.exe" shell: bash - name: Run build system unit tests timeout-minutes: 10 - run: | - opam exec -- dune build tests/build_tests/unit/build_system_tests_main.exe - # Run the executable directly so a stuck test leaves live progress; - # dune otherwise buffers the test output until the action exits. - opam exec -- ./_build/default/tests/build_tests/unit/build_system_tests_main.exe -runner sequential + run: opam exec -- make -C tests/build_tests unit shell: bash # The integration suite works in tests/build_tests/testrepo and the @@ -281,11 +272,12 @@ jobs: mkdir -p tmp cp -R "$bin" tmp/integration-bin integration_log=tmp/integration-tests.log - ./tests/build_tests/integration/suite.sh tmp/integration-bin/rescript.exe >"$integration_log" 2>&1 & + make -C tests/build_tests integration RESCRIPT="$PWD/tmp/integration-bin/rescript.exe" \ + >"$integration_log" 2>&1 & integration=$! isolated_status=0 - sh tests/build_tests/isolated/run.sh "$bin/rescript.exe" || isolated_status=$? + make -C tests/build_tests isolated RESCRIPT="$PWD/$bin/rescript.exe" || isolated_status=$? integration_status=0 wait "$integration" || integration_status=$? diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b0ef28b11b..5ad2b515d2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -296,12 +296,12 @@ node scripts/test.js -mocha **Run build, project and error tests:** -This will run the test projects in `tests/build_tests` (build system), +This will run the test projects in `tests/build_tests/projects` (build system), `tests/project_tests` (compiler end-to-end) and `tests/error_tests` (error message snapshots). ``` -node scripts/test.js -build +node scripts/test.js -projects ``` **Run ounit tests:** diff --git a/Makefile b/Makefile index a32df873b9..a528708243 100644 --- a/Makefile +++ b/Makefile @@ -157,7 +157,7 @@ test-gentype: lib make -C tests/gentype_tests/stdlib-no-shims clean test test-build: lib - ./tests/build_tests/integration/suite.sh $(RESCRIPT_EXE) + $(MAKE) -C tests/build_tests test RESCRIPT=$(abspath $(RESCRIPT_EXE)) test-all: test test-gentype test-analysis test-tools test-build diff --git a/build_system/AGENTS.md b/build_system/AGENTS.md index df38f3fbd7..ec8ae2ea84 100644 --- a/build_system/AGENTS.md +++ b/build_system/AGENTS.md @@ -32,10 +32,8 @@ repository root. ## Testing -- Unit tests: `dune runtest tests/build_tests/unit`. -- Isolated end-to-end tests: - `sh tests/build_tests/isolated/run.sh "$PWD/packages/@rescript//bin/rescript.exe"`. -- Integration suite: `make test-build`. Run it for any change to build - behavior. +- All build system tests: `make test-build`. Run it for any change to build + behavior. Single suites: `make -C tests/build_tests unit`, `isolated`, + `snapshots`, `verbose`, `interactive` or `integration`. - Add a test for every bug fix. Prefer the integration suite in `tests/build_tests/integration`. Poll for observable conditions instead of sleeping. diff --git a/build_system/README.md b/build_system/README.md index d924683fdf..cb3cd46f68 100644 --- a/build_system/README.md +++ b/build_system/README.md @@ -182,9 +182,10 @@ Windows CI. ## Testing ```sh -dune runtest tests/build_tests/unit # unit tests -sh tests/build_tests/isolated/run.sh "$PWD/packages/@rescript//bin/rescript.exe" # isolated end-to-end tests -make test-build # integration suite in tests/build_tests/integration +make test-build # all build system tests +make -C tests/build_tests unit # unit tests +make -C tests/build_tests isolated # isolated end-to-end tests +make -C tests/build_tests integration # integration suite in tests/build_tests/integration ``` The scripts in `tests/build_tests/isolated/check_*.sh` check configuration diff --git a/changes/make-test-build-all.internal.md b/changes/make-test-build-all.internal.md new file mode 100644 index 0000000000..d7d2f2740e --- /dev/null +++ b/changes/make-test-build-all.internal.md @@ -0,0 +1 @@ +- `make test-build` runs all build system tests (unit, isolated and integration) through `tests/build_tests/Makefile`, whose targets CI calls; `scripts/test.js -build` is now `-projects`. diff --git a/scripts/test.js b/scripts/test.js index 820c364aa6..1a66e91b28 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -26,7 +26,7 @@ import { let ounitTest = false; let mochaTest = false; -let buildTest = false; +let projectTest = false; let formatTest = false; let runtimeDocstrings = false; @@ -38,8 +38,8 @@ if (process.argv.includes("-mocha")) { mochaTest = true; } -if (process.argv.includes("-build")) { - buildTest = true; +if (process.argv.includes("-projects")) { + projectTest = true; } if (process.argv.includes("-format")) { @@ -53,7 +53,7 @@ if (process.argv.includes("-docstrings")) { if (process.argv.includes("-all")) { ounitTest = true; mochaTest = true; - buildTest = true; + projectTest = true; formatTest = true; runtimeDocstrings = true; } @@ -153,7 +153,7 @@ if (mochaTest) { }); } -if (buildTest) { +if (projectTest) { // Each directory below these suites with an input.js is one test. const suites = [buildTestDir, projectTestDir, errorTestDir]; let hasError = false; diff --git a/tests/build_tests/Makefile b/tests/build_tests/Makefile new file mode 100644 index 0000000000..3782deb0f4 --- /dev/null +++ b/tests/build_tests/Makefile @@ -0,0 +1,41 @@ +SHELL = /bin/bash + +# The build system's tests (see README.md). `make test-build` at the +# repository root builds the toolchain and runtime and then runs `test`; CI +# runs the targets one at a time. RESCRIPT is the executable under test, by +# default the one in the platform package; pass an absolute path to override. + +ROOT := $(abspath ../..) +RESCRIPT ?= $(shell node -p "require('$(ROOT)/cli/common/bins.cjs').rescript_exe") + +test: unit snapshots verbose interactive isolated integration + +# OUnit tests of the build system's modules. The executable runs directly, not +# through `dune test`, so a stuck test still shows its progress. +unit: + cd $(ROOT) && dune build tests/build_tests/unit/build_system_tests_main.exe + $(ROOT)/_build/default/tests/build_tests/unit/build_system_tests_main.exe -runner sequential + +# Output snapshots of configuration acceptance and command validation, and the +# check that suite.sh runs every integration script. On Windows CI they run +# under a watchdog that stops runaway processes. +snapshots: + . isolated/process_watchdog.sh && start_process_watchdog && \ + bash isolated/check_integration_test_coverage.sh && \ + bash isolated/check_config_acceptance.sh "$(RESCRIPT)" && \ + bash isolated/check_command_validation.sh "$(RESCRIPT)" + +verbose: + bash isolated/check_verbose_output.sh "$(RESCRIPT)" + +# Needs the `script` PTY, which Windows lacks. +interactive: + bash isolated/check_interactive_output.sh "$(RESCRIPT)" + +isolated: + sh isolated/run.sh "$(RESCRIPT)" + +integration: + ./integration/suite.sh "$(RESCRIPT)" + +.PHONY: test unit snapshots verbose interactive isolated integration diff --git a/tests/build_tests/README.md b/tests/build_tests/README.md index 7deac1ecf3..3a2751cc56 100644 --- a/tests/build_tests/README.md +++ b/tests/build_tests/README.md @@ -25,10 +25,11 @@ which are not recommended for new projects. Run commands from the repository root: ```sh -make test-build # integration suite -dune runtest tests/build_tests/unit # unit tests -sh tests/build_tests/isolated/run.sh "$PWD/packages/@rescript//bin/rescript.exe" -node scripts/test.js -build # projects (with project_tests and error_tests) +make test-build # all of the suites below +make -C tests/build_tests unit # unit tests +make -C tests/build_tests isolated # isolated/run.sh; also snapshots, verbose, interactive +make -C tests/build_tests integration # integration suite +node scripts/test.js -projects # projects (with project_tests and error_tests) ``` The integration suite is [`integration/suite.sh`](integration/suite.sh). It diff --git a/tests/build_tests/integration/suite.sh b/tests/build_tests/integration/suite.sh index 81e10e2015..e7cb7891b7 100755 --- a/tests/build_tests/integration/suite.sh +++ b/tests/build_tests/integration/suite.sh @@ -26,11 +26,23 @@ fi source ./utils.sh +# Processes that run the executable under test. Processes that only name it in +# their arguments, like this script and the make that started it, don't count. +# The ps of Git for Windows has no -o and lists only the program, without its +# arguments, so there the plain match is enough. +executable_processes() { + if ps -eo pid=,args= >/dev/null 2>&1; then + ps -eo pid=,args= | awk -v exe="$RESCRIPT_EXECUTABLE" '$2 == exe' + else + ps aux | grep -F "$RESCRIPT_EXECUTABLE" | grep -v grep + fi +} + bold "Check for stale rescript processes" -STALE_PIDS=$(ps aux | grep "$RESCRIPT_EXECUTABLE" | grep -v grep | awk '{print $2}') -if [ -n "$STALE_PIDS" ]; then +STALE_PROCESSES=$(executable_processes) +if [ -n "$STALE_PROCESSES" ]; then error "Found stale rescript processes using this executable:" - ps aux | grep "$RESCRIPT_EXECUTABLE" | grep -v grep + echo "$STALE_PROCESSES" exit 1 fi success "No stale rescript processes found" From f19ec24128b902551e6eb1806ff9851cb15868db Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 27 Nov 2026 06:34:37 +0000 Subject: [PATCH 2/4] Keep the integration suite running when no process matches on Windows Git for Windows' ps has no -o, so the leftover-process check falls back to grep, which exits 1 when it finds nothing. Under set -e that ended the suite before its first test. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kbf3gLP8xKdoF8ZA2WZNCo Signed-off-by: Christoph Knittel --- tests/build_tests/integration/suite.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/build_tests/integration/suite.sh b/tests/build_tests/integration/suite.sh index e7cb7891b7..44e7da882b 100755 --- a/tests/build_tests/integration/suite.sh +++ b/tests/build_tests/integration/suite.sh @@ -29,12 +29,13 @@ source ./utils.sh # Processes that run the executable under test. Processes that only name it in # their arguments, like this script and the make that started it, don't count. # The ps of Git for Windows has no -o and lists only the program, without its -# arguments, so there the plain match is enough. +# arguments, so there the plain match is enough. grep finding nothing is the +# normal case and must not end the script under set -e. executable_processes() { if ps -eo pid=,args= >/dev/null 2>&1; then ps -eo pid=,args= | awk -v exe="$RESCRIPT_EXECUTABLE" '$2 == exe' else - ps aux | grep -F "$RESCRIPT_EXECUTABLE" | grep -v grep + ps aux | grep -F "$RESCRIPT_EXECUTABLE" | grep -v grep || true fi } From 7bdd4e035cd5b9e51f939ccdd77d4628e98c8c27 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 27 Nov 2026 09:03:39 +0000 Subject: [PATCH 3/4] Let the integration suite run alongside the other build tests Its check for leftover processes aborts when another process runs its executable. With make -j, the suites of make test-build (or other make targets) could run at the same time on the same binary. The integration target now runs a copy of the binaries, as CI did by hand, and CI no longer makes its own copy. Answers the Codex review on #9445. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kbf3gLP8xKdoF8ZA2WZNCo Signed-off-by: Christoph Knittel --- .github/workflows/ci.yml | 10 ++++------ tests/build_tests/Makefile | 9 ++++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c0fc5fa39..1461c92a30 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -260,19 +260,17 @@ jobs: # The integration suite works in tests/build_tests/testrepo and the # isolated one in directories of its own, so they run side by side; each - # takes one to three and a half minutes. The integration suite fails when - # another process runs its executable as it starts, so it runs a copy. - # Its output is shown once both are done. + # takes one to three and a half minutes. The integration target runs a + # copy of the binaries, so the isolated suite's processes don't count as + # leftovers. Its output is shown once both are done. - name: Run build system integration and isolated tests if: ${{ !matrix.skip_build_system_integration_tests }} timeout-minutes: 30 run: | bin=packages/@rescript/${{ matrix.node-target }}/bin - rm -rf tmp/integration-bin mkdir -p tmp - cp -R "$bin" tmp/integration-bin integration_log=tmp/integration-tests.log - make -C tests/build_tests integration RESCRIPT="$PWD/tmp/integration-bin/rescript.exe" \ + make -C tests/build_tests integration RESCRIPT="$PWD/$bin/rescript.exe" \ >"$integration_log" 2>&1 & integration=$! diff --git a/tests/build_tests/Makefile b/tests/build_tests/Makefile index 3782deb0f4..7671cfaec0 100644 --- a/tests/build_tests/Makefile +++ b/tests/build_tests/Makefile @@ -35,7 +35,14 @@ interactive: isolated: sh isolated/run.sh "$(RESCRIPT)" +# The suite fails when another process runs its executable as it starts, so it +# runs a copy of the binaries: the other suites, run alongside it with -j or by +# another make, use the original. integration: - ./integration/suite.sh "$(RESCRIPT)" + mkdir -p $(ROOT)/tmp + bin=$$(mktemp -d "$(ROOT)/tmp/integration-bin.XXXXXX") && \ + cp -R "$$(dirname "$(RESCRIPT)")"/. "$$bin" && \ + { ./integration/suite.sh "$$bin/$$(basename "$(RESCRIPT)")"; status=$$?; \ + rm -rf "$$bin"; exit $$status; } .PHONY: test unit snapshots verbose interactive isolated integration From 8e7278472abd7437bffe833cec118c7bc07c80d2 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 27 Nov 2026 09:36:57 +0000 Subject: [PATCH 4/4] Catch leftover watchers again in the integration target Each run copied the binaries to a new temporary directory, so the suite's check for leftover processes could never match a watcher from an interrupted earlier run, and the copies piled up after Ctrl-C. The copy now always goes to tmp/integration-bin. The check also counts node running the cli/rescript.js script, the default RESCRIPT is resolved through a relative path that node understands under an MSYS make, and the docs no longer say that make test-build runs the projects. Answers the Fable review of stack #9449. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kbf3gLP8xKdoF8ZA2WZNCo Signed-off-by: Christoph Knittel --- Makefile | 4 ++-- tests/build_tests/Makefile | 19 ++++++++++++------- tests/build_tests/README.md | 4 ++-- tests/build_tests/integration/suite.sh | 9 ++++++--- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index a528708243..b2e86f0663 100644 --- a/Makefile +++ b/Makefile @@ -230,7 +230,7 @@ semantic-diff: # make coverage # run full test suite, generate report # make clean-coverage # remove coverage artifacts # -# Suites covered: the `scripts/test.js -all` suites (mocha/build/ounit/ +# Suites covered: the `scripts/test.js -all` suites (mocha/projects/ounit/ # docstrings), the syntax tests (syntax/, via the instrumented # res_parser), the gentype tests (compiler/gentype, via the instrumented # bsc) and the analysis + tools tests, including reanalyze (analysis/, via @@ -286,7 +286,7 @@ coverage-lib: coverage-prepare # Run the test suites that exercise the instrumented toolchain. Each suite # shells out to a binary that `coverage-build` instrumented: -# - `node scripts/test.js -all` drives bsc (mocha/build/ounit/docstrings). +# - `node scripts/test.js -all` drives bsc (mocha/projects/ounit/docstrings). # - the syntax tests drive the instrumented `res_parser` from # _build/install/default/bin, adding coverage for syntax/. # ROUNDTRIP_TEST=1 matches Linux CI and also exercises the printer paths. diff --git a/tests/build_tests/Makefile b/tests/build_tests/Makefile index 7671cfaec0..363718187c 100644 --- a/tests/build_tests/Makefile +++ b/tests/build_tests/Makefile @@ -6,7 +6,9 @@ SHELL = /bin/bash # default the one in the platform package; pass an absolute path to override. ROOT := $(abspath ../..) -RESCRIPT ?= $(shell node -p "require('$(ROOT)/cli/common/bins.cjs').rescript_exe") +# Relative, so that a make that spells paths the MSYS way still gives node +# a path it can resolve. +RESCRIPT ?= $(shell node -p "require('../../cli/common/bins.cjs').rescript_exe") test: unit snapshots verbose interactive isolated integration @@ -37,12 +39,15 @@ isolated: # The suite fails when another process runs its executable as it starts, so it # runs a copy of the binaries: the other suites, run alongside it with -j or by -# another make, use the original. +# another make, use the original. The copy's path is always the same, so a +# watcher left by an interrupted earlier run still counts as a leftover, and +# the next run replaces it. +INTEGRATION_BIN := $(ROOT)/tmp/integration-bin + integration: - mkdir -p $(ROOT)/tmp - bin=$$(mktemp -d "$(ROOT)/tmp/integration-bin.XXXXXX") && \ - cp -R "$$(dirname "$(RESCRIPT)")"/. "$$bin" && \ - { ./integration/suite.sh "$$bin/$$(basename "$(RESCRIPT)")"; status=$$?; \ - rm -rf "$$bin"; exit $$status; } + rm -rf "$(INTEGRATION_BIN)" + mkdir -p "$(INTEGRATION_BIN)" + cp -R "$$(dirname "$(RESCRIPT)")"/. "$(INTEGRATION_BIN)" + ./integration/suite.sh "$(INTEGRATION_BIN)/$$(basename "$(RESCRIPT)")" .PHONY: test unit snapshots verbose interactive isolated integration diff --git a/tests/build_tests/README.md b/tests/build_tests/README.md index 3a2751cc56..a7abdce786 100644 --- a/tests/build_tests/README.md +++ b/tests/build_tests/README.md @@ -25,11 +25,11 @@ which are not recommended for new projects. Run commands from the repository root: ```sh -make test-build # all of the suites below +make test-build # unit, isolated and integration suites make -C tests/build_tests unit # unit tests make -C tests/build_tests isolated # isolated/run.sh; also snapshots, verbose, interactive make -C tests/build_tests integration # integration suite -node scripts/test.js -projects # projects (with project_tests and error_tests) +node scripts/test.js -projects # projects (part of make test, with project_tests and error_tests) ``` The integration suite is [`integration/suite.sh`](integration/suite.sh). It diff --git a/tests/build_tests/integration/suite.sh b/tests/build_tests/integration/suite.sh index 44e7da882b..47066b8fbe 100755 --- a/tests/build_tests/integration/suite.sh +++ b/tests/build_tests/integration/suite.sh @@ -26,14 +26,17 @@ fi source ./utils.sh -# Processes that run the executable under test. Processes that only name it in -# their arguments, like this script and the make that started it, don't count. +# Processes that run the executable under test, directly or, for the +# cli/rescript.js script, through node. Processes that only name it among +# their other arguments, like this script and the make that started it, don't +# count. # The ps of Git for Windows has no -o and lists only the program, without its # arguments, so there the plain match is enough. grep finding nothing is the # normal case and must not end the script under set -e. executable_processes() { if ps -eo pid=,args= >/dev/null 2>&1; then - ps -eo pid=,args= | awk -v exe="$RESCRIPT_EXECUTABLE" '$2 == exe' + ps -eo pid=,args= | awk -v exe="$RESCRIPT_EXECUTABLE" \ + '$2 == exe || ($2 ~ /(^|\/)node$/ && $3 == exe)' else ps aux | grep -F "$RESCRIPT_EXECUTABLE" | grep -v grep || true fi