diff options
Diffstat (limited to 'ocaml-binary-annot/testsuite/tests/tool-ocamldoc')
8 files changed, 224 insertions, 0 deletions
diff --git a/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/Makefile b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/Makefile new file mode 100644 index 0000000000..5e7398ba7d --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/Makefile @@ -0,0 +1,17 @@ +CUSTOM_MODULE=odoc_test +ADD_COMPFLAGS=-I +ocamldoc + +run: $(CUSTOM_MODULE).cmo + @for file in t*.ml; do \ + printf " ... testing '$$file'"; \ + $(OCAMLDOC) -g $(CUSTOM_MODULE).cmo -o `basename $$file ml`result $$file; \ + diff -q `basename $$file ml`reference `basename $$file ml`result > /dev/null && echo " => passed" || (echo " => failed" && exit 1); \ + done; + @$(OCAMLDOC) -html t*.ml 2>&1 | grep -v test_types_display || true + @$(OCAMLDOC) -latex t*.ml 2>&1 | grep -v test_types_display || true + + +clean: defaultclean + @rm -f *.result *.html *.tex *.log *.out *.sty *.toc *.css *.aux + +include ../../makefiles/Makefile.common diff --git a/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/odoc_test.ml b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/odoc_test.ml new file mode 100644 index 0000000000..8bd1127011 --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/odoc_test.ml @@ -0,0 +1,112 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2004 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_test.ml 6127 2004-02-20 16:28:27Z guesdon $ *) + +(** Custom generator to perform test on ocamldoc. *) + +open Odoc_info +open Odoc_info.Module +open Odoc_info.Type + +type test_kind = + Types_display + +let p = Format.fprintf + +class string_gen = + object(self) + inherit Odoc_info.Scan.scanner + + val mutable test_kinds = [] + val mutable fmt = Format.str_formatter + + method must_display_types = List.mem Types_display test_kinds + + method set_test_kinds_from_module m = + test_kinds <- List.fold_left + (fun acc (s, _) -> + match s with + "test_types_display" -> Types_display :: acc + | _ -> acc + ) + [] + ( + match m.m_info with + None -> [] + | Some i -> i.i_custom + ) + method! scan_type t = + match test_kinds with + [] -> () + | _ -> + p fmt "# type %s:\n" t.ty_name; + if self#must_display_types then + ( + p fmt "# manifest (Odoc_info.string_of_type_expr):\n<[%s]>\n" + (match t.ty_manifest with + None -> "None" + | Some e -> Odoc_info.string_of_type_expr e + ); + ); + + + method! scan_module_pre m = + p fmt "#\n# module %s:\n" m.m_name ; + if self#must_display_types then + ( + p fmt "# Odoc_info.string_of_module_type:\n<[%s]>\n" + (Odoc_info.string_of_module_type m.m_type); + p fmt "# Odoc_info.string_of_module_type ~complete: true :\n<[%s]>\n" + (Odoc_info.string_of_module_type ~complete: true m.m_type); + ); + true + + method! scan_module_type_pre m = + p fmt "#\n# module type %s:\n" m.mt_name ; + if self#must_display_types then + ( + p fmt "# Odoc_info.string_of_module_type:\n<[%s]>\n" + (match m.mt_type with + None -> "None" + | Some t -> Odoc_info.string_of_module_type t + ); + p fmt "# Odoc_info.string_of_module_type ~complete: true :\n<[%s]>\n" + (match m.mt_type with + None -> "None" + | Some t -> Odoc_info.string_of_module_type ~complete: true t + ); + ); + true + + method generate (module_list: Odoc_info.Module.t_module list) = + let oc = open_out !Odoc_info.Args.out_file in + fmt <- Format.formatter_of_out_channel oc; + ( + try + List.iter + (fun m -> + self#set_test_kinds_from_module m; + self#scan_module_list [m]; + ) + module_list + with + e -> + prerr_endline (Printexc.to_string e) + ); + Format.pp_print_flush fmt (); + close_out oc + end + + +let my_generator = new string_gen +let _ = Odoc_info.Args.set_doc_generator + (Some (my_generator :> Odoc_info.Args.doc_generator)) diff --git a/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t01.ml b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t01.ml new file mode 100644 index 0000000000..6caf3d7afc --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t01.ml @@ -0,0 +1,19 @@ +(** Testing display of types. + + @test_types_display + *) + +let x = 1 + + +module M = struct + let y = 2 + +end + +module type MT = sig + type t = string -> int -> string -> (string * string * string) -> + (string * string * string) -> + (string * string * string) -> unit + val y : int +end diff --git a/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t01.reference b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t01.reference new file mode 100644 index 0000000000..72345ffecd --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t01.reference @@ -0,0 +1,33 @@ +# +# module T01: +# Odoc_info.string_of_module_type: +<[sig end]> +# Odoc_info.string_of_module_type ~complete: true : +<[sig end]> +# +# module T01.M: +# Odoc_info.string_of_module_type: +<[sig end]> +# Odoc_info.string_of_module_type ~complete: true : +<[sig val y : int end]> +# +# module type T01.MT: +# Odoc_info.string_of_module_type: +<[sig end]> +# Odoc_info.string_of_module_type ~complete: true : +<[sig + type t = + string -> + int -> + string -> + string * string * string -> + string * string * string -> string * string * string -> unit + val y : int +end]> +# type T01.MT.t: +# manifest (Odoc_info.string_of_type_expr): +<[string -> + int -> + string -> + string * string * string -> + string * string * string -> string * string * string -> unit]> diff --git a/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t02.ml b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t02.ml new file mode 100644 index 0000000000..d7c9742134 --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t02.ml @@ -0,0 +1,10 @@ +module Foo = struct type u type t = int let x = 1 end;; +module type TFoo = module type of Foo;; + +module type TBar = TFoo with type u := float;; + +module type Gee = + sig + module M : module type of Foo + include module type of Foo + end diff --git a/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t02.reference b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t02.reference new file mode 100644 index 0000000000..f1e7de43dd --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t02.reference @@ -0,0 +1,12 @@ +# +# module T02: +# +# module T02.Foo: +# +# module type T02.TFoo: +# +# module type T02.TBar: +# +# module type T02.Gee: +# +# module T02.Gee.M: diff --git a/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t03.ml b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t03.ml new file mode 100644 index 0000000000..43f1857d56 --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t03.ml @@ -0,0 +1,7 @@ +module Foo = struct type t = int let x = 1 end;; +module type MT = module type of Foo;; +module Bar = struct type t = int let x = 2 end;; + +module type MT2 = sig type t val x : t end;; +module type Gee = MT2 with type t = float ;; +module T = (val (if true then (module Foo:MT2 with type t = int) else (module Bar: MT2 with type t = int)) : MT2 with type t = int);;
\ No newline at end of file diff --git a/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t03.reference b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t03.reference new file mode 100644 index 0000000000..174e21991c --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/tool-ocamldoc/t03.reference @@ -0,0 +1,14 @@ +# +# module T03: +# +# module T03.Foo: +# +# module type T03.MT: +# +# module T03.Bar: +# +# module type T03.MT2: +# +# module type T03.Gee: +# +# module T03.T: |
