Skip to content

Commit 43f93cb

Browse files
Merge pull request #425 from Leonidas-from-XIV/contributing
Add `CONTRIBUTING.md`
2 parents 2cbf243 + 4c6cf0c commit 43f93cb

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

CONTRIBUTING.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
## General
2+
3+
While this project is in the OCaml Labs organization, contributions from others
4+
are very much welcome. We're trying to build a tool that works for many users.
5+
6+
If you're unclear whether a feature would fit the scope of `dune-release` don't
7+
hesitate to open an issue to gauge the interest.
8+
9+
## Setting up your working environment
10+
11+
If you want to contribute to the project you'll first need to install the dependencies.
12+
You can do it via `opam`:
13+
14+
```sh
15+
$ git clone [email protected]:ocamllabs/dune-release.git
16+
$ cd dune-release
17+
$ opam switch create ./ ocaml-base-compiler.4.13.1 --deps-only -t
18+
```
19+
20+
This will create a local switch with a fresh compiler, the dependencies of
21+
`dune-release` and the dependencies for running the tests. The exact OCaml
22+
version is just an example, you should be able to use any reasonably recent
23+
version of OCaml.
24+
25+
From there you can build `dune-release` by simply running:
26+
27+
```sh
28+
$ dune build
29+
```
30+
31+
and run the test suite with:
32+
33+
```sh
34+
$ dune runtest
35+
```
36+
37+
## Tests
38+
39+
In a effort to cover as much of the codebase with tests as possible, new contributions
40+
should come with tests when possible/it makes sense.
41+
42+
dune-release uses [dune's cram
43+
tests](https://dune.readthedocs.io/en/stable/tests.html#cram-tests) extensively
44+
to make sure the workflows work as expected and don't break for our users.
45+
46+
### Unit testing
47+
48+
We should aim at improving the unit tests coverage as much as possible. Our
49+
unit tests can be found in [`tests/lib/`](tests/lib). They are written using
50+
the [alcotest](https://github.com/mirage/alcotest) testing framework. If you
51+
want to add new tests, we encourage you to reuse the style used in the existing
52+
tests ([`test_vcs.ml`](tests/lib/test_vcs.ml) is a good example).
53+
54+
There should be one test module per actual module there. The test runner is
55+
[`tests.ml`](tests/lib/tests.ml). If you add tests for a new or so far untested
56+
module, don't forget to add its test suite to the runner.
57+
58+
For each function we test, we build a list of Alcotest `unit test_case`. It's important to try to be
59+
consistent in that regard as it makes the output of the test runner more readable and helps with
60+
fixing or investigating broken tests.
61+
62+
For each module, we then have one Alcotest `unit test` that contains the concatenation of all the
63+
test cases.
64+
65+
That results in the following test output for a successful run:
66+
67+
```sh
68+
$ dune runtest
69+
tests alias tests/lib/runtest
70+
Testing `dune-release'.
71+
This run has ID `14602E98-BFF4-4D74-A50A-56466A3F2C5B'.
72+
73+
[OK] Github 0 Parse.ssh_uri_from_http https://gi...
74+
...
75+
[OK] Github_repo 15 from_gh_pages: https://user.github...
76+
77+
Full test results in `.../_build/default/tests/lib/_build/_tests/dune-release'.
78+
Test Successful in 0.017s. 95 tests run.
79+
```
80+
81+
### End-to-end testing
82+
83+
End-to-end tests directly call the `dune-release` binary and make sure it
84+
behaves in the expected way. They live in the [`tests/bin/`](tests/bin)
85+
directory.
86+
87+
We have one folder there per aspect we want to test, for instance the tests for
88+
determining the version from a tag live in
89+
[`version-from-tag/`](tests/bin/version-from-tag).
90+
91+
Make sure to only output relevant information in your test by e.g.
92+
postprocessing the output with `grep` and the usual POSIX tools. This makes the
93+
test more relevant, easier to read and less fragile should other things change.
94+
95+
If these tools don't suffice/are not portable there is an OCaml helper binary
96+
[`tests/bin/helpers/make_dune_release_deterministic`](tests/bin/helpers/make_dune_release_deterministic.ml)
97+
that can be extended to make the output more deterministic and can be used to
98+
filter output in the `cram` tests.
99+
100+
If your tests change behavior but the change is correct you can use `dune
101+
promote` to update your test file so the next run of `dune runtest` will expect
102+
the new behavior.

0 commit comments

Comments
 (0)