Skip to content

Commit ab708ab

Browse files
authored
Update CONTRIBUTING (about testing and some other small tweaks) (rescript-lang#5374)
* Update CONTRIBUTING * Typo * Add section for automatic tests
1 parent f5a2dfe commit ab708ab

File tree

1 file changed

+73
-43
lines changed

1 file changed

+73
-43
lines changed

CONTRIBUTING.md

+73-43
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
Welcome to the ReScript compiler project!
44

5-
This documet will give you guidance on how to get up and running to work on the ReScript compiler and toolchain.
5+
This document will give you guidance on how to get up and running to work on the ReScript compiler and toolchain.
6+
7+
(If you want to contribute to the documentation website, check out [rescript-association/rescript-lang.org](See https://github.com/reason-association/rescript-lang.org). For contributions to the ReScript syntax, please visit the [rescript-lang/syntax](https://github.com/rescript-lang/syntax) project.)
68

79
We tried to keep the installation process as simple as possible. In case you are having issues or get stuck in the process, please let us know in the issue tracker.
810

911
Happy hacking!
1012

11-
## Prerequisites
13+
## Setup
1214

13-
> We are mainly working on Apple machines, so all our instructions are currently MacOS / Linux centric. Contributions for Windows development welcome!
15+
> Most of our contributors are working on Apple machines, so all our instructions are currently MacOS / Linux centric. Contributions for Windows development welcome!
1416
1517
- [NodeJS v16](https://nodejs.org/)
1618
- C compiler toolchain (usually installed with `xcode` on Mac)
@@ -57,7 +59,7 @@ The ReScript project is built with a vendored version of `ninja`. It requires bu
5759

5860
Whenever you edit a file, run `./scripts/ninja.js build` to rebuild the ReScript compiler. There's also an optional watcher to auto-rebuild on file changes: `node scripts/tasks.js`.
5961

60-
## Building the Project During Development (`dune` workflow)
62+
## Build the Project during Development (`dune` workflow)
6163

6264
When working on a project you may want to use `dune` to compile all the files you've been working on. This is especially important for full IDE support, including auto-completion and showing compilation errors.
6365

@@ -71,7 +73,9 @@ dune build -w
7173

7274
> Please note that `dune` will not build the final `rescript` binaries. Use the aforementioned `ninja` workflow if you want to build, test and distribute the final product.
7375
74-
### Troubleshoot Broken Build
76+
### Troubleshoot a Broken Build
77+
78+
Usually whenever there's some issues with missing files, incompatible interfaces or stale artifacts, the easiest fix is to clean and rebuild the project:
7579

7680
```sh
7781
./scripts/ninja.js clean # remove files not in version control
@@ -84,73 +88,72 @@ If this doesn't work (rare), then:
8488
- `git clean -xdf .` to wipe all artifacts
8589
- Then do a clean build as instructed above
8690

87-
## Test
91+
## Running tests for independent ReScript files
92+
93+
The simplest way for running tests is to run your locally built compiler on separate ReScript files:
8894

8995
```sh
90-
./darwin/bsc.exe myTestFile.ml
96+
# Make sure to rebuild the compiler before running any tests (./scripts/ninja.js config / build etc)
97+
./darwinarm64/bsc.exe myTestFile.res
9198
```
9299

93-
(`./linux/bsc` for linux developers).
94-
95-
> Note: production, only `path/to/bsc myTestFile.ml` is needed. During development, you need to pass the `-I jscomp/runtime/` flag for various reasons (e.g. to avoid cyclic dependencies).
100+
**Different architectures:**
96101

97-
Tips:
98-
- To get a nice stack trace when you debug type errors from running `bsc`/`bsb`, uncomment the conditional compilation check in [`rescript_compiler_main.ml`](https://github.com/rescript-lang/rescript-compiler/blob/496c70d1d4e709c26dba23629e430dc944bd59f9/jscomp/main/rescript_compiler_main.ml#L501).
102+
- `darwinarm64/bsc.exe`: M1 Macs
103+
- `darwin/bsc.exe`: Intel Macs
104+
- `linux/bsc.exe`: Linux computers
99105

100-
### Integration Test
106+
### Testing the whole ReScript Package
101107

102-
If you'd like to use your modified ReScript like an end-user, try:
108+
If you'd like to bundle up and use your modified ReScript like an end-user, try:
103109

104110
```sh
105-
npm uninstall -g bs-platform # a cache-busting uninstall is needed, but only for npm >=7
111+
npm uninstall -g rescript # a cache-busting uninstall is needed, but only for npm >=7
112+
113+
# This will globally install your local build via npm
106114
BS_TRAVIS_CI=1 npm install -g .
107115
```
108116

109-
Then go somewhere and create a dummy project:
117+
Then you may initialize and build your ReScript project as usual:
110118

111119
```sh
112-
bsb -init foo -theme basic
113-
cd foo
120+
rescript init my-project
121+
cd my-project
114122
npm run build
115123
```
116124

117-
## Editor Support for Developing This Repo
125+
### Running Automatic Tests
118126

119-
This is hard to set up and therefore not entirely encouraged. Use this deprecated [VSCode extension](https://marketplace.visualstudio.com/items?itemName=hackwaly.ocaml).
120-
The extension requires using an opam switch for ocaml 4.02.3, with `merlin` and `ocp-indent` are installed.
127+
We provide different test suites for different levels of the compiler and build system infrastructure. Always make sure to locally build your compiler before running any tests.
121128

122-
## Contribute to the Documentation
129+
**Run Mocha tests for our runtime code:**
123130

124-
See https://github.com/reason-association/rescript-lang.org
131+
This will run our `mocha` unit test suite defined in `jscomp/test`.
125132

126-
## Contribute to the API Reference
133+
```
134+
npx node scripts/ciTest.js -mocha
135+
```
127136

128-
The API reference is generated from doc comments in the source code. [Here](https://github.com/rescript-lang/rescript-compiler/blob/99650/jscomp/others/js_re.mli#L146-L161)'s a good example.
137+
**Run build system test (integration tests):**
129138

130-
Some tips:
139+
This will run the whole build system test suite defined in `jscomp/build_tests`.
131140

132-
- The first sentence or line should be a very short summary. This is used in indexes and by tools like merlin.
133-
- Ideally, every function should have **at least one** `@example`.
134-
- Cross-reference another definition with `{! identifier}`. But use them sparingly, they’re a bit verbose (currently, at least).
135-
- Wrap non-cross-referenced identifiers and other code in `[ ... ]`.
136-
- Escape `{`, `}`, `[`, `]` and `@` using `\`.
137-
- It’s possible to use `{%html ...}` to generate custom html, but use this very, very sparingly.
138-
- A number of "documentation tags" are provided that would be nice to use, but unfortunately they’re often not supported for \`external\`s. Which is of course most of the API.
139-
- `@param` usually doesn’t work. Use `{b <param>} ...` instead
140-
- `@returns` usually doesn’t work. Use `{b returns} ...` instead.
141-
- Always use `@deprecated` when applicable.
142-
- Always use `@raise` when applicable.
143-
- Always provide a `@see` tag pointing to MDN for more information when available.
141+
```
142+
# Make sure to globally install rescript via npm first
143+
npm install -g .
144144
145-
See [Ocamldoc documentation](http://caml.inria.fr/pub/docs/manual-ocaml/ocamldoc.html#sec333) for more details.
145+
npx node scripts/ciTest.js -bsb
146+
```
146147

147-
To generate the html:
148+
**Run ounit tests:**
149+
150+
This will run unit tests for compiler related modules. The tests can be found in `jscomp/ounit_tests`.
148151

149-
```sh
150-
../scripts/ninja docs
152+
```
153+
npx node scripts/ciTest.js -ounit
151154
```
152155

153-
## Contributing to the Runtime
156+
## Contributing to the ReScript Runtime
154157

155158
Our runtime implementation is written in pure OCaml with some raw JS code embedded (`jscomp/runtime` directory).
156159

@@ -285,6 +288,33 @@ In this repo, these files usually sit right next to each compiled `.ml` / `.re`
285288

286289
For any other dependency needed in the playground, such as `ReasonReact`, you will be required to serialize your `.cmi` / `.cmt` files accordingly from binary to hex encoded strings so that BS Playground's `ocaml.load` function can load the data. Right now we don't provide any instructions inside here yet, but [here's how the official ReasonML playground did it](https://github.com/reasonml/reasonml.github.io/blob/source/website/setupSomeArtifacts.js#L65).
287290

291+
## Contribute to the API Reference
292+
293+
The API reference is generated from doc comments in the source code. [Here](https://github.com/rescript-lang/rescript-compiler/blob/99650/jscomp/others/js_re.mli#L146-L161)'s a good example.
294+
295+
Some tips:
296+
297+
- The first sentence or line should be a very short summary. This is used in indexes and by tools like merlin.
298+
- Ideally, every function should have **at least one** `@example`.
299+
- Cross-reference another definition with `{! identifier}`. But use them sparingly, they’re a bit verbose (currently, at least).
300+
- Wrap non-cross-referenced identifiers and other code in `[ ... ]`.
301+
- Escape `{`, `}`, `[`, `]` and `@` using `\`.
302+
- It’s possible to use `{%html ...}` to generate custom html, but use this very, very sparingly.
303+
- A number of "documentation tags" are provided that would be nice to use, but unfortunately they’re often not supported for \`external\`s. Which is of course most of the API.
304+
- `@param` usually doesn’t work. Use `{b <param>} ...` instead
305+
- `@returns` usually doesn’t work. Use `{b returns} ...` instead.
306+
- Always use `@deprecated` when applicable.
307+
- Always use `@raise` when applicable.
308+
- Always provide a `@see` tag pointing to MDN for more information when available.
309+
310+
See [Ocamldoc documentation](http://caml.inria.fr/pub/docs/manual-ocaml/ocamldoc.html#sec333) for more details.
311+
312+
To generate the html:
313+
314+
```sh
315+
../scripts/ninja docs
316+
```
317+
288318
## Code structure
289319

290320
The highlevel architecture is illustrated as below:

0 commit comments

Comments
 (0)