Skip to content

Commit 5732972

Browse files
lubegasimonjonludlam
authored andcommitted
update CONTRIBUTING.md
Signed-off-by: lubegasimon <lubegasimon73@gmail.com>
1 parent a0644a9 commit 5732972

File tree

1 file changed

+24
-103
lines changed

1 file changed

+24
-103
lines changed

CONTRIBUTING.md

Lines changed: 24 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ find the information in this file helpful.
1515
- [Quick start: HTML and CSS](#Quick_start)
1616
- [Testing](#Testing)
1717
- [Debug prints](#Debug_prints)
18-
- [Expect tests](#Expect_tests)
1918
- [Coverage analysis](#Coverage_analysis)
2019
- [Project structure](#Project_structure)
2120
- [Roadmap](#Roadmap)
@@ -136,72 +135,6 @@ The [testing framework][alcotest] will display STDERR if a test fails.
136135
137136
<br/>
138137
139-
<a id="Expect_tests"></a>
140-
### Expect tests
141-
142-
Most of odoc's tests are *expect tests*, which means that they convert output
143-
of some code that is being tested to strings, and then check that those strings
144-
are correct:
145-
146-
1. The tests run some code, for example the odoc parser on the string `{e foo}`.
147-
2. They take the output, in this case an AST representing "emphasized `foo`,"
148-
and convert that output to a string. In this case, it will be an S-expression
149-
roughly like `(emphasis (foo))`.
150-
3. There is an *expected* copy of this S-expression in a file somewhere in the
151-
repo. If the S-expression from the code doesn't match the expected one, the
152-
test fails.
153-
154-
The reason for using expect tests is that when a test fails, there are two
155-
possibilities:
156-
157-
1. The code being tested has become wrong, in which case the *first* failure
158-
should trigger fixing the code.
159-
2. The code being tested has been changed in some way, but is correct (perhaps
160-
more correct than it used to be), and it is the test case that is wrong. It
161-
is possible that *dozens* or even *hundreds* of tests are now wrong. It is
162-
not practical to fix them fully by hand.
163-
164-
When an expect test fails, the string that the code emitted is saved, so that
165-
the human developer can choose to *replace* the now-incorrect expected string.
166-
In odoc, a test failure looks like this:
167-
168-
```diff
169-
-- bold.000 [basic.] Failed --
170-
in _build/_tests/bold.000.output:
171-
172-
{e foo}
173-
174-
--- expect/bold/basic.txt 2018-04-15 14:42:32.356895400 -0500
175-
+++ _actual/bold/basic.txt 2018-04-15 17:36:26.812747400 -0500
176-
@@ -2,5 +2,5 @@
177-
(ok
178-
(((f.ml (1 0) (1 7))
179-
(paragraph
180-
- (((f.ml (1 0) (1 7)) (bold (((f.ml (1 3) (1 6)) (word foo)))))))))))
181-
+ (((f.ml (1 0) (1 7)) (emphasis (((f.ml (1 3) (1 6)) (word foo)))))))))))
182-
(warnings ()))
183-
184-
To replace expected output with actual, run
185-
186-
bash _build/default/test/parser/_actual/replace.sh
187-
```
188-
189-
The intended response to this is:
190-
191-
1. Check the diff. If the `-` line is correct, the code is broken. If the `+`
192-
line is correct, the test is broken.
193-
2. If the test is broken, copy/paste the command that the output suggests,
194-
and re-run the tests:
195-
196-
```
197-
bash _build/default/test/parser/_actual/replace.sh; make test
198-
```
199-
200-
This command is the same within one test category (e.g. HTML tests, parser
201-
tests), so if you have lots of tests to fix, you paste it once, then use
202-
UP, ENTER to repeat it over and over again, quickly checking each failure.
203-
204-
<br/>
205138
206139
<a id="Coverage_analysis"></a>
207140
### Coverage analysis
@@ -237,15 +170,10 @@ writing new tests, and want to know what they are actually touching. To use it,
237170
odoc is divided into several sub-libraries, each of which is a directory
238171
under `src/`. Most of these have a *main file*, whose name is the directory
239172
name prefixed with "`odoc__`". That main file is the interface for the entire
240-
sub-library directory. For example, [`src/parser`][parser-dir] has
241-
[`src/parser/odoc__parser.mli`][parser-api], and everything in `src/parser` is
173+
sub-library directory. For example, [`src/loader`][loader-dir] has
174+
[`src/loader/odoc__loader.mli`][loader-api], and everything in `src/loader` is
242175
hidden behind that interface.
243176
244-
We use an alias module, in [`src/alias/odoc__alias.ml`][alias] to shorten these
245-
names in odoc's own code. For example, as you can see in the alias module, we
246-
`Odoc__parser` is shortened to `Parser_`. The underscore is there to avoid
247-
needlessly shadowing OCaml's module `Parser`, which is part of `compiler-libs`.
248-
249177
The `dune` files in each directory can be used to figure out how the
250178
directories depend on each other. Mostly, however, everything depends on
251179
`model`, and `odoc` depends on everything.
@@ -258,7 +186,7 @@ OCaml.
258186
- [`src/model`][model-dir] &mdash; datatypes representing the OCaml
259187
language ([`src/model/lang.ml`][lang]), error-handling
260188
([`src/model/error.ml`][error]), cross-references
261-
([`src/model/paths-types.ml`][paths]), etc. This directory actually has no main
189+
([`src/model/paths_types.ml`][paths]), etc. This directory actually has no main
262190
file. It is a collection of the datatypes that the rest of the odoc
263191
sub-libraries use to communicate with each other, so everything else depends on
264192
`model`.
@@ -267,18 +195,17 @@ sub-libraries use to communicate with each other, so everything else depends on
267195
to `model`. You can see the three functions' signatures in the main file,
268196
[`src/loader/odoc__loader.mli`][loader-api].
269197
270-
- [`src/parser`][parser-dir] &mdash; a single function from strings to comment
271-
ASTs. You can see its signature in the main file,
272-
[`src/parser/odoc__parser.mli`][parser-api].
273-
274198
- [`src/xref`][xref-dir] &mdash; functions for resolving cross-references. These
275199
consume things from `model`, and return transformed instances. The signature, in
276200
[`src/xref/odoc__xref.mli`][xref-api] is not very pretty, but the usage of
277201
`xref` is pretty isolated in the rest of odoc, and can be found by grepping for
278202
`Xref`.
279203
280-
- [`src/html`][html-dir] &mdash; the HTML generator. The main file is
281-
[`src/html/odoc__html.mli`][html-api].
204+
- [`src/html`][html-dir] &mdash; the HTML generator.
205+
206+
- [`src/latex`][latex-dir] &mdash; the Latex generator.
207+
208+
- [`src/man`][man-dir] &mdash; the Manpages generator.
282209
283210
- [`src/odoc`][odoc-dir] &mdash; the overall `odoc` command-line tool that ties
284211
the other parts together. This doesn't have the same kind of main file, because
@@ -294,46 +221,40 @@ third-party software.
294221
[lang]: https://github.com/ocaml/odoc/blob/master/src/model/lang.ml
295222
[error]: https://github.com/ocaml/odoc/blob/master/src/model/error.ml
296223
[paths]: https://github.com/ocaml/odoc/blob/master/src/model/paths_types.ml
297-
[parser-dir]: https://github.com/ocaml/odoc/tree/master/src/parser
298-
[parser-api]: https://github.com/ocaml/odoc/blob/master/src/parser/odoc__parser.mli
299224
[loader-dir]: https://github.com/ocaml/odoc/tree/master/src/loader
300225
[loader-api]: https://github.com/ocaml/odoc/blob/master/src/loader/odoc__loader.mli
301226
[xref-dir]: https://github.com/ocaml/odoc/tree/master/src/xref
302227
[xref-api]: https://github.com/ocaml/odoc/blob/master/src/xref/odoc__xref.mli
303228
[html-dir]: https://github.com/ocaml/odoc/tree/master/src/html
304-
[html-api]: https://github.com/ocaml/odoc/blob/master/src/html/odoc__html.ml
229+
[latex-dir]: https://github.com/ocaml/odoc/tree/master/src/html
230+
[man-dir]: https://github.com/ocaml/odoc/tree/master/src/html
305231
[odoc-dir]: https://github.com/ocaml/odoc/tree/master/src/odoc
306232
[main]: https://github.com/ocaml/odoc/blob/master/src/odoc/bin/main.ml
307233
[util-dir]: https://github.com/ocaml/odoc/tree/master/src/util
308234
[vendor-dir]: https://github.com/ocaml/odoc/tree/master/src/vendor
309235
310236
The tests parallel the structure of `src/`:
311237
312-
- [`test/parser`][test-parser] is expect tests for the parser. Each [one]
313-
[parser-test] calls the parser on a string, converts the AST to a string, and
314-
compares it with an [expected string][parser-expect].
238+
- [`test/generators`][test-generators] This contains backend tests. See the [README.md](https://github.com/ocaml/odoc/blob/master/test/generators/README.md).
315239
316-
- [`test/html`][test-html] is end-to-end expect tests for the HTML generator.
317-
Each [one][html-test] is an OCaml source file. The tester runs the `odoc` tool
318-
on it, and compares the resulting HTML to some [expected HTML][html-expect].
240+
- [`test/inactive`][test-inactive] is some old tests that have suffered some bit
241+
rot, and we haven't gotten around to restoring yet.
319242
320-
- [`test/print`][test-print] is converters from odoc datatypes to strings, so
321-
they can be used in expect tests.
243+
- [`test/integration`] is meant to test `odoc`'s CLI and integration with dune, and it use [cram-testing](https://dune.readthedocs.io/en/stable/tests.html?highlight=cram%20testing#cram-tests) style.
322244
323-
- [`test/dune`][test-dune] is a tiny project for checking that Dune drives odoc
324-
correctly. It is mainly used in the odoc CI.
245+
- [`test/model`] tests the odoc model using expect tests and cram-testing style.
325246
326-
- [`test/inactive`][test-inactive] is some old tests that have suffered some bit
327-
rot, and we haven't gotten around to restoring yet.
247+
- [`test/odoc_print`] is an helper program that is used by cram tests to print the content of intermediary files, that is `.odoc`, `.odocl` et cetera.
248+
249+
- [`test/pages`] is testing the `odoc's` CLI too
250+
251+
- [`test/print`][test-print] converts from `odoc`'s datatypes to strings, so
252+
they can be used in expect tests.
253+
254+
- [`test/xref2`] is testing specific paths of compile and link code but always from "the outside" (calling Odoc's CLI or the "public" API, they are not unit tests). Some of the tests are run using [`Mdx`](https://github.com/realworldocaml/mdx) and most of them using cram-testing style. [`xref/compile.ml`](https://github.com/ocaml/odoc/blob/master/test/xref2/compile.ml) is a small script helping to write the cram tests.
328255
329-
[test-parser]: https://github.com/ocaml/odoc/blob/master/test/parser/test.ml
330-
[parser-test]: https://github.com/ocaml/odoc/blob/4c09575a5b25f4b224322f25d7867ce41fa4d032/test/parser/test.ml#L35
331-
[parser-expect]: https://github.com/ocaml/odoc/blob/4c09575a5b25f4b224322f25d7867ce41fa4d032/test/parser/expect/one-paragraph/word.txt
332-
[test-html]: https://github.com/ocaml/odoc/blob/master/test/html/test.ml
333-
[html-test]: https://github.com/ocaml/odoc/blob/master/test/html/cases/val.mli
334-
[html-expect]: https://github.com/ocaml/odoc/blob/master/test/html/expect/val.html
256+
[test-generators]: https://github.com/ocaml/odoc/tree/master/test/generators
335257
[test-print]: https://github.com/ocaml/odoc/tree/master/test/print
336-
[test-dune]: https://github.com/ocaml/odoc/tree/master/test/dune
337258
[test-inactive]: https://github.com/ocaml/odoc/tree/master/test/inactive
338259
339260
<br/>

0 commit comments

Comments
 (0)