Skip to content

Commit b8a6089

Browse files
authored
Include gentype, analysis and syntax tests in coverage (rescript-lang#8467)
* coverage: include gentype and analysis test suites The coverage suite previously only ran `node scripts/test.js -all` (mocha/build/ounit/docstrings), leaving compiler/gentype and the whole analysis/ tree uninstrumented in the report. Run the additional suites under the same BISECT_FILE env so their instrumented binaries accumulate counters: - gentype tests compile via the instrumented bsc in BIN_DIR - analysis tests run the instrumented rescript-editor-analysis - tools tests run the instrumented rescript-tools (links analysis + reanalyze) Use the analysis suite's test-analysis-binary target rather than its full test: the reanalyze tests invoke the binary via `dune exec`, which rebuilds it uninstrumented and strips instrumentation from the shared _build artifacts, so they produce no coverage and would corrupt the build for later suites. * coverage: include syntax tests The syntax suite (scripts/test_syntax.sh) is a merge-gating test on all platforms but contributed no coverage: it drives the res_parser binary, which is instrumented (it carries the bisect_ppx stanza and links the instrumented compiler/syntax lib) and is invoked from _build/install/default/bin, the same pattern as the analysis tests. Run it under BISECT_FILE so compiler/syntax is no longer a blind spot. ROUNDTRIP_TEST=1 matches Linux CI and also exercises the printer paths. * coverage: include reanalyze tests via DUNE_INSTRUMENT_WITH The reanalyze tests invoke rescript-tools through `dune exec`, so they ran an uninstrumented binary and produced no coverage (and a plain `dune exec` would rebuild the shared _build artifacts uninstrumented). Set DUNE_INSTRUMENT_WITH=bisect_ppx (the env-var form of `--instrument-with`) for the analysis suite so that `dune exec` matches the instrumentation config coverage-build already used. dune finds the build up to date, runs the instrumented binary, and reanalyze now contributes coverage for analysis/reanalyze without any test-script changes. Switch the analysis line from test-analysis-binary to the full test target to pull reanalyze in. * coverage: instrument the reanalyze library The DUNE_INSTRUMENT_WITH change alone routed the reanalyze tests to an instrumented rescript-tools, but the reanalyze library itself declared no instrumentation backend, so its own 58 source files recorded zero coverage (only the analysis/tools code it links was counted). Add the (instrumentation (backend bisect_ppx)) stanza — matching every other analysis/* and tools/* library — so analysis/reanalyze/src is measured. Verified locally: reanalyze goes from 0 to ~61% line coverage in the report. The stanza is a no-op for normal builds (it only activates under --instrument-with / DUNE_INSTRUMENT_WITH). * Update changelog
1 parent 6a18567 commit b8a6089

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
- Convert OCaml codebase to snake case format. https://github.com/rescript-lang/rescript/pull/8456
6767
- Analysis refactor: remove global state `Shared_types.state`. https://github.com/rescript-lang/rescript/pull/8465
6868
- Refactor analysis CLI helpers to use source input. https://github.com/rescript-lang/rescript/pull/8466
69+
- Include syntax, gentype, analysis, tools, and reanalyze tests in coverage reports. https://github.com/rescript-lang/rescript/pull/8467
6970

7071
# 13.0.0-alpha.4
7172

‎Makefile‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ checkformat: | $(YARN_INSTALL_STAMP)
237237
# make coverage # run full test suite, generate report
238238
# make clean-coverage # remove coverage artifacts
239239
#
240+
# Suites covered: the `scripts/test.js -all` suites (mocha/build/ounit/
241+
# docstrings), the syntax tests (compiler/syntax, via the instrumented
242+
# res_parser), the gentype tests (compiler/gentype, via the instrumented
243+
# bsc) and the analysis + tools tests, including reanalyze (analysis/, via
244+
# the instrumented rescript-editor-analysis and rescript-tools).
245+
#
240246
# Outputs (under _coverage/):
241247
# html/index.html — human-browsable line-level report
242248
# coverage.json — Coveralls-format JSON, queryable with jq:
@@ -253,6 +259,10 @@ COVERAGE_FILES_DIR := $(COVERAGE_DIR)/files
253259
COVERAGE_HTML_DIR := $(COVERAGE_DIR)/html
254260
COVERAGE_JSON := $(COVERAGE_DIR)/coverage.json
255261
COVERAGE_BISECT_PREFIX := $(abspath $(COVERAGE_FILES_DIR))/bisect
262+
# Env that makes instrumented binaries append their counters to the shared
263+
# coverage prefix. bisect_ppx adds a unique per-process suffix, so many
264+
# concurrent `bsc` / analysis processes accumulate without colliding.
265+
COVERAGE_TEST_ENV := BISECT_FILE=$(COVERAGE_BISECT_PREFIX) BISECT_SILENT=YES
256266

257267
# Re-builds the toolchain with bisect_ppx instrumentation and swaps the
258268
# instrumented binaries into BIN_DIR so any test runner that shells out to
@@ -278,10 +288,33 @@ coverage-lib: coverage-prepare
278288
yarn workspace @rescript/runtime build
279289
rm -f $(COVERAGE_BISECT_PREFIX)-discard*.coverage
280290

291+
# Run the test suites that exercise the instrumented toolchain. Each suite
292+
# shells out to a binary that `coverage-build` instrumented:
293+
# - `node scripts/test.js -all` drives bsc (mocha/build/ounit/docstrings).
294+
# - the syntax tests drive the instrumented `res_parser` from
295+
# _build/install/default/bin, adding coverage for compiler/syntax.
296+
# ROUNDTRIP_TEST=1 matches Linux CI and also exercises the printer paths.
297+
# - gentype tests compile via `rescript build`, i.e. the instrumented bsc in
298+
# BIN_DIR, so they add coverage for compiler/gentype.
299+
# - analysis tests run the instrumented `rescript-editor-analysis` and tools
300+
# tests the instrumented `rescript-tools` (which links analysis + reanalyze),
301+
# both from _build/install/default/bin — adding coverage for analysis/.
302+
# The reanalyze tests (run by the analysis suite's full `test`) invoke the
303+
# binary via `dune exec`, which would otherwise rebuild it *uninstrumented*.
304+
# Setting DUNE_INSTRUMENT_WITH=bisect_ppx (the env-var form of
305+
# `--instrument-with`) makes that `dune exec` match the config coverage-build
306+
# already used, so it runs the instrumented binary — no rebuild, no
307+
# de-instrumentation of the shared _build artifacts. (The reanalyze library
308+
# also carries its own bisect_ppx instrumentation stanza so its source is
309+
# counted, not just the analysis/tools code it links.)
281310
.PHONY: coverage-run
282311
coverage-run: coverage-lib
283-
BISECT_FILE=$(COVERAGE_BISECT_PREFIX) BISECT_SILENT=YES \
284-
node scripts/test.js -all
312+
$(COVERAGE_TEST_ENV) node scripts/test.js -all
313+
$(COVERAGE_TEST_ENV) ROUNDTRIP_TEST=1 ./scripts/test_syntax.sh
314+
$(COVERAGE_TEST_ENV) make -C tests/gentype_tests/typescript-react-example clean test
315+
$(COVERAGE_TEST_ENV) make -C tests/gentype_tests/stdlib-no-shims clean test
316+
$(COVERAGE_TEST_ENV) DUNE_INSTRUMENT_WITH=bisect_ppx make -C tests/analysis_tests clean test
317+
$(COVERAGE_TEST_ENV) make -C tests/tools_tests clean test
285318

286319
.PHONY: coverage-report
287320
coverage-report:

‎analysis/reanalyze/src/dune‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
(library
22
(name reanalyze)
3+
(instrumentation
4+
(backend bisect_ppx))
35
(flags
46
(-w "+6+26+27+32+33+39"))
57
(libraries reactive yojson ml str unix))

0 commit comments

Comments
 (0)