Skip to content

Commit f2014c2

Browse files
committed
Make tests more reproducible
Also contains a fix for source-id - currently a source id requires a container page as parent. This was previously 'working' by creating a parent page called "./" which is obviously not great. This change requires that the source id have a non-empty parent, which we may want to change at some point.
1 parent 3e34177 commit f2014c2

File tree

17 files changed

+183
-178
lines changed

17 files changed

+183
-178
lines changed

src/loader/odoc_loader.ml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ let read_cmti ~make_root ~parent ~filename () =
108108
match cmt_info.cmt_interface_digest with
109109
| None -> raise Corrupted
110110
| Some digest as interface ->
111-
Odoc_model.Names.set_unique_ident (Digest.to_hex digest);
111+
let _ =
112+
try Odoc_model.Names.set_unique_ident (Digest.to_hex digest)
113+
with _ -> ()
114+
in
112115
let name = cmt_info.cmt_modname in
113116
let sourcefile =
114117
( cmt_info.cmt_sourcefile,
@@ -134,7 +137,9 @@ let read_cmt ~make_root ~parent ~filename () =
134137
let interface = cmt_info.cmt_interface_digest in
135138
(match cmt_info.cmt_interface_digest with
136139
| None -> raise Corrupted
137-
| Some digest -> Odoc_model.Names.set_unique_ident (Digest.to_hex digest));
140+
| Some digest -> (
141+
try Odoc_model.Names.set_unique_ident (Digest.to_hex digest)
142+
with _ -> ()));
138143
let imports = cmt_info.cmt_imports in
139144
match cmt_info.cmt_annots with
140145
| Packed (_, files) ->
@@ -205,7 +210,8 @@ let read_impl ~make_root ~filename ~source_id () =
205210
| None -> raise Corrupted
206211
| exception Not_found -> raise Corrupted)
207212
in
208-
Odoc_model.Names.set_unique_ident (Digest.to_hex digest);
213+
Odoc_model.Names.set_unique_ident
214+
(Odoc_model.Paths.Identifier.fullname source_id |> String.concat "-");
209215
let root =
210216
match make_root ~module_name:name ~digest with
211217
| Ok root -> root

src/odoc/bin/main.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ end = struct
151151
file |> Fs.File.basename |> Fs.File.to_string
152152
|> Astring.String.is_prefix ~affix:"page-"
153153

154+
let unique_id =
155+
let doc = "For debugging use" in
156+
Arg.(value & opt (some string) None & info ~doc ~docv:"ID" [ "unique-id" ])
157+
154158
let output_file ~dst ~input =
155159
match dst with
156160
| Some file ->
@@ -175,8 +179,13 @@ end = struct
175179

176180
let compile hidden directories resolve_fwd_refs dst output_dir package_opt
177181
parent_name_opt parent_id_opt open_modules children input warnings_options
178-
=
182+
unique_id =
179183
let open Or_error in
184+
let _ =
185+
match unique_id with
186+
| Some id -> Odoc_model.Names.set_unique_ident id
187+
| None -> ()
188+
in
180189
let resolver =
181190
Resolver.create ~important_digests:(not resolve_fwd_refs) ~directories
182191
~open_modules
@@ -262,7 +271,7 @@ end = struct
262271
const handle_error
263272
$ (const compile $ hidden $ odoc_file_directories $ resolve_fwd_refs $ dst
264273
$ output_dir $ package_opt $ parent_opt $ parent_id_opt $ open_modules
265-
$ children $ input $ warnings_options))
274+
$ children $ input $ warnings_options $ unique_id))
266275

267276
let info ~docs =
268277
let man =

src/odoc/source.ml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@ let root_of_implementation ~source_id ~module_name ~digest =
2121

