Merge pull request #352 from rgrinberg/odoc-tests

Odoc tests
This commit is contained in:
Rudi Grinberg 2017-12-11 14:50:29 +08:00 committed by GitHub
commit e373e67c12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 92 additions and 3 deletions

View File

@ -46,7 +46,7 @@ case "$TARGET" in
rm -rf ~/.opam
opam init --yes
eval $(opam config env)
opam install reason menhir ocaml-migrate-parsetree js_of_ocaml-ppx --yes
opam install odoc reason menhir ocaml-migrate-parsetree js_of_ocaml-ppx --yes
opam remove jbuilder `opam list --depends-on jbuilder --installed --short` --yes
fi
cp -a ~/.opam ~/.opam-start
@ -73,7 +73,7 @@ case "$TARGET" in
opam list
echo "version: \"1.0+dev$DATE\"" >> jbuilder.opam
opam pin add jbuilder . --no-action --yes
opam install reason ocaml-migrate-parsetree js_of_ocaml-ppx --yes
opam install odoc reason ocaml-migrate-parsetree js_of_ocaml-ppx --yes
echo -en "travis_fold:end:opam.deps\r"
fi
echo -en "travis_fold:start:jbuilder.bootstrap\r"

View File

@ -20,7 +20,32 @@ rule file = parse
{
let () =
Test_common.run_expect_test Sys.argv.(1) ~f:(fun file_contents lexbuf ->
let ocaml_version = ref None in
let skip_versions = ref [] in
let expect_test = ref None in
let usage = sprintf "%s [OPTIONS]" (Filename.basename Sys.executable_name) in
let anon s =
match !expect_test with
| None -> expect_test := Some s
| Some _ -> raise (Arg.Bad "test must only be given once") in
Arg.parse
[ "-ocamlv"
, Arg.String (fun s -> ocaml_version := Some s)
, "Version of ocaml being used"
; "-skip-versions"
, Arg.String (fun s -> skip_versions := String.split s ~on:',')
, "Comma separated versions of ocaml where to skip test"
] anon usage;
let expect_test =
match !expect_test with
| None -> raise (Arg.Bad "expect test file must be passed")
| Some p -> p in
begin match !ocaml_version, !skip_versions with
| None, [] -> ()
| None, _::_ -> raise (Arg.Bad "provide -ocaml along with -skip-versions")
| Some v, skip -> if List.mem v ~set:skip then exit 0
end;
Test_common.run_expect_test expect_test ~f:(fun file_contents lexbuf ->
let items = file lexbuf in
let temp_file = Filename.temp_file "jbuilder-test" ".output" in
at_exit (fun () -> Sys.remove temp_file);

View File

@ -113,3 +113,11 @@
(action
(chdir test-cases/reason
(setenv JBUILDER ${bin:jbuilder} (run ${exe:cram.exe} run.t))))))
(alias
((name runtest)
(deps ((files_recursively_in test-cases/odoc)))
(action
(chdir test-cases/odoc
(setenv JBUILDER ${bin:jbuilder} (run ${exe:cram.exe} -ocamlv ${ocaml_version} -skip-versions 4.02.3 run.t))))))

View File

@ -0,0 +1,24 @@
(jbuild_version 1)
(library
((name foo)
(modules (foo))
(wrapped false)
(public_name foo)))
(library
((name foo_byte)
(modules (foo_byte))
(modes (byte))
(public_name foo.byte)))
(executables
((names (bar))
(modules (bar))
(public_names (bar))
(libraries (foo))))
(alias
((name runtest)
(deps (_doc/index.html))
(action (echo "${read:_doc/index.html}"))))

View File

@ -0,0 +1,32 @@
$ $JBUILDER build @doc -j1 --root .
ocamldep foo_byte.depends.ocamldep-output
ocamldep foo_byte.dependsi.ocamldep-output
ocamldep foo.depends.ocamldep-output
ocamldep foo.dependsi.ocamldep-output
odoc _doc/odoc.css
ocamlc foo_byte.{cmi,cmo,cmt}
ocamlc foo.{cmi,cmo,cmt}
odoc foo_byte.odoc
odoc foo.odoc
odoc _doc/foo.byte/index.html
odoc _doc/foo.byte/Foo_byte/.jbuilder-keep,_doc/foo.byte/Foo_byte/index.html
odoc _doc/foo/index.html
odoc _doc/foo/Foo/.jbuilder-keep,_doc/foo/Foo/index.html
$ $JBUILDER runtest -j1 --root .
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>index</title>
<link rel="stylesheet" href="./odoc.css"/>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
</head>
<body>
<div class="by-name">
<h2>OCaml package documentation</h2>
<ol>
<li><a href="foo/index.html">foo</a></li>
<li><a href="foo.byte/index.html">foo.byte</a></li>
</ol>
</body>
</html>