Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ jobs:
# to 0.2%. The runtime and Belt are built there too, since the
# replayed builds would otherwise write interfaces that don't
# match those of the files they don't replay yet. Both build the
# base's tests/tests, which the base's compiler builds already.
# base's tests/compiler_tests, which the base's compiler builds already.
measure() {
sudo mkdir -p /bench
sudo mount --bind "$1" /bench
Expand Down Expand Up @@ -782,10 +782,10 @@ jobs:
echo "$manager=$dir" >> "$GITHUB_OUTPUT"
cp -r tests/package_tests/installation_test/* "$dir"
# The compiled stdlib tests run against the installed runtime. Their
# Test.mjs imports @babel/code-frame, which tests/tests depends on.
cp -r tests/tests/src/stdlib "$dir/stdlib"
# Test.mjs imports @babel/code-frame, which tests/compiler_tests depends on.
cp -r tests/compiler_tests/src/stdlib "$dir/stdlib"
done
echo "code-frame=$(node -p 'require("./tests/tests/package.json").dependencies["@babel/code-frame"]')" >> "$GITHUB_OUTPUT"
echo "code-frame=$(node -p 'require("./tests/compiler_tests/package.json").dependencies["@babel/code-frame"]')" >> "$GITHUB_OUTPUT"

- name: "npm: Install ReScript package"
run: |
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ system).
#### Test Types to Include

1. **Syntax tests** (`tests/syntax_tests/`) - Parser validation
2. **Integration tests** (`tests/tests/`) - End-to-end behavior
2. **Integration tests** (`tests/compiler_tests/`) - End-to-end behavior
3. **Unit tests** (`tests/ounit_tests/`) - Compiler functions
4. **Build tests** (`tests/build_tests/`) - Build system behavior
5. **Project tests** (`tests/project_tests/`) - Compiler behavior that needs a whole project, such as JSX output or source maps
Expand Down
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ make test

**Run Mocha tests only (for our runtime code):**

This will run our `mocha` unit test suite defined in `tests/tests`.
This will run our `mocha` unit test suite defined in `tests/compiler_tests`.

```
node scripts/test.js -mocha
Expand Down Expand Up @@ -320,7 +320,7 @@ The goal is to implement the runtime **purely in ReScript**. This includes remov

Each new PR should include appropriate testing.

Currently all tests are located in the `tests/tests` directory and you should either add / update test files according to your changes to the compiler.
Currently all tests are located in the `tests/compiler_tests` directory and you should either add / update test files according to your changes to the compiler.

There are currently two formats for test files:

Expand All @@ -331,8 +331,8 @@ Below we will discuss on how to write, build and run these test files.

### 1) Write a Mocha Test File

- Create a file `tests/tests/src/feature_abc_test.res`. Make sure to end the file name with `_test.res`.
- Inside the file, add a mocha test suite. The mocha bindings are defined in `tests/tests/src/mocha.res`, the assertion helpers in `tests/tests/src/test_utils.res`. To get you started, here is a simple scaffold for a test suite with multiple test cases:
- Create a file `tests/compiler_tests/src/feature_abc_test.res`. Make sure to end the file name with `_test.res`.
- Inside the file, add a mocha test suite. The mocha bindings are defined in `tests/compiler_tests/src/mocha.res`, the assertion helpers in `tests/compiler_tests/src/test_utils.res`. To get you started, here is a simple scaffold for a test suite with multiple test cases:

```rescript
open Mocha
Expand Down Expand Up @@ -360,9 +360,9 @@ Below we will discuss on how to write, build and run these test files.

This is usually the file you want to create to test certain compile behavior without running the JS code formally as a test, i.e., when you just want to check that the ReScript code compiles and produces the expected JS code.

- Create your test file `tests/tests/src/my_file_test.res`. Make sure to end the file name with `_test.res`.
- Create your test file `tests/compiler_tests/src/my_file_test.res`. Make sure to end the file name with `_test.res`.
- Build the `.mjs` artifact: `node scripts/test.js -mocha`.
- Verify the output, check in the `tests/tests/src/my_file_test.res` and `tests/tests/src/my_file_test.mjs` to version control. The checked in `.mjs` file is essential for verifying regressions later on.
- Verify the output, check in the `tests/compiler_tests/src/my_file_test.res` and `tests/compiler_tests/src/my_file_test.mjs` to version control. The checked in `.mjs` file is essential for verifying regressions later on.
- Eventually check in other relevant files changed during the rebuild (depends on your compiler changes).

## Contribute to the ReScript Playground Bundle
Expand Down
4 changes: 2 additions & 2 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ ReScript imported one file from [jsoo](https://github.com/ocsigen/js_of_ocaml)

This file was imported but changed significantly in iterations later.

- [`tests/tests`](tests/tests)
- [`tests/compiler_tests`](tests/compiler_tests)

`tests/tests` is based on [`ocaml/testsuite`](ocaml/testsuite).
`tests/compiler_tests` is based on [`ocaml/testsuite`](ocaml/testsuite).

ReScript compiler unit test builds on [OUnit](http://ounit.forge.ocamlcore.org/)

Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"!**/tests/docstring_tests",
"!**/tests/gentype_tests",
"**/tests/gentype_tests/typescript-react-example/**",
"!**/tests/tests/**/src",
"!**/tests/compiler_tests/**/src",
"!**/tests/tools_tests/**/src",
"!**/tests/build_tests/isolated",
"!**/tests/build_tests/integration",
Expand Down
1 change: 1 addition & 0 deletions changes/compiler-tests-dir.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Rename `tests/tests`, the compiler's output and mocha tests, to `tests/compiler_tests`.
2 changes: 1 addition & 1 deletion compiler/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Run the full compiler tests for backend changes:
make test
```

End-to-end fixtures under `tests/tests/` check generated `.mjs` output. Add
End-to-end fixtures under `tests/compiler_tests/` check generated `.mjs` output. Add
focused OUnit coverage for an isolated analysis or transformation. Use the
compiler flags below to compare intermediate forms for a small source file:

Expand Down
2 changes: 1 addition & 1 deletion compiler/typing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ make checkformat # check formatting

Useful focused suites include `tests/ounit_tests/` for internal operations and
`tests/error_tests/single/` for type errors. Add end-to-end cases under
`tests/tests/` when a type-system change also affects accepted programs or
`tests/compiler_tests/` when a type-system change also affects accepted programs or
generated JavaScript.

To inspect the compiler pipeline for a small source file:
Expand Down
22 changes: 11 additions & 11 deletions compiler/typing/UntaggedVariants.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apart (rule 6). The user manual describes the feature in
This document states the rules the compiler implements. Each rule names the
code that implements it and the tests that pin it. Tests named
`spec_test` are in
[`tests/tests/src/untagged_variants_spec_test.res`](../../tests/tests/src/untagged_variants_spec_test.res);
[`tests/compiler_tests/src/untagged_variants_spec_test.res`](../../tests/compiler_tests/src/untagged_variants_spec_test.res);
the committed `.mjs` beside it shows the checks emitted for each declaration.
Fixtures are in `tests/error_tests/single/fixtures/` unless another
directory is named.
Expand Down Expand Up @@ -85,7 +85,7 @@ is the number `1`.
("A variant case annotation @as(...) must be a string, integer, float,
bigint, boolean, null, or undefined."), `VariantAsIntegerOutOfRange.res`,
`UntaggedDuplicatedBsAs.res`; `spec_test` rule 2;
`tests/tests/src/unboxed_variant_fold_test.res` (`wide`).
`tests/compiler_tests/src/unboxed_variant_fold_test.res` (`wide`).

### 4. Payload kinds

Expand Down Expand Up @@ -125,7 +125,7 @@ builtin payload type. `@notUndefined` on an abstract type leaves it unknown.
`UntaggedNonUnary2.res` ("Constructor A has more than one argument."),
`UntaggedUnknown.res` (`list<float>` is unknown),
`untagged_unannotated_stdlib_name.res` (a type named like a stdlib class
is unknown); `tests/tests/src/untagged_runtime_annotations_test.res`,
is unknown); `tests/compiler_tests/src/untagged_runtime_annotations_test.res`,
`untagged_builtin_alias_test.res`.
- Shaped by #6121, #6208, #6219, #6279, #6368, #6394, #6550, #6670.

Expand Down Expand Up @@ -298,7 +298,7 @@ written (Known bugs).
`variant_runtime.ml:Instance`;
`lam_compile_external_call.ml:class_constructor`.
- Tests: `spec_test` rules 4 and 5;
`tests/tests/src/untagged_runtime_annotations_test.res`,
`tests/compiler_tests/src/untagged_runtime_annotations_test.res`,
`untagged_runtime_annotations_shadow_test.res`,
`untagged_file_blob_test.res`, `not_undefined_interface_test.res`,
`not_undefined_abbreviation_test.res`; the fixtures above,
Expand Down Expand Up @@ -350,7 +350,7 @@ belongs to.

- Implementation: `variant_layout.ml:check_invariant`,
`variant_runtime.ml:literal_value_key`.
- Tests: the fixtures above; `tests/tests/src/unboxed_variant_fold_test.res`
- Tests: the fixtures above; `tests/compiler_tests/src/unboxed_variant_fold_test.res`
(a number and a bigint literal with the same digits); `TaggedDuplicateLiteral.res`,
`multiple_tag_1.res`, `multiple_tag_2.res` (tagged variants).
- Shaped by #6128, #6136, #7441, #8777, #8953.
Expand Down Expand Up @@ -403,7 +403,7 @@ does not cover it.

- Implementation: `untagged_dispatch.ml:plan` (the literal part);
`parmatch.ml` (shadowed payload patterns, exhaustiveness).
- Tests: `spec_test` rule 7; `tests/tests/src/untagged_variants_heuristic.res`
- Tests: `spec_test` rule 7; `tests/compiler_tests/src/untagged_variants_heuristic.res`
(literals that skip the `switch`); `unboxed_variant_fold_test.res`
(`answerName2`, `bigintOrPayloadName`); fixtures
`warning_11_untagged_literal_shadows_payload.res`,
Expand Down Expand Up @@ -467,8 +467,8 @@ context, where they are labeled; an arm of an `if` is not
`ounit_untagged_dispatch_tests.ml` pin plans as data.
- Tests: `spec_test` rules 4, 5 and 8 (`instanceName` shows the chain in
declaration order, `objectFirst` the unchecked last arm);
`tests/tests/src/UntaggedVariants.res` (`AllInstanceofTypes`,
`MergeCases`); `tests/tests/src/untagged_runtime_annotations_test.res`
`tests/compiler_tests/src/UntaggedVariants.res` (`AllInstanceofTypes`,
`MergeCases`); `tests/compiler_tests/src/untagged_runtime_annotations_test.res`
(subclasses, the function case, a missing class);
`untagged_default_arm_test.res` (`Symbol.hasInstance`, incomplete
matches); `untagged_loop_control_test.res` (`break`, `continue`).
Expand All @@ -494,7 +494,7 @@ as a record case does.
- Implementation: `untagged_dispatch.ml:plan` (`null_guard`),
`payload_part`.
- Tests: `spec_test` rule 9; `UntaggedVariants.res` (`ObjectAndNull`, `Json`);
`tests/tests/src/untagged_default_arm_test.res`.
`tests/compiler_tests/src/untagged_default_arm_test.res`.
- Shaped by #6219, #7303, #8253, #8255, #8279, #8995.

### 10. Values outside every case
Expand Down Expand Up @@ -532,7 +532,7 @@ matched at run time.

- Implementation: `lambda.ml:switch` (`untagged_value`, `untagged_plan`),
`untagged_dispatch.ml:select`.
- Tests: `tests/tests/src/unboxed_variant_fold_test.res`; `spec_test` rule 10
- Tests: `tests/compiler_tests/src/unboxed_variant_fold_test.res`; `spec_test` rule 10
(a folded value outside every case); `ounit_untagged_dispatch_tests.ml`
compares the plans of random variants and matches with rules 7 to 9.
- Shaped by #8631.
Expand Down Expand Up @@ -578,7 +578,7 @@ hold `undefined`.

- Implementation: `typeopt.ml:type_cannot_contain_undefined`.
- Tests: `spec_test` rule 12; `UntaggedVariants.res`
(`OptionUnboxingHeuristic`); `tests/tests/src/option_wrapping_test.res`;
(`OptionUnboxingHeuristic`); `tests/compiler_tests/src/option_wrapping_test.res`;
`tests/project_tests/option_transitive_dependency`.
- Shaped by #6222, #6233, #8719, #8954.

Expand Down
4 changes: 2 additions & 2 deletions lib_dev/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export const compilerRootDir = path.resolve(projectDir, "compiler");
export const testDir = path.resolve(projectDir, "tests");

/**
* path: `<projectDir>/tests/tests/`
* path: `<projectDir>/tests/compiler_tests/`
*/
export const compilerTestDir = path.resolve(testDir, "tests");
export const compilerTestDir = path.resolve(testDir, "compiler_tests");

/**
* path: `<projectDir>/tests/build_tests/projects/`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"tests/docstring_tests",
"tests/belt_tests",
"tests/gentype_tests/**",
"tests/tests",
"tests/compiler_tests",
"tests/tools_tests",
"tests/commonjs_tests",
"scripts/res"
Expand Down
4 changes: 2 additions & 2 deletions scripts/commitRecords.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ test("a card draws the message alone, whatever the diff", async () => {
.replaceAll(sha, "SHA");
};
const touched = await card({
"tests/tests/src/a_test.res": "let y = 1\n",
"tests/tests/src/a_test.mjs": "y\n",
"tests/compiler_tests/src/a_test.res": "let y = 1\n",
"tests/compiler_tests/src/a_test.mjs": "y\n",
"tests/error_tests/single/expected/x.res.expected": "e\n",
"changes/x.fix.md": "- Fix a thing.\n",
"compiler/typing/config.ml": 'let cmi_magic_number = "BS00MI002"\n',
Expand Down
23 changes: 17 additions & 6 deletions scripts/compilerBenchmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
// inputs, the data files and the largest runtime and Belt files run under
// cachegrind. The generated inputs and the data files come from the checkout
// of this script, so both measurements use the same ones. With `--project`,
// it also builds tests/tests of the given checkout with the build system,
// it also builds tests/compiler_tests of the given checkout with the build system,
// clean, with nothing to do and after two edits (see measureProjectBuild),
// and a few generated projects, clean and after an edit, for costs that grow
// with the number of modules of a build (see generatedProjects), counting
Expand Down Expand Up @@ -582,8 +582,15 @@ function copySources(from, to) {
});
}

/** The project the build benchmarks build, relative to a checkout. */
const benchmarkProject = path.join("tests", "tests");
/**
* The project the build benchmarks build, relative to a checkout. A base from
* before the rename to tests/compiler_tests still has it at tests/tests; the
* next pull request in the stack drops that fallback.
*/
const benchmarkProjects = [
path.join("tests", "compiler_tests"),
path.join("tests", "tests"),
];

/**
* The module of the project that about 200 others use, and that has no
Expand All @@ -592,7 +599,7 @@ const benchmarkProject = path.join("tests", "tests");
const sharedModule = path.join("src", "test_utils.res");

/**
* Builds tests/tests of `projectCheckout` with the build system of
* Builds tests/compiler_tests of `projectCheckout` with the build system of
* `checkout`, on one worker domain so that the counts don't depend on how
* the work is shared: a clean build, a build with nothing to do, and the
* builds after an edit of a module that nothing uses and of one that many
Expand All @@ -615,7 +622,11 @@ const sharedModule = path.join("src", "test_utils.res");
*/
function measureProjectBuild(checkout, projectCheckout, results) {
const rescript = path.join(checkout, relativeBinDir, "rescript.exe");
const projectDir = path.join(projectCheckout, benchmarkProject);
const projectDir =
benchmarkProjects
.map(project => path.join(projectCheckout, project))
.find(dir => fs.existsSync(dir)) ??
path.join(projectCheckout, benchmarkProjects[0]);
const workDir = path.join(os.tmpdir(), "compiler-bench-project");
fs.rmSync(workDir, { recursive: true, force: true });
try {
Expand Down Expand Up @@ -765,7 +776,7 @@ function measureGeneratedProjects(checkout, results) {
/**
* @param {string} checkout
* @param {{ instructions: boolean, project?: string, playground?: boolean }} options
* `project` is the checkout whose tests/tests the build benchmarks build;
* `project` is the checkout whose tests/compiler_tests the build benchmarks build;
* without it, there are none. `playground` adds the size of the
* playground's compiler, which must be built.
* @returns {Results}
Expand Down
10 changes: 5 additions & 5 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,34 +100,34 @@ if (mochaTest) {
[
"-t",
"10000",
"tests/tests/src/**/*_test.mjs",
"tests/compiler_tests/src/**/*_test.mjs",
"tests/belt_tests/src/**/*_test.mjs",
"tests/cli_tests/*_test.mjs",
// jsx_preserve_test.mjs contains JSX, which Node cannot load; the
// file exists to pin the preserved-JSX output.
"--ignore",
"tests/tests/src/jsx_preserve_test.mjs",
"tests/compiler_tests/src/jsx_preserve_test.mjs",
],
{
cwd: projectDir,
stdio: "inherit",
},
);

await node("tests/tests/src/stdlib/Stdlib_TestSuite.mjs", [], {
await node("tests/compiler_tests/src/stdlib/Stdlib_TestSuite.mjs", [], {
cwd: projectDir,
stdio: "inherit",
});

await node("tests/tests/src/stdlib/Stdlib_TempTests.mjs", [], {
await node("tests/compiler_tests/src/stdlib/Stdlib_TempTests.mjs", [], {
cwd: projectDir,
stdio: "inherit",
});

// Not part of Stdlib_TestSuite, which the installation tests also run on
// Node.js 22.
if ("Temporal" in globalThis) {
await node("tests/tests/src/stdlib/Stdlib_TemporalTests.mjs", [], {
await node("tests/compiler_tests/src/stdlib/Stdlib_TemporalTests.mjs", [], {
cwd: projectDir,
stdio: "inherit",
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading