Skip to content

Commit

Permalink
Adds explanations and improve occurrence tests
Browse files Browse the repository at this point in the history
Signed-off-by: Paul-Elliot <peada@free.fr>
  • Loading branch information
panglesd committed Jul 26, 2023
1 parent 0d774b6 commit 50f8e11
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 165 deletions.
18 changes: 14 additions & 4 deletions test/occurrences/double_wrapped.t/run.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
This is what happens when a dune user write a toplevel module.
This test simulates the conditions when a dune user write a toplevel module.

The module C is not exposed in the handwritten toplevel module.
The module A and B are exposed.
The module B depends on both B and C, the module C only depends on A.

$ odoc compile -c module-a -c src-source root.mld

Expand All @@ -8,6 +12,9 @@ This is what happens when a dune user write a toplevel module.
$ ocamlc -c -open Main__ -o main__B.cmo b.ml -bin-annot -I .
$ ocamlc -c -open Main__ main.ml -bin-annot -I .

Passing the count-occurrences flag to odoc compile makes it collect the
occurrences information.

$ odoc compile --count-occurrences -I . main__A.cmt
$ odoc compile --count-occurrences -I . main__C.cmt
$ odoc compile --count-occurrences -I . main__B.cmt
Expand All @@ -20,12 +27,15 @@ This is what happens when a dune user write a toplevel module.
$ odoc link -I . main__C.odoc
$ odoc link -I . main__.odoc

Count occurrences
The count occurrences command currently outputs two files: a textual one (using the name given in the command line) and a marshalled hashtable, whose keys are odoc identifiers, and whose values are integers corresponding to the number of uses.

$ odoc count-occurrences -I . -o occurrences.txt

Uses of A and B are counted correctly, since the path is rewritten correctly.
Uses of C are not counted, since the canonical destination does not exists.
$ du -h occurrences.txt.bin
c865409ce5dd5251f4b5da25551c0dba occurrences.txt.bin

Uses of A and B are counted correctly, with the path rewritten correctly.
Uses of C are not counted, since the canonical destination (generated by dune) does not exists.
Uses of values Y.x and Z.y (in b.ml) are not counted since they come from a "local" module.
Uses of values Main__.C.y and Main__.A.x are not rewritten since we use references instead of paths.

Expand Down
2 changes: 1 addition & 1 deletion test/occurrences/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

(cram
(enabled_if
(= %{ocaml_version} 4.14.0))
(= %{ocaml_version} 4.14.1))
(deps %{bin:odoc} %{bin:odoc_print}))
21 changes: 1 addition & 20 deletions test/occurrences/source.t/a.ml
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
type t = string

let x = 2
let y = x + 1
let z a = if x = 1 || true then x + y else 0

module A = struct end
module B = A

module type T = sig end
module type U = T

type ext = ..
type ext += Foo

exception Exn

class cls = object end
class cls' = cls
class type ct = object end
let a = B.b
1 change: 1 addition & 0 deletions test/occurrences/source.t/b.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let b = 3
162 changes: 22 additions & 140 deletions test/occurrences/source.t/run.t
Original file line number Diff line number Diff line change
@@ -1,155 +1,37 @@
Files containing some values:
When both source rendering and occurrence counting are enabled, the occurrences information are used to generate "jump to documentation" links.

$ cat a.ml
type t = string

let x = 2
let y = x + 1
let z a = if x = 1 || true then x + y else 0

module A = struct end
module B = A

module type T = sig end
module type U = T

type ext = ..
type ext += Foo

exception Exn

class cls = object end
class cls' = cls
class type ct = object end
This test tests this.

Source pages require a parent:
Files containing some values:

$ odoc compile -c module-a -c src-source root.mld
$ cat a.ml | head -n 3
let a = B.b

Compile the modules:
$ cat b.ml | head -n 3
let b = 3

$ ocamlc -c a.ml -bin-annot
Source pages require a parent:

Compile the pages without --source:
$ odoc compile -c module-a -c module-b -c src-source root.mld

$ odoc compile a.cmt
$ odoc link -I . a.odoc
$ odoc html-generate --indent -o html a.odocl

No source links are generated in the documentation:
Compile the modules:

$ ! grep source_link html/A/index.html -B 2
$ ocamlc -c b.ml -bin-annot
$ ocamlc -c a.ml -I . -bin-annot

Now, compile the pages with the --source option:
Compile the pages with the source and occurrences options

$ printf "a.ml\n" > source_tree.map
$ printf "a.ml\nb.ml\n" > source_tree.map
$ odoc source-tree -I . --parent page-root -o src-source.odoc source_tree.map

$ odoc compile -I . --source-name a.ml --source-parent-file src-source.odoc a.cmt
$ odoc compile --count-occurrences -I . --source-name b.ml --source-parent-file src-source.odoc b.cmt
$ odoc compile --count-occurrences -I . --source-name a.ml --source-parent-file src-source.odoc a.cmt
$ odoc link -I . b.odoc
$ odoc link -I . a.odoc
$ odoc html-generate --source b.ml --indent -o html b.odocl
$ odoc html-generate --source a.ml --indent -o html a.odocl
$ odoc support-files -o html

Source links generated in the documentation:

$ grep source_link html/A/index.html -B 2
<header class="odoc-preamble">
<h1>Module <code><span>A</span></code>
<a href="../root/source/a.ml.html" class="source_link">Source</a>
--
<div class="spec type anchored" id="type-t">
<a href="#type-t" class="anchor"></a>
<a href="../root/source/a.ml.html#def-0" class="source_link">Source</a>
--
<div class="spec value anchored" id="val-x">
<a href="#val-x" class="anchor"></a>
<a href="../root/source/a.ml.html#def-1" class="source_link">Source</a>
--
<div class="spec value anchored" id="val-y">
<a href="#val-y" class="anchor"></a>
<a href="../root/source/a.ml.html#def-2" class="source_link">Source</a>
--
<div class="spec value anchored" id="val-z">
<a href="#val-z" class="anchor"></a>
<a href="../root/source/a.ml.html#def-3" class="source_link">Source</a>
--
<div class="spec module anchored" id="module-A">
<a href="#module-A" class="anchor"></a>
<a href="../root/source/a.ml.html#def-5" class="source_link">Source</a>
--
<div class="spec module anchored" id="module-B">
<a href="#module-B" class="anchor"></a>
<a href="../root/source/a.ml.html#def-5" class="source_link">Source</a>
--
<div class="spec module-type anchored" id="module-type-T">
<a href="#module-type-T" class="anchor"></a>
<a href="../root/source/a.ml.html#def-7" class="source_link">Source</a>
--
<div class="spec module-type anchored" id="module-type-U">
<a href="#module-type-U" class="anchor"></a>
<a href="../root/source/a.ml.html#def-8" class="source_link">Source</a>
--
<div class="spec type anchored" id="type-ext">
<a href="#type-ext" class="anchor"></a>
<a href="../root/source/a.ml.html#def-9" class="source_link">Source</a>
--
<div class="spec type extension anchored" id="extension-decl-Foo">
<a href="#extension-decl-Foo" class="anchor"></a>
<a href="../root/source/a.ml.html#def-10" class="source_link">Source</a>
--
<div class="spec exception anchored" id="exception-Exn">
<a href="#exception-Exn" class="anchor"></a>
<a href="../root/source/a.ml.html#def-11" class="source_link">Source</a>
--
<div class="spec class anchored" id="class-cls">
<a href="#class-cls" class="anchor"></a>
<a href="../root/source/a.ml.html#def-12" class="source_link">Source</a>
--
<div class="spec class anchored" id="class-cls'">
<a href="#class-cls'" class="anchor"></a>
<a href="../root/source/a.ml.html#def-14" class="source_link">Source</a>
--
<div class="spec class-type anchored" id="class-type-ct">
<a href="#class-type-ct" class="anchor"></a>
<a href="../root/source/a.ml.html#def-15" class="source_link">Source</a>

Ids generated in the source code:
The source for a contains a link to the documentation of `B.b`, as it is used in the implementation:

$ cat html/root/source/a.ml.html | tr '> ' '\n\n' | grep '^id'
id="L1"
id="L2"
id="L3"
id="L4"
id="L5"
id="L6"
id="L7"
id="L8"
id="L9"
id="L10"
id="L11"
id="L12"
id="L13"
id="L14"
id="L15"
id="L16"
id="L17"
id="L18"
id="L19"
id="L20"
id="def-0"
id="x_268"
id="def-1"
id="y_269"
id="def-2"
id="z_270"
id="def-3"
id="a_272"
id="def-5"
id="def-6"
id="def-7"
id="def-8"
id="def-9"
id="def-10"
id="def-11"
id="def-12"
id="def-14"
id="def-15"
$ cat html/root/source/a.ml.html | tr '> ' '\n\n' | grep 'href' | grep val-b
href="../../B/index.html#val-b"

0 comments on commit 50f8e11

Please sign in to comment.