@@ -15,7 +15,6 @@ find the information in this file helpful.
15
15
- [ Quick start: HTML and CSS] ( #Quick_start )
16
16
- [ Testing] ( #Testing )
17
17
- [ Debug prints] ( #Debug_prints )
18
- - [ Expect tests] ( #Expect_tests )
19
18
- [ Coverage analysis] ( #Coverage_analysis )
20
19
- [ Project structure] ( #Project_structure )
21
20
- [ Roadmap] ( #Roadmap )
@@ -136,72 +135,6 @@ The [testing framework][alcotest] will display STDERR if a test fails.
136
135
137
136
<br/>
138
137
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/>
205
138
206
139
<a id="Coverage_analysis"></a>
207
140
### Coverage analysis
@@ -237,15 +170,10 @@ writing new tests, and want to know what they are actually touching. To use it,
237
170
odoc is divided into several sub-libraries, each of which is a directory
238
171
under `src/`. Most of these have a *main file*, whose name is the directory
239
172
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
242
175
hidden behind that interface.
243
176
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
-
249
177
The `dune` files in each directory can be used to figure out how the
250
178
directories depend on each other. Mostly, however, everything depends on
251
179
`model`, and `odoc` depends on everything.
@@ -258,7 +186,7 @@ OCaml.
258
186
- [`src/model`][model-dir] — datatypes representing the OCaml
259
187
language ([`src/model/lang.ml`][lang]), error-handling
260
188
([`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
262
190
file. It is a collection of the datatypes that the rest of the odoc
263
191
sub-libraries use to communicate with each other, so everything else depends on
264
192
`model`.
@@ -267,18 +195,17 @@ sub-libraries use to communicate with each other, so everything else depends on
267
195
to `model`. You can see the three functions' signatures in the main file,
268
196
[`src/loader/odoc__loader.mli`][loader-api].
269
197
270
- - [`src/parser`][parser-dir] — 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
-
274
198
- [`src/xref`][xref-dir] — functions for resolving cross-references. These
275
199
consume things from `model`, and return transformed instances. The signature, in
276
200
[`src/xref/odoc__xref.mli`][xref-api] is not very pretty, but the usage of
277
201
`xref` is pretty isolated in the rest of odoc, and can be found by grepping for
278
202
`Xref`.
279
203
280
- - [`src/html`][html-dir] — the HTML generator. The main file is
281
- [`src/html/odoc__html.mli`][html-api].
204
+ - [`src/html`][html-dir] — the HTML generator.
205
+
206
+ - [`src/latex`][latex-dir] — the Latex generator.
207
+
208
+ - [`src/man`][man-dir] — the Manpages generator.
282
209
283
210
- [`src/odoc`][odoc-dir] — the overall `odoc` command-line tool that ties
284
211
the other parts together. This doesn't have the same kind of main file, because
@@ -294,46 +221,40 @@ third-party software.
294
221
[lang]: https://github.com/ocaml/odoc/blob/master/src/model/lang.ml
295
222
[error]: https://github.com/ocaml/odoc/blob/master/src/model/error.ml
296
223
[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
299
224
[loader-dir]: https://github.com/ocaml/odoc/tree/master/src/loader
300
225
[loader-api]: https://github.com/ocaml/odoc/blob/master/src/loader/odoc__loader.mli
301
226
[xref-dir]: https://github.com/ocaml/odoc/tree/master/src/xref
302
227
[xref-api]: https://github.com/ocaml/odoc/blob/master/src/xref/odoc__xref.mli
303
228
[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
305
231
[odoc-dir]: https://github.com/ocaml/odoc/tree/master/src/odoc
306
232
[main]: https://github.com/ocaml/odoc/blob/master/src/odoc/bin/main.ml
307
233
[util-dir]: https://github.com/ocaml/odoc/tree/master/src/util
308
234
[vendor-dir]: https://github.com/ocaml/odoc/tree/master/src/vendor
309
235
310
236
The tests parallel the structure of `src/`:
311
237
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).
315
239
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.
319
242
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.
322
244
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.
325
246
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.
328
255
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
335
257
[test-print]: https://github.com/ocaml/odoc/tree/master/test/print
336
- [test-dune]: https://github.com/ocaml/odoc/tree/master/test/dune
337
258
[test-inactive]: https://github.com/ocaml/odoc/tree/master/test/inactive
338
259
339
260
<br/>
0 commit comments