This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,3 @@
(executable
(name foo)
(public_name foo))

View file

@ -0,0 +1,4 @@
(lang dune 3.7)
(package
(name foo))

View file

@ -0,0 +1,8 @@
This tests shows how to use the `dune ocaml doc` command to open the
documentation index to a browser.
$ if [ "$(uname)" = Darwin ]; then mv xdg-open open; fi
$ export PATH=.:$PATH
$ dune ocaml doc
Docs built. Index can be found here: _build/default/_doc/_html/index.html
open command received args:
_build/default/_doc/_html/index.html

View file

@ -0,0 +1,3 @@
#!/bin/sh
echo "open command received args:"
echo $@

View file

@ -0,0 +1,46 @@
$ cat > dune-project << EOF
> (lang dune 3.10)
>
> (package
> (name l))
> EOF
$ cat > dune << EOF
> (library
> (public_name l))
> EOF
$ cat > l.ml << EOF
> module M = struct
> type t = int
> end
> EOF
$ list_docs () {
> find _build/default/_doc/_html -name '*.html' -o -name '*.html.json' | sort
> }
$ dune build @doc-json
$ list_docs
_build/default/_doc/_html/index.html.json
_build/default/_doc/_html/l/L/M/index.html.json
_build/default/_doc/_html/l/L/index.html.json
_build/default/_doc/_html/l/index.html.json
The toplevel index is generated by dune itself:
$ cat _build/default/_doc/_html/index.html.json
{"packages":[{"name":"l","version":null,"link":"l/index.html"}]}
@doc will continue generating doc as usual:
$ dune build @doc
$ list_docs
_build/default/_doc/_html/index.html
_build/default/_doc/_html/index.html.json
_build/default/_doc/_html/l/L/M/index.html
_build/default/_doc/_html/l/L/M/index.html.json
_build/default/_doc/_html/l/L/index.html
_build/default/_doc/_html/l/L/index.html.json
_build/default/_doc/_html/l/index.html
_build/default/_doc/_html/l/index.html.json

View file

@ -0,0 +1,3 @@
(cram
(applies_to :whole_subtree)
(deps %{bin:odoc} %{bin:sherlodoc}))

View file

@ -0,0 +1,16 @@
Show behavior of doc-private alias when it's part of an unavailable library
$ cat > dune-project << EOF
> (lang dune 3.13)
> EOF
$ cat > dune << EOF
> (library
> (name foo)
> (enabled_if (= %{context_name} "unavailable")))
> EOF
$ cat > foo.ml <<EOF
> let x = "foo"
> EOF
$ dune build @doc-private

View file

@ -0,0 +1,17 @@
Private libraries attached to packages shouldn't be displayed in the index
$ cat <<EOF > dune-project
> (lang dune 3.0)
> (package (name foo))
> EOF
$ cat <<EOF > dune
> (library
> (name foo)
> (package foo))
> EOF
> touch foo.ml bar.ml
$ dune build @doc
$ cat _build/default/_doc/_mlds/foo/index.mld
{0 foo index}

View file

@ -0,0 +1,34 @@
The rules that call odoc know that it is going to read the ODOC_SYNTAX
variable, and can rebuild as needed.
$ cat > dune-project << EOF
> (lang dune 1.1)
> (package (name l))
> EOF
$ cat > dune << EOF
> (library
> (public_name l))
> EOF
$ cat > l.ml << EOF
> module type X = sig end
> EOF
$ detect () {
> if grep -q '>sig<' $1 ; then
> echo it is ocaml
> elif grep -q '{ ... }' $1 ; then
> echo it is reason
> else
> echo it is unknown
> fi
> }
$ dune build @doc
$ detect _build/default/_doc/_html/l/L/index.html
it is ocaml
$ ODOC_SYNTAX=re dune build @doc
$ detect _build/default/_doc/_html/l/L/index.html
it is reason

View file

@ -0,0 +1,44 @@
We create two libraries `l.one` and `l.two` with a conflicting module.
They build fine, are not co-linkable, but documentation should be able to be
built. See #1645.
$ cat > dune-project << EOF
> (lang dune 1.0)
> (package (name l))
> EOF
$ mkdir one
$ cat > one/dune << EOF
> (library
> (name l_one)
> (public_name l.one)
> (wrapped false))
> EOF
$ touch one/module.ml
$ mkdir two
$ cat > two/dune << EOF
> (library
> (name l_two)
> (public_name l.two)
> (wrapped false))
> EOF
$ touch two/module.ml
$ dune build @install
$ dune build @doc
Error: Multiple rules generated for
_build/default/_doc/_html/l/Module/index.html:
- <internal location>
- <internal location>
-> required by alias _doc/_html/l/doc
-> required by alias doc
Error: Multiple rules generated for
_build/default/_doc/_odocls/l/module.odocl:
- <internal location>
- <internal location>
-> required by _build/default/_doc/_html/l/db.js
-> required by _build/default/_doc/_html/l/index.html
-> required by alias _doc/_html/l/doc
-> required by alias doc
[1]

