Skip to content

Commit ed7f803

Browse files
authored
Merge pull request #3955 from ryyppy/update-contributing
Update CONTRIBUTING file
2 parents 33c7e63 + aa96463 commit ed7f803

File tree

1 file changed

+54
-14
lines changed

1 file changed

+54
-14
lines changed

CONTRIBUTING.md

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ git submodule update --init && node scripts/buildocaml.js
2424

2525
`scripts/ninja.js` will generate many `.ninja` build files inside the `jscomp` directory which will be invoked by `./scripts/ninja.js build`.
2626

27+
### Install JS tools
28+
29+
This is required to have all the necessary tools installed, such as the `mocha`
30+
JS testing framework, etc.
31+
32+
```
33+
npm install
34+
```
35+
2736
### Editor support
2837

2938
Use this deprecated [VSCode extension](https://marketplace.visualstudio.com/items?itemName=hackwaly.ocaml).
@@ -123,35 +132,66 @@ cd ocaml && make -j9 world.opt && make install && cd ..
123132

124133
## Contributing to the runtime
125134

126-
BuckleScript runtime implementation is currently a mix of OCaml and JavaScript. (`jscomp/runtime` directory). The JavaScript code is defined in the `.ml` file using the `bs.raw` syntax extension.
135+
BuckleScript runtime implementation is written in pure OCaml with some raw JS
136+
code embedded (`jscomp/runtime` directory).
127137

128-
The goal is to implement the runtime **purely in OCaml** and you can help!
138+
The goal is to implement the runtime **purely in OCaml**. This includes
139+
removing all existing occurrences of embedded raw JS code as well, and you can
140+
help!
129141

130142
Each new PR should include appropriate testing.
131143

132-
Currently all tests are in `jscomp/test` directory and you should either add/modify a test file which covers the part of the compiler you modified.
144+
Currently all tests are located in the `jscomp/test` directory and you should
145+
either add / update test files according to your changes to the compiler.
146+
147+
There are currently two formats for test files:
148+
1. Proper mocha test files with executed javascript test code
149+
2. Plain `.ml` files which are only supposed to be compiled to JS (without any logic validation)
133150

134-
- Add the filename in `jscomp/test/test.mllib`
135-
- Add a test suite. The specification is in `jscomp/test/mt.ml`. For example some simple tests would be like:
151+
Below we will discuss on how to write, build and run these test files.
152+
153+
### 1) Writing a mocha test file
154+
155+
- Create a file `jscomp/test/feature_abc_test.ml`. Make sure to end the file name with `_test.ml`.
156+
- Inside the file, add a mocha test suite. The mocha bindings are defined in
157+
`jscomp/test/mt.ml`. To get you started, here is a simple scaffold for a test
158+
suite with multiple test cases:
136159

137160
```ocaml
138161
let suites : _ Mt.pair_suites =
139162
["hey", (fun _ -> Eq(true, 3 > 2));
140-
"hi", (fun _ -> Neq(2,3));
141-
"hello", (fun _ -> Approx(3.0, 3.0));
142-
"throw", (fun _ -> ThrowAny(fun _ -> raise 3))
143-
]
163+
"hi", (fun _ -> Neq(2,3));
164+
"hello", (fun _ -> Approx(3.0, 3.0));
165+
"throw", (fun _ -> ThrowAny(fun _ -> raise 3))
166+
]
144167
let () = Mt.from_pair_suites __FILE__ suites
145168
```
146169

170+
- Build the test files:
171+
`node scripts/ninja.js clean && node scripts/ninja.js build`
147172
- Run the tests:
148-
`mocha -R list jscomp/test/your_test_file.js`
149-
To build libs, tests and run all tests:
150-
`make libs && make -C jscomp/test all && npm test`
173+
`npx mocha jscomp/test/**/*test.js`
174+
175+
### 2) Writing a plain `.ml` test file
176+
177+
This is usually the file you want to create to test certain compile behavior
178+
without running the JS code formally as a test, i.e. if you add a new type
179+
alias to a specific module and you just want to make sure the compiler handles
180+
the types correctly (see
181+
[`jscomp/test/empty_obj.ml`](jscomp/test/empty_obj.ml) as an example).
182+
183+
- Create your test file `jscomp/test/my_file_test.ml`. Make sure to end the
184+
file name with `_test.ml`.
151185

152-
- See the coverage: `npm run cover`
186+
- Build the `.js` artifact: `node scripts/ninja.js config && node
187+
scripts/ninja.js build`
188+
- Verify the output, check in the `jscomp/test/my_file_test.ml` and `jscomp/test/my_file_test.js` to
189+
version control. The checked in `.js` file is essential for verifying
190+
regressions later on.
191+
- Eventually check in other relevant files changed during the rebuild (depends on
192+
your compiler changes)
153193

154-
## Contributing to Documentation
194+
## Contributing to the Documentation
155195

156196
See https://github.com/BuckleScript/bucklescript.github.io
157197

0 commit comments

Comments
 (0)