Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -246,46 +241,41 @@ 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
# 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
./tests/build_tests/integration/suite.sh tmp/integration-bin/rescript.exe >"$integration_log" 2>&1 &
make -C tests/build_tests integration RESCRIPT="$PWD/$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=$?

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 3 additions & 5 deletions build_system/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<platform>/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.
7 changes: 4 additions & 3 deletions build_system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<platform>/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
Expand Down
1 change: 1 addition & 0 deletions changes/make-test-build-all.internal.md
Original file line number Diff line number Diff line change
@@ -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`.
10 changes: 5 additions & 5 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {

let ounitTest = false;
let mochaTest = false;
let buildTest = false;
let projectTest = false;
let formatTest = false;
let runtimeDocstrings = false;

Expand All @@ -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")) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
53 changes: 53 additions & 0 deletions tests/build_tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 ../..)
# 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
Comment thread
cknitt marked this conversation as resolved.
Resolved

# 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)"

# 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. 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:
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
9 changes: 5 additions & 4 deletions tests/build_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<platform>/bin/rescript.exe"
node scripts/test.js -build # projects (with project_tests and error_tests)
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 (part of make test, with project_tests and error_tests)
```

The integration suite is [`integration/suite.sh`](integration/suite.sh). It
Expand Down
22 changes: 19 additions & 3 deletions tests/build_tests/integration/suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,27 @@ fi

source ./utils.sh

# 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 || ($2 ~ /(^|\/)node$/ && $3 == exe)'
else
ps aux | grep -F "$RESCRIPT_EXECUTABLE" | grep -v grep || true
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"
Expand Down
Loading