View file

@ -0,0 +1,5 @@
(library
(name hello_world)
(public_name hello_world))
(documentation)

View file

@ -0,0 +1 @@
(library (name test))

View file

@ -0,0 +1 @@
(library (name test))

View file

@ -0,0 +1,3 @@
This test checks that there is no clash when two private libraries have the same name
$ dune build @doc-private

View file

@ -0,0 +1,3 @@
(cram
(applies_to :whole_subtree)
(deps %{bin:odoc}))

View file

@ -0,0 +1,3 @@
(library
(public_name odoctest)
(name odoctest))

View file

@ -0,0 +1,3 @@
(** Test linking with stdlib *)
let fprintf = Format.fprintf

View file

@ -0,0 +1,5 @@
Check that a type path referring to Stdlib.Format is resolved:
$ dune build @doc-new
$ grep unresolved _build/default/_doc_new/html/docs/local/odoctest/Odoctest/index.html
[1]

View file

@ -0,0 +1,34 @@
The rules that call odoc know that it is going to read the ODOC_SYNTAX
variable, and can rebuild as needed.
$ cat > dune-project << EOF
> (lang dune 1.1)
> (package (name l))
> EOF
$ cat > dune << EOF
> (library
> (public_name l))
> EOF
$ cat > l.ml << EOF
> module type X = sig end
> EOF
$ detect () {
> if grep -q '>sig<' $1 ; then
> echo it is ocaml
> elif grep -q '{ ... }' $1 ; then
> echo it is reason
> else
> echo it is unknown
> fi
> }
$ dune build @doc-new
$ detect _build/default/_doc_new/html/docs/local/l/L/index.html
it is ocaml
$ ODOC_SYNTAX=re dune build @doc-new
$ detect _build/default/_doc_new/html/docs/local/l/L/index.html
it is reason

View file

@ -0,0 +1,35 @@
We create two libraries `l.one` and `l.two` with a conflicting module.
They build fine, are not co-linkable, but documentation should be able to be
built. See #1645.
$ cat > dune-project << EOF
> (lang dune 1.0)
> (package (name l))
> EOF
$ mkdir one
$ cat > one/dune << EOF
> (library
> (name l_one)
> (public_name l.one)
> (wrapped false))
> EOF
$ touch one/module.ml
$ mkdir two
$ cat > two/dune << EOF
> (library
> (name l_two)
> (public_name l.two)
> (wrapped false))
> EOF
$ touch two/module.ml
$ dune build @install
$ dune build @doc-new
File "Module":
Ambiguous lookup. Possible files: Module
Module
File "Module":
Ambiguous lookup. Possible files: Module
Module

View file

@ -0,0 +1,5 @@
(library
(name hello_world)
(public_name hello_world))
(documentation)

View file

@ -0,0 +1,3 @@
$ dune build @doc-new
$ grep Test _build/default/_doc_new/html/docs/local/hello_world/index.html > /dev/null || echo Missing

View file

@ -0,0 +1,2 @@
module Foo = Odoctest2_sublib.A

View file

@ -0,0 +1,4 @@
module Foo : module type of Odoctest2_sublib.A

View file

@ -0,0 +1,4 @@
(library
(public_name odoctest2)
(libraries odoctest2.sublib))

View file

@ -0,0 +1,9 @@
This test checks that compilation dependencies are correct
$ dune build @doc-new
There should be an expansion of `B.Foo` - ie, a directory called `Foo`:
$ ls _build/default/_doc_new/html/docs/local/odoctest2/Odoctest2/B
Foo
index.html

View file

@ -0,0 +1,4 @@
(library
(name odoctest2_sublib)
(public_name odoctest2.sublib))

View file

@ -0,0 +1,5 @@
This test checks that there is no clash when two private libraries have the same name
$ dune build --display short @doc-new 2>&1 | grep docs/test
odoc _doc_new/html/docs/test@38f98c954b37/Test
odoc _doc_new/html/docs/test@38f98c954b37/index.html

View file

@ -0,0 +1,2 @@
(lang dune 1.5)
(name ocaml-labs)

View file

@ -0,0 +1,4 @@
{0 Big title}
Let's test a link to {{!page-otherpage}Other page} and see if it works.

View file

@ -0,0 +1,4 @@
{0 The other page}
This is the other page. Congratulations!

View file

@ -0,0 +1,9 @@
Make sure that links between mld files are resolved even when there is
no library associated with the project
This test case is based on code provided by @vphantom, ocaml/dune#2007
$ dune build @doc-new
$ grep -r xref-unresolved _build/default/_doc_new/html/docs/local/odoc_page_link_bug/index.html
[1]

View file

@ -0,0 +1,27 @@
(library
(name foo)
(modules foo foo2 foo3)
(wrapped false)
(private_modules foo3)
(public_name foo))
(library
(name bar)
(public_name bar)
(modules bar))
(library
(name foo_byte)
(modules foo_byte)
(modes byte)
(public_name foo.byte))
(alias
(name foo-mld)
(deps _doc_new/index/local/foo/foo.mld)
(action (echo "%{read:_doc_new/index/local/foo/foo.mld}")))
(alias
(name bar-mld)
(deps _doc_new/index/local/bar/bar.mld)
(action (echo "%{read:_doc_new/index/local/bar/bar.mld}")))

View file

@ -0,0 +1,32 @@
This test generates documentation using odoc for a library:
$ dune build @doc-new
This test if `.odocl` files are generated
$ find _build/default/_doc_new/odoc/local -name '*.odocl' | sort -n
_build/default/_doc_new/odoc/local/bar/bar.odocl
_build/default/_doc_new/odoc/local/foo/byte/foo_byte.odocl
_build/default/_doc_new/odoc/local/foo/foo.odocl
_build/default/_doc_new/odoc/local/foo/foo2.odocl
$ ls _build/default/_doc_new/html/docs/local/
bar
foo
index.html
$ dune build @foo-mld
{0 Package foo}
{1 Sub-indexes}
- {{!page-"byte"}byte}
{1 Library foo}
This library exposes the following toplevel modules:
{!modules:foo foo2}
{1 Library foo.byte}
The entry point of this library is the module:
{!module-Foo_byte}.
$ dune build @bar-mld
{0 Package bar}
{1 Library bar}
The entry point of this library is the module:
{!module-Bar}.

View file

@ -0,0 +1 @@
this is an mld file

View file

@ -0,0 +1,16 @@
Duplicate mld's in different scope
$ dune build @doc-new --display short 2>&1 | grep page
odoc _doc_new/index/page-docs.odoc
odoc _doc_new/index/stdlib/page-stdlib.odoc
odoc _doc_new/index/local/page-local.odoc
odoc _doc_new/index/local/scope2/page-scope2.odoc
odoc _doc_new/index/local/scope1/page-scope1.odoc
odoc _doc_new/odoc/local/scope2/page-foo.odoc
odoc _doc_new/odoc/local/scope1/page-foo.odoc
odoc _doc_new/index/stdlib/page-stdlib.odocl
odoc _doc_new/index/local/page-local.odocl
odoc _doc_new/index/page-docs.odocl
odoc _doc_new/index/local/scope2/page-scope2.odocl
odoc _doc_new/odoc/local/scope2/page-foo.odocl
odoc _doc_new/index/local/scope1/page-scope1.odocl
odoc _doc_new/odoc/local/scope1/page-foo.odocl

View file

@ -0,0 +1,5 @@
(library
(name scope1)
(public_name scope1))
(documentation)

View file

@ -0,0 +1,5 @@
(library
(name scope2)
(public_name scope2))
(documentation)

View file

@ -0,0 +1,5 @@
(library
(name root_lib1)
(public_name root.lib1))
(documentation)

View file

@ -0,0 +1,5 @@
(library
(name root_lib2)
(public_name root.lib2))
(documentation)

View file

@ -0,0 +1,6 @@
Duplicate mld's in the same scope
$ dune build @doc-new
Error: Package root has two mld's with the same basename
_build/default/lib1/test.mld, _build/default/lib2/test.mld
-> required by alias doc-new
[1]

View file

@ -0,0 +1,2 @@
(library
(public_name foo))

View file

@ -0,0 +1,18 @@
This test generates documentation for non-hidden modules only for a library:
$ dune build @doc-new
Hidden modules should be compiled
$ find _build/default/_doc_new/odoc/local/foo -name '*.odoc' | sort -n
_build/default/_doc_new/odoc/local/foo/foo.odoc
_build/default/_doc_new/odoc/local/foo/foo__.odoc
_build/default/_doc_new/odoc/local/foo/foo__Bar.odoc
Hidden modules should not be linked
$ find _build/default/_doc_new/odoc/local/foo -name '*.odocl' | sort -n
_build/default/_doc_new/odoc/local/foo/foo.odocl
We don't expect html for hidden modules
$ find _build/default/_doc_new/html/docs/local/foo -name '*.html' | sort -n
_build/default/_doc_new/html/docs/local/foo/Foo/index.html
_build/default/_doc_new/html/docs/local/foo/index.html

View file

@ -0,0 +1 @@
module type S = module type of B.A

View file

@ -0,0 +1,4 @@
(library
(public_name odoctest3)
(libraries odoctest3.sublib2))

View file

@ -0,0 +1,9 @@
This test checks that compilation dependencies are correct
$ dune build @doc-new
There should be an expansion of S:
$ ls _build/default/_doc_new/html/docs/local/odoctest3/Odoctest3/C/
index.html
module-type-S

Some files were not shown because too many files have changed in this diff Show more