2222
let compile ~resolver ~output ~warnings_options ~source_id input =
2323
let parent_id, name = Fpath.(split_base (v source_id)) in
24-
let parent = Compile.mk_id Fpath.(to_string (rem_empty_seg parent_id)) in
25-
let source_id =
26-
Paths.Identifier.Mk.source_page (parent, [ Fpath.to_string name ])
27-
in
28-
let make_root = root_of_implementation ~source_id in
29-
let result =
30-
Error.catch_errors_and_warnings (fun () ->
31-
resolve_and_substitute ~resolver ~make_root ~source_id input)
32-
in
33-
(* Extract warnings to write them into the output file *)
34-
let _, warnings = Error.unpack_warnings result in
35-
Error.handle_errors_and_warnings ~warnings_options result >>= fun impl ->
36-
Odoc_file.save_impl output ~warnings impl;
37-
Ok ()
24+
if parent_id = Fpath.v "./" then
25+
Error (`Msg "Source id cannot be in the root directory")
26+
else
27+
let parent = Compile.mk_id Fpath.(to_string (rem_empty_seg parent_id)) in
28+
29+
let source_id =
30+
Paths.Identifier.Mk.source_page (parent, [ Fpath.to_string name ])
31+
in
32+
let make_root = root_of_implementation ~source_id in
33+
let result =
34+
Error.catch_errors_and_warnings (fun () ->
35+
resolve_and_substitute ~resolver ~make_root ~source_id input)
36+
in
37+
(* Extract warnings to write them into the output file *)
38+
let _, warnings = Error.unpack_warnings result in
39+
Error.handle_errors_and_warnings ~warnings_options result >>= fun impl ->
40+
Odoc_file.save_impl output ~warnings impl;
41+
Ok ()

test/integration/json_expansion_with_sources.t/run.t

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ Test the JSON output in the presence of expanded modules.
22

33
$ ocamlc -c -bin-annot -o main__A.cmo a.ml -I .
44
$ ocamlc -c -bin-annot main.ml -I .
5-
$ odoc compile-impl --source-id a.ml -I . main__A.cmt --output-dir .
5+
$ odoc compile-impl --source-id src/a.ml -I . main__A.cmt --output-dir .
66
$ odoc compile -I . main__A.cmt
7-
$ odoc compile-impl --source-id main.ml -I . main.cmt --output-dir .
7+
$ odoc compile-impl --source-id src/main.ml -I . main.cmt --output-dir .
88
$ odoc compile -I . main.cmt
99
$ odoc link -I . impl-main__A.odoc
1010
$ odoc link -I . impl-main.odoc
@@ -24,27 +24,27 @@ Test the JSON output in the presence of expanded modules.
2424
html/Main/A/index.html.json
2525
html/Main/A/B/index.html.json
2626
$ odoc html-targets --source a.ml -o html impl-main__A.odocl
27-
html/a.ml.html
27+
html/src/a.ml.html
2828
$ odoc html-targets --source main.ml -o html impl-main.odocl
29-
html/main.ml.html
29+
html/src/main.ml.html
3030
$ odoc html-targets --source a.ml --as-json -o html impl-main__A.odocl
31-
html/a.ml.html.json
31+
html/src/a.ml.html.json
3232
$ odoc html-targets --source main.ml --as-json -o html impl-main.odocl
33-
html/main.ml.html.json
33+
html/src/main.ml.html.json
3434

3535
$ odoc html-generate --source a.ml --as-json -o html impl-main__A.odocl
3636
$ odoc html-generate --as-json -o html main__A.odocl
3737
$ odoc html-generate --source main.ml --as-json -o html impl-main.odocl
3838
$ odoc html-generate --as-json -o html main.odocl
3939

4040
$ cat html/Main/index.html.json
41-
{"type":"documentation","uses_katex":false,"breadcrumbs":[{"name":"Main","href":"#","kind":"module"}],"toc":[],"source_anchor":".././main.ml.html","preamble":"","content":"<div class=\"odoc-spec\"><div class=\"spec module anchored\" id=\"module-A\"><a href=\"#module-A\" class=\"anchor\"></a><a href=\".././a.ml.html\" class=\"source_link\">Source</a><code><span><span class=\"keyword\">module</span> <a href=\"A/index.html\">A</a></span><span> : <span class=\"keyword\">sig</span> ... <span class=\"keyword\">end</span></span></code></div></div>"}
41+
{"type":"documentation","uses_katex":false,"breadcrumbs":[{"name":"Main","href":"#","kind":"module"}],"toc":[],"source_anchor":"../src/main.ml.html","preamble":"","content":"<div class=\"odoc-spec\"><div class=\"spec module anchored\" id=\"module-A\"><a href=\"#module-A\" class=\"anchor\"></a><a href=\"../src/a.ml.html\" class=\"source_link\">Source</a><code><span><span class=\"keyword\">module</span> <a href=\"A/index.html\">A</a></span><span> : <span class=\"keyword\">sig</span> ... <span class=\"keyword\">end</span></span></code></div></div>"}
4242

4343
$ cat html/Main/A/index.html.json
44-
{"type":"documentation","uses_katex":false,"breadcrumbs":[{"name":"Main","href":"../index.html","kind":"module"},{"name":"A","href":"#","kind":"module"}],"toc":[],"source_anchor":"../.././a.ml.html","preamble":"","content":"<div class=\"odoc-spec\"><div class=\"spec module anchored\" id=\"module-B\"><a href=\"#module-B\" class=\"anchor\"></a><a href=\"../.././a.ml.html#module-B\" class=\"source_link\">Source</a><code><span><span class=\"keyword\">module</span> <a href=\"B/index.html\">B</a></span><span> : <span class=\"keyword\">sig</span> ... <span class=\"keyword\">end</span></span></code></div></div>"}
44+
{"type":"documentation","uses_katex":false,"breadcrumbs":[{"name":"Main","href":"../index.html","kind":"module"},{"name":"A","href":"#","kind":"module"}],"toc":[],"source_anchor":"../../src/a.ml.html","preamble":"","content":"<div class=\"odoc-spec\"><div class=\"spec module anchored\" id=\"module-B\"><a href=\"#module-B\" class=\"anchor\"></a><a href=\"../../src/a.ml.html#module-B\" class=\"source_link\">Source</a><code><span><span class=\"keyword\">module</span> <a href=\"B/index.html\">B</a></span><span> : <span class=\"keyword\">sig</span> ... <span class=\"keyword\">end</span></span></code></div></div>"}
4545

4646
$ cat html/Main/A/B/index.html.json
47-
{"type":"documentation","uses_katex":false,"breadcrumbs":[{"name":"Main","href":"../../index.html","kind":"module"},{"name":"A","href":"../index.html","kind":"module"},{"name":"B","href":"#","kind":"module"}],"toc":[],"source_anchor":"../../.././a.ml.html#module-B","preamble":"","content":""}
47+
{"type":"documentation","uses_katex":false,"breadcrumbs":[{"name":"Main","href":"../../index.html","kind":"module"},{"name":"A","href":"../index.html","kind":"module"},{"name":"B","href":"#","kind":"module"}],"toc":[],"source_anchor":"../../../src/a.ml.html#module-B","preamble":"","content":""}
4848

49-
$ cat html/a.ml.html.json
50-
{"type":"source","breadcrumbs":[{"name":".","href":"index.html","kind":"page"},{"name":"a.ml","href":"#","kind":"source"}],"content":"<pre class=\"source_container\"><code class=\"source_line_column\"><a id=\"L1\" class=\"source_line\" href=\"#L1\">1</a>\u000A</code><code class=\"source_code\"><span><span id=\"module-B\"><span class=\"MODULE\">module</span> <span class=\"UIDENT\">B</span> <span class=\"EQUAL\">=</span> <span class=\"STRUCT\">struct</span> <span class=\"END\">end</span></span><span class=\"EOL\">\u000A</span></span></code></pre>"}
49+
$ cat html/src/a.ml.html.json
50+
{"type":"source","breadcrumbs":[{"name":"src","href":"index.html","kind":"page"},{"name":"a.ml","href":"#","kind":"source"}],"content":"<pre class=\"source_container\"><code class=\"source_line_column\"><a id=\"L1\" class=\"source_line\" href=\"#L1\">1</a>\u000A</code><code class=\"source_code\"><span><span id=\"module-B\"><span class=\"MODULE\">module</span> <span class=\"UIDENT\">B</span> <span class=\"EQUAL\">=</span> <span class=\"STRUCT\">struct</span> <span class=\"END\">end</span></span><span class=\"EOL\">\u000A</span></span></code></pre>"}

test/occurrences/double_wrapped.t/run.t

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ The module B depends on both B and C, the module C only depends on A.
1212

1313
Collecting occurrences is done on implementation files.
1414

15-
$ odoc compile-impl --source-id a.ml -I . main__A.cmt --output-dir .
16-
$ odoc compile-impl --source-id c.ml -I . main__C.cmt --output-dir .
17-
$ odoc compile-impl --source-id b.ml -I . main__B.cmt --output-dir .
18-
$ odoc compile-impl --source-id main__.ml -I . main__.cmt --output-dir .
19-
$ odoc compile-impl --source-id main.ml -I . main.cmt --output-dir .
15+
$ odoc compile-impl --source-id src/a.ml -I . main__A.cmt --output-dir .
16+
$ odoc compile-impl --source-id src/c.ml -I . main__C.cmt --output-dir .
17+
$ odoc compile-impl --source-id src/b.ml -I . main__B.cmt --output-dir .
18+
$ odoc compile-impl --source-id src/main__.ml -I . main__.cmt --output-dir .
19+
$ odoc compile-impl --source-id src/main.ml -I . main.cmt --output-dir .
2020

2121
We need the interface version to resolve the occurrences
2222

test/sources/double_wrapped.t/run.t

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ Similar to the lookup_def_wrapped test.
55
$ ocamlc -c -o main__.cmo main__.ml -bin-annot -I .
66
$ ocamlc -c -open Main__ main.ml -bin-annot -I .
77

8-
$ odoc compile-impl --source-id a.ml -I . main__A.cmt --output-dir .
8+
$ odoc compile-impl --source-id src/a.ml -I . main__A.cmt --output-dir .
99
$ odoc compile -I . main__A.cmt
10-
$ odoc compile-impl --source-id main__.ml -I . main__.cmt --output-dir .
10+
$ odoc compile-impl --source-id src/main__.ml -I . main__.cmt --output-dir .
1111
$ odoc compile -I . main__.cmt
12-
$ odoc compile-impl --source-id main.ml -I . main.cmt --output-dir .
12+
$ odoc compile-impl --source-id src/main.ml -I . main.cmt --output-dir .
1313
$ odoc compile -I . main.cmt
1414

1515
$ odoc link -I . main.odoc
@@ -31,8 +31,9 @@ Look if all the source files are generated:
3131
html/Main/A
3232
html/Main/A/index.html
3333
html/Main/index.html
34-
html/a.ml.html
35-
html/main.ml.html
34+
html/src
35+
html/src/a.ml.html
36+
html/src/main.ml.html
3637

3738
$ cat html/Main/A/index.html
3839
<!DOCTYPE html>
@@ -50,14 +51,14 @@ Look if all the source files are generated:
5051
</nav>
5152
<header class="odoc-preamble">
5253
<h1>Module <code><span>Main.A</span></code>
53-
<a href="../.././a.ml.html" class="source_link">Source</a>
54+
<a href="../../src/a.ml.html" class="source_link">Source</a>
5455
</h1>
5556
</header>
5657
<div class="odoc-content">
5758
<div class="odoc-spec">
5859
<div class="spec value anchored" id="val-x">
5960
<a href="#val-x" class="anchor"></a>
60-
<a href="../.././a.ml.html#val-x" class="source_link">Source</a>
61+
<a href="../../src/a.ml.html#val-x" class="source_link">Source</a>
6162
<code><span><span class="keyword">val</span> x : int</span></code>
6263
</div>
6364
</div>

test/sources/functor.t/run.t

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Verify the behavior on functors.
33
$ ocamlc -c -o s.cmo s.ml -bin-annot -I .
44
$ ocamlc -c -o a.cmo a.ml -bin-annot -I .
55
$ ocamlc -c -o b.cmo b.ml -bin-annot -I .
6-
$ odoc compile-impl --source-id s.ml -I . s.cmt --output-dir .
6+
$ odoc compile-impl --source-id src/s.ml -I . s.cmt --output-dir .
77
$ odoc compile -I . s.cmt
8-
$ odoc compile-impl --source-id a.ml -I . a.cmt --output-dir .
8+
$ odoc compile-impl --source-id src/a.ml -I . a.cmt --output-dir .
99
$ odoc compile -I . a.cmt
10-
$ odoc compile-impl --source-id b.ml -I . b.cmt --output-dir .
10+
$ odoc compile-impl --source-id src/b.ml -I . b.cmt --output-dir .
1111
$ odoc compile -I . b.cmt
1212
$ odoc link -I . s.odoc
1313
$ odoc link -I . a.odoc
@@ -40,23 +40,24 @@ Verify the behavior on functors.
4040
html/S/index.html
4141
html/S/module-type-S
4242
html/S/module-type-S/index.html
43-
html/a.ml.html
44-
html/b.ml.html
45-
html/s.ml.html
43+
html/src
44+
html/src/a.ml.html
45+
html/src/b.ml.html
46+
html/src/s.ml.html
4647

4748
In this test, the functor expansion contains the right link.
4849

4950
$ cat html/A/F/index.html | grep source_link -C 1
5051
<h1>Module <code><span>A.F</span></code>
51-
<a href="../.././a.ml.html#module-F" class="source_link">Source</a>
52+
<a href="../../src/a.ml.html#module-F" class="source_link">Source</a>
5253
</h1>
5354
--
5455
<a href="#type-t" class="anchor"></a>
55-
<a href="../.././a.ml.html#module-F.type-t" class="source_link">Source
56+
<a href="../../src/a.ml.html#module-F.type-t" class="source_link">Source
5657
</a>
5758
--
5859
<a href="#val-y" class="anchor"></a>
59-
<a href="../.././a.ml.html#module-F.val-y" class="source_link">Source
60+
<a href="../../src/a.ml.html#module-F.val-y" class="source_link">Source
6061
</a>
6162

6263
$ cat html/root/source/a.ml.html | grep L3
@@ -68,19 +69,19 @@ However, on functor results, there is a link to source in the file:
6869
$ cat html/B/R/index.html | grep source_link -C 2
6970
<header class="odoc-preamble">
7071
<h1>Module <code><span>B.R</span></code>
71-
<a href="../.././b.ml.html#module-R" class="source_link">Source</a>
72+
<a href="../../src/b.ml.html#module-R" class="source_link">Source</a>
7273
</h1>
7374
</header>
7475
--
7576
<div class="spec type anchored" id="type-t">
7677
<a href="#type-t" class="anchor"></a>
77-
<a href="../.././a.ml.html#module-F.type-t" class="source_link">Source
78+
<a href="../../src/a.ml.html#module-F.type-t" class="source_link">Source
7879
</a>
7980
<code><span><span class="keyword">type</span> t</span>
8081
--
8182
<div class="spec value anchored" id="val-y">
8283
<a href="#val-y" class="anchor"></a>
83-
<a href="../.././a.ml.html#module-F.val-y" class="source_link">Source
84+
<a href="../../src/a.ml.html#module-F.val-y" class="source_link">Source
8485
</a>
8586
<code>
8687

test/sources/include_in_expansion.t/run.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ Checking that source parents are kept, using include.
66
$ ocamlc -c -o main__A.cmo a.ml -bin-annot -I .
77
$ ocamlc -c main.ml -bin-annot -I .
88

9-
$ odoc compile-impl --source-id b.m -I . b.cmt --output-dir .
9+
$ odoc compile-impl --source-id src/b.m -I . b.cmt --output-dir .
1010
$ odoc compile -I . b.cmt
11-
$ odoc compile-impl --source-id a.ml -I . main__A.cmt --output-dir .
11+
$ odoc compile-impl --source-id src/a.ml -I . main__A.cmt --output-dir .
1212
$ odoc compile -I . main__A.cmt
13-
$ odoc compile-impl --source-id main.ml -I . main.cmt --output-dir .
13+
$ odoc compile-impl --source-id src/main.ml -I . main.cmt --output-dir .
1414
$ odoc compile -I . main.cmt
1515

1616
$ odoc link -I . main.odoc
@@ -28,13 +28,13 @@ source parent of value y should be left to B.
2828

2929
$ grep source_link html/Main/A/index.html -C 1
3030
<h1>Module <code><span>Main.A</span></code>
31-
<a href="../.././a.ml.html" class="source_link">Source</a>
31+
<a href="../../src/a.ml.html" class="source_link">Source</a>
3232
</h1>
3333
--
3434
<a href="#val-y" class="anchor"></a>
35-
<a href="../.././b.m.html#val-y" class="source_link">Source</a>
35+
<a href="../../src/b.m.html#val-y" class="source_link">Source</a>
3636
<code><span><span class="keyword">val</span> y : int</span></code>
3737
--
3838
<a href="#val-x" class="anchor"></a>
39-
<a href="../.././a.ml.html#val-x" class="source_link">Source</a>
39+
<a href="../../src/a.ml.html#val-x" class="source_link">Source</a>
4040
<code><span><span class="keyword">val</span> x : int</span></code>

0 commit comments

Comments
 (0)