1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
|
{0 Contributing to [odoc]}
Please ask any questions you have about [odoc], {{:https://github.com/ocaml/odoc/issues}open any issues},
{{:https://github.com/ocaml/odoc#contact}offer feedback}, etc. All of these are valued contributions :)
If you'd like specifically to work on the code of [odoc], we hope that you will
find the information in this file helpful.
{1 Quick start: HTML and CSS}
The [odoc] CSS is found at {{:https://github.com/ocaml/odoc/blob/master/src/odoc/etc/odoc.css}[src/odoc/etc/odoc.css]}. It
still needs work, and PRs are very welcome. You can edit CSS using your browser's {{:https://developer.mozilla.org/en-US/docs/Tools}developer}
{{:https://developer.chrome.com/docs/devtools/}tools}. Then send us a PR for the same changes made to this file.
Working on the HTML is more involved. The main HTML generator is in {{:https://github.com/ocaml/odoc/blob/master/src/html/generator.ml}[src/html/generator.ml]}.
It operates on the types defined in {!module-Odoc_document.Types}, which is an intermediate representation used by all output renderers. The type that
describes an individual HTML page is {!Odoc_document.Types.Page.t}.
To make edits to the HTML generation, run the following commands:
{ol
{- Install requirements:
{ul
{- A recent version of {{:http://www.html-tidy.org/}HTML tidy} (used for HTML validity testing) is required:
{[
# On MacOS (should be version 5.6.0 by the date of this writing)
brew install tidy-html5
# Debian / Ubuntu
sudo apt-get install tidy
]}}
{- A recent version of {{:https://github.com/stedolan/jq}jq} is required.
{[
# On MacOS
brew install jq
# Debian / Ubuntu
sudo apt-get install jq
]}}}}
{- Set up for development:
{[
git clone https://github.com/ocaml/odoc.git
cd odoc
opam pin add --no-action odoc .
opam install --with-test --deps-only odoc
opam install mdx
]}}
{- Make changes to the code. To compile it,
{[
make
]}
and then to run the tests,
{[
make test
]}
Changes to the HTML are likely to cause the tests to fail. See the section on {{!testing}testing} below to understand how to update them.
}
{- To test [odoc] against your own project, install it
{[
make clean
opam install odoc
]}
Since [odoc] is pinned, this installs your modified version. Then you can run
[odoc] in your project as normal:
{[
dune build @doc
]}
}
{- If all looks good, send odoc a PR :)
}
}
{1:testing Testing}
[odoc] uses a variety of different test types. We are slowly converging on using
Dune's {{:https://dune.readthedocs.io/en/stable/tests.html#cram-tests}cram tests},
though we still have many tests that aren't yet converted.
{2 Cram Tests}
The tests extensively use these for the model layer and are found in
{{:https://github.com/ocaml/odoc/blob/master/test/xref2}[test/xref2]}. These consist
of a directory called [something.t], containing a file [run.t]. This file has
shell-like syntax and usually runs [odoc] on some carefully crafted
input files. For tests of the model layer it's often useful to use the binary
[odoc_print] which can dump [.odoc] and [.odocl] files as JSON. This output can
then be piped through [jq] to verify that values are as expected.
We try to make these test files describe the test and what's expected, which
helps when the output isn’t what the test expected. This also means that
the tests can serve as documentation of how things work. As an example, see
the file {{:https://github.com/ocaml/odoc/blob/master/test/xref2/multi_file_module_type_of.t/run.t}[test/xref2/multi_file_module_type_of.t/run.t]}
The tests work by executing the shell script snippets and then comparing the
actual output with those in the [run.t] files. If these {e don't}
match, the difference is rendered as a diff. For example, if I change the
way [type] declarations are printed and run [dune runtest], I get the
following output:
{[
------ test/xref2/module_type_of.t/run.t
++++++ test/xref2/module_type_of.t/run.t.corrected
File "test/xref2/module_type_of.t/run.t", line 95, characters 0-1:
| ]
| },
| "T"
| ]
| },
| "Z"
| ]
| }
| }
| ]
|
|Check that the expansion of 'T.Y' contains only 1 type
|
| $ jq ".[0].ModuleType.expr.Some.TypeOf.t_expansion.Some.Signature.items" < T_sig.json > T.Y_sig.json
| $ odoc_print m.odocl | jq "map(keys | .[0])" < T.Y_sig.json
| [
-| "Type"
+| "Toupe"
| ]
|
]}
The intended response to this is:
+ Check the diff. If the [-] line is correct, the code is broken. If the [+]
line is correct, the test is broken.
+ If the test is broken, run [dune promote] to replace the expected output
with the current output.
{2 Other Expect-Tests}
Many of [odoc]'s older tests are {b custom Expect-tests}, similar to those
run in the Cram test above, but that don't use Dune's [promote] workflow.
As an example the parser tests in [test/parser] work in the following way:
+ The tests run some code, e.g., the [odoc] parser on the string [{e foo}].
+ They take the output, in this case an AST representing "emphasized [foo],"
and convert that output to a string, which will be an S-expression
roughly like [(emphasis (foo))].
+ There is an {b expected} copy of this S-expression in a file somewhere in the
repo. If the S-expression from the code doesn't match the expected one, the
test fails.
When one of these Expect-tests fail, the output is saved, so
the developer can choose to {b replace} the now-incorrect expected string.
For these custom Expect-tests, the results may look like:
{[
-- bold.000 [basic.] Failed --
in _build/_tests/bold.000.output:
{e foo}
--- expect/bold/basic.txt 2018-04-15 14:42:32.356895400 -0500
+++ _actual/bold/basic.txt 2018-04-15 17:36:26.812747400 -0500
@@ -2,5 +2,5 @@
(ok
(((f.ml (1 0) (1 7))
(paragraph
- (((f.ml (1 0) (1 7)) (bold (((f.ml (1 3) (1 6)) (word foo)))))))))))
+ (((f.ml (1 0) (1 7)) (emphasis (((f.ml (1 3) (1 6)) (word foo)))))))))))
(warnings ()))
To replace expected output with actual, run
bash _build/default/test/parser/_actual/replace.sh
]}
As with the Cram tests, the idea is to examine the diff to see if your code
is broken or the test is broken. If the test is broken, the actual results
may be promoted to the expected results by running the suggested command. If
your code is broken, go and fix it!
We are slowly shifting these custom Expect-tests over to the Dune [promote]
workflow.
{1 Coverage Analysis}
The [odoc] repo is set up for coverage analysis. This is most useful if you're
writing new tests, and want to know what they’re actually touching.
To use it,
+ Run [make coverage]. This will run the tests as normal, except at the end you’ll get a message like
{[
See _coverage/index.html
]}
You can then open [_coverage/index.html] and see the coverage of the code you’d like your new test to reach. However, it’s possible that it’s already covered
"accidentally" by tests that are checking other properties. In which
case, coverage analysis won’t be very useful :)
+ Write new tests.
+ Check coverage again.
{1 CI Tests}
[odoc] is tested by {{:https://ci.ocamllabs.io/}ocaml-ci} and by GitHub workflows.
One of these also does a coverage build, so we have up-to-date coverage stats
on {{:https://coveralls.io/github/ocaml/odoc}Coveralls}.
The tests cover Esy and Opam builds on Windows, macOS, and Linux. The Linux
tests cover all supported versions of OCaml. We strive to retain compatibility
back as far as we can (currently 4.02) which is important for supporting
{{:https://ocaml.org/docs/}ocaml.org/docs}.
{1 API Reference}
{2 Loading}
The library {{!page-odoc_loader}odoc.loader} is responsible for converting
from the OCaml {!module-Typedtree} representations to the
{{!Odoc_model.Lang}internal representation}.
{2 Model}
The library {{!page-odoc_model}odoc.model} contains definitions of
the internal types used to represent OCaml interfaces.
{2 Resolution and Expansion}
Resolution of Paths, Fragments and References, and Expansion of Modules and
Module Types are handled by the {{!page-odoc_xref2}odoc.xref2 library}.
{2 Intermediate Representation and Renderers}
The generic documentation intermediate format is defined in the
{{!page-odoc_document}odoc.document library}.
The three current renderers are implemented within the following libraries
{{!page-odoc_html}odoc.html}, {{!page-odoc_latex}odoc.latex}, and {{!page-odoc_manpage}odoc.manpage}.
{2 CLI and Driver}
The CLI for [odoc] and various helper functions for driving the process are contained in the
{{!page-odoc_odoc}odoc.odoc library}.
{2 Test and Internal Libraries}
There are a couple of libraries used internally for testing - {{!page-odoc_xref_test}odoc.xref_test}
and {{!page-odoc_model_desc}odoc.model_desc}.
{1 Dependency Libraries}
There are several {{!page-deps}dependency libraries} that [odoc] uses, whose functions,
type, and module declarations are essential for understanding how [odoc] works. See the
{{!page-driver}driver} page for details on how the documentation for these
libraries are included.
|