From 1eb862b290e02d107c8bab8ed4ee8819bdf67dee Mon Sep 17 00:00:00 2001 From: zazedd Date: Tue, 13 Jun 2023 23:50:44 +0100 Subject: [PATCH 01/14] basic new latex type --- lib/syntax.ml | 5 ++++- lib/syntax.mli | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/syntax.ml b/lib/syntax.ml index f24d397c7..176159413 100644 --- a/lib/syntax.ml +++ b/lib/syntax.ml @@ -1,7 +1,8 @@ -type t = Markdown | Cram | Mli | Mld +type t = Markdown | Latex | Cram | Mli | Mld let pp fs = function | Markdown -> Fmt.string fs "markdown" + | Latex -> Fmt.string fs "latex" | Cram -> Fmt.string fs "cram" | Mli -> Fmt.string fs "mli" | Mld -> Fmt.string fs "mld" @@ -12,12 +13,14 @@ let infer ~file = match Filename.extension file with | ".t" -> Some Cram | ".md" -> Some Markdown + | ".tex" -> Some Latex | ".mli" -> Some Mli | ".mld" -> Some Mld | _ -> None let of_string = function | "markdown" | "normal" -> Some Markdown + | "latex" -> Some Latex | "cram" -> Some Cram | "mli" -> Some Mli | "mld" -> Some Mld diff --git a/lib/syntax.mli b/lib/syntax.mli index 70732d13c..f885104e4 100644 --- a/lib/syntax.mli +++ b/lib/syntax.mli @@ -1,4 +1,4 @@ -type t = Markdown | Cram | Mli | Mld +type t = Markdown | Latex | Cram | Mli | Mld val pp : Format.formatter -> t -> unit val equal : t -> t -> bool From 48dd592d3c0f36c68c6e27d5fd1a03ab4729e772 Mon Sep 17 00:00:00 2001 From: zazedd Date: Wed, 14 Jun 2023 00:11:46 +0100 Subject: [PATCH 02/14] fixed pattern matching, waiting for latex lexer --- lib/block.ml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/block.ml b/lib/block.ml index 46ae3ad55..5f3aedaaf 100644 --- a/lib/block.ml +++ b/lib/block.ml @@ -173,6 +173,7 @@ let pp_footer ?syntax ppf _ = match syntax with | Some Syntax.Mli | Some Syntax.Mld -> Fmt.string ppf "]}" | Some Syntax.Cram -> Fmt.string ppf "\n" + | Some Syntax.Latex -> Fmt.string ppf "\\end{ocaml}\n" | Some Syntax.Markdown | None -> Fmt.string ppf "```\n" let pp_legacy_labels ppf = function @@ -192,6 +193,7 @@ let pp_labels ?syntax ppf labels = | [ Non_det (Some Nd_command) ] -> Fmt.pf ppf "<-- non-deterministic command\n" | _ -> failwith "cannot happen: checked during parsing") + | Some Syntax.Latex -> () | Some Syntax.Markdown | None -> ( match labels with | [] -> () @@ -217,6 +219,15 @@ let pp_header ?syntax ppf t = in Fmt.pf ppf "{%a%a[" pp_lang_header lang_headers pp_labels other_labels | Some Syntax.Cram -> pp_labels ?syntax ppf t.labels + | Some Syntax.Latex -> + if t.legacy_labels then + Fmt.pf ppf "\\begin{%a%a}" + Fmt.(option Header.pp) + (header t) pp_legacy_labels t.labels + else + Fmt.pf ppf "%a\\end{%a}" (pp_labels ?syntax) t.labels + Fmt.(option Header.pp) + (header t) | Some Syntax.Markdown | None -> if t.legacy_labels then Fmt.pf ppf "```%a%a" From 4994a0c6ae300e3c4d80b86f4129ea55afb6a533 Mon Sep 17 00:00:00 2001 From: ProgramingIsTheFuture Date: Wed, 14 Jun 2023 00:12:10 +0100 Subject: [PATCH 03/14] LaTeX lexer --- lib/dune | 2 ++ lib/lexer_tex.mll | 88 +++++++++++++++++++++++++++++++++++++++++++++++ lib/mdx.ml | 1 + lib/mdx.mli | 1 + 4 files changed, 92 insertions(+) create mode 100644 lib/lexer_tex.mll diff --git a/lib/dune b/lib/dune index f1c5fd4b2..e0c022509 100644 --- a/lib/dune +++ b/lib/dune @@ -21,3 +21,5 @@ (ocamllex lexer_cram) (ocamllex lexer_top) + +(ocamllex lexer_tex) diff --git a/lib/lexer_tex.mll b/lib/lexer_tex.mll new file mode 100644 index 000000000..a6117a865 --- /dev/null +++ b/lib/lexer_tex.mll @@ -0,0 +1,88 @@ +{ +open Astring + +type token = [ `Block of Block.Raw.t | `Section of int * string | `Text of string ] + +let newline lexbuf = Lexing.new_line lexbuf + +let loc ~start ~end_ = + Location.{loc_start = start; loc_end = end_; loc_ghost = false} +} + +let eol = '\n' | eof +let ws = ' ' | '\t' + +rule text section = parse + | eof { [] } + | ("#"+ as n) " " ([^'\n']* as str) eol + { let section = (String.length n, str) in + newline lexbuf; + `Section section :: text (Some section) lexbuf } + | ( "%" ws* "$MDX" ws* ([^' ' '\n']* as label_cmt) ws* eol? )? + "\begin{" ([^' ' '\n']* as header) ws* ([^'\n']* as legacy_labels) "}" eol + { let start = Lexing.lexeme_start_p lexbuf in + newline lexbuf; + (match label_cmt with + | Some _ -> newline lexbuf + | None -> ()); + let contents = block lexbuf in + (* we assume the multi-line block starts with an "" + TODO: tie this to the regex match *) + let contents = "" :: contents in + let errors = + match error_block lexbuf with + | exception _ -> [] + | e -> + List.map (fun x -> + match String.trim x with + | "..." -> `Ellipsis + | _ -> `Output x) e + in + let end_ = Lexing.lexeme_start_p lexbuf in + let loc = loc ~start ~end_ in + let block = + Block.Raw.make ~loc ~section ~header ~contents ~label_cmt + ~legacy_labels ~errors + in + `Block block :: text section lexbuf } + | "%" ws* "$MDX" ws* ([^' ' '\n']* as labels) ws* eol + { let loc = Location.curr lexbuf in + newline lexbuf; + let block = Block.Raw.make_include ~loc ~section ~labels in + `Block block :: text section lexbuf } + | ([^'\n']* as str) eol + { newline lexbuf; + let str = String.append str "\n" in + `Text str :: text section lexbuf } + +and block = parse + | eof | ws* as end_pad "\end" ws* eol + { newline lexbuf; + [end_pad] } + | ([^'\n']* as str) eol + { newline lexbuf; + str :: block lexbuf } + +and error_block = parse + | "```mdx-error" ws* eol { newline lexbuf; block lexbuf } + +and cram_block = parse + | eof { false, [] } + | eol { newline lexbuf; true, [] } + | (" " as ws) ([^'\n'] * as str) eol + { let requires_empty_line, lst = cram_block lexbuf in + newline lexbuf; + requires_empty_line, (String.append ws str) :: lst } + +{ + let latex_token lexbuf = + try Ok (text None lexbuf) + with + | exn -> + let loc = Location.curr lexbuf in + let msg = + Format.asprintf "%a: %s" Stable_printer.Location.pp loc + (Printexc.to_string exn) + in + Util.Result.errorf "%s" msg +} diff --git a/lib/mdx.ml b/lib/mdx.ml index 6ca670631..15fd27281 100644 --- a/lib/mdx.ml +++ b/lib/mdx.ml @@ -17,6 +17,7 @@ let src = Logs.Src.create "ocaml-mdx" module Lexer_mdx = Lexer_mdx +module Lexer_tex = Lexer_tex module Log = (val Logs.src_log src : Logs.LOG) module Output = Output module Cram = Cram diff --git a/lib/mdx.mli b/lib/mdx.mli index 381379b44..fad13924f 100644 --- a/lib/mdx.mli +++ b/lib/mdx.mli @@ -24,6 +24,7 @@ {{!Output}outputs}. *) module Lexer_mdx = Lexer_mdx +module Lexer_tex = Lexer_tex module Output = Output module Cram = Cram module Deprecated = Deprecated From 6df3d760db23c6184fa4ea133abfec2946624238 Mon Sep 17 00:00:00 2001 From: ProgramingIsTheFuture Date: Wed, 14 Jun 2023 00:13:18 +0100 Subject: [PATCH 04/14] \end{ocaml} --- lib/lexer_tex.mll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lexer_tex.mll b/lib/lexer_tex.mll index a6117a865..233419b08 100644 --- a/lib/lexer_tex.mll +++ b/lib/lexer_tex.mll @@ -56,7 +56,7 @@ rule text section = parse `Text str :: text section lexbuf } and block = parse - | eof | ws* as end_pad "\end" ws* eol + | eof | ws* as end_pad "\end{ocaml}" ws* eol { newline lexbuf; [end_pad] } | ([^'\n']* as str) eol From ae79aafb17faa434179ce55a0f46ff9ff9c1f330 Mon Sep 17 00:00:00 2001 From: ProgramingIsTheFuture Date: Wed, 14 Jun 2023 00:21:55 +0100 Subject: [PATCH 05/14] Mdx supports Latex --- lib/lexer_tex.mli | 4 ++++ lib/lexer_tex.mll | 12 ++---------- lib/mdx.ml | 4 +++- 3 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 lib/lexer_tex.mli diff --git a/lib/lexer_tex.mli b/lib/lexer_tex.mli new file mode 100644 index 000000000..d0a0ca4d3 --- /dev/null +++ b/lib/lexer_tex.mli @@ -0,0 +1,4 @@ +type token = + [ `Block of Block.Raw.t | `Section of int * string | `Text of string ] + +val latex_token : Lexing.lexbuf -> (token list, [ `Msg of string ]) result diff --git a/lib/lexer_tex.mll b/lib/lexer_tex.mll index 233419b08..27029dc16 100644 --- a/lib/lexer_tex.mll +++ b/lib/lexer_tex.mll @@ -19,7 +19,7 @@ rule text section = parse newline lexbuf; `Section section :: text (Some section) lexbuf } | ( "%" ws* "$MDX" ws* ([^' ' '\n']* as label_cmt) ws* eol? )? - "\begin{" ([^' ' '\n']* as header) ws* ([^'\n']* as legacy_labels) "}" eol + "\\begin{" ([^' ' '\n']* as header) ws* ([^'\n']* as legacy_labels) "}" eol { let start = Lexing.lexeme_start_p lexbuf in newline lexbuf; (match label_cmt with @@ -56,7 +56,7 @@ rule text section = parse `Text str :: text section lexbuf } and block = parse - | eof | ws* as end_pad "\end{ocaml}" ws* eol + | eof | ws* as end_pad "\\end{ocaml}" ws* eol { newline lexbuf; [end_pad] } | ([^'\n']* as str) eol @@ -66,14 +66,6 @@ and block = parse and error_block = parse | "```mdx-error" ws* eol { newline lexbuf; block lexbuf } -and cram_block = parse - | eof { false, [] } - | eol { newline lexbuf; true, [] } - | (" " as ws) ([^'\n'] * as str) eol - { let requires_empty_line, lst = cram_block lexbuf in - newline lexbuf; - requires_empty_line, (String.append ws str) :: lst } - { let latex_token lexbuf = try Ok (text None lexbuf) diff --git a/lib/mdx.ml b/lib/mdx.ml index 15fd27281..1fc80bbb7 100644 --- a/lib/mdx.ml +++ b/lib/mdx.ml @@ -73,6 +73,8 @@ let parse_lexbuf syntax Misc.{ string; lexbuf } = match syntax with | Syntax.Mli -> Mli_parser.parse_mli string | Syntax.Mld -> Mli_parser.parse_mld string + | Latex -> + Util.Result.to_error_list @@ Lexer_tex.latex_token lexbuf >>= parse | Markdown -> Util.Result.to_error_list @@ Lexer_mdx.markdown_token lexbuf >>= parse | Cram -> Util.Result.to_error_list @@ Lexer_mdx.cram_token lexbuf >>= parse @@ -83,7 +85,7 @@ let of_string syntax s = match syntax with | Syntax.Mli -> Mli_parser.parse_mli s | Syntax.Mld -> Mli_parser.parse_mld s - | Syntax.Markdown | Syntax.Cram -> + | Syntax.Latex | Syntax.Markdown | Syntax.Cram -> Misc.{ lexbuf = Lexing.from_string s; string = s } |> parse_lexbuf syntax let dump_line ppf (l : line) = From cc5d885259006fef2346b4777cea5ee2299cf347 Mon Sep 17 00:00:00 2001 From: ProgramingIsTheFuture Date: Wed, 14 Jun 2023 01:15:43 +0100 Subject: [PATCH 06/14] legacy_labels with square brackets --- lib/block.ml | 21 ++++++++++++++------- lib/lexer_tex.mll | 6 +++--- test/lib/test_syntax.ml | 1 + 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/block.ml b/lib/block.ml index 5f3aedaaf..6d9c0e318 100644 --- a/lib/block.ml +++ b/lib/block.ml @@ -159,14 +159,20 @@ let rec error_padding = function let xs = error_padding xs in x :: xs -let pp_errors ppf t = +let pp_errors ?syntax ppf t = match t.value with | OCaml { errors = []; _ } -> () | OCaml { errors; _ } -> let errors = error_padding errors in - Fmt.pf ppf "```mdx-error\n%a\n```\n" - Fmt.(list ~sep:(any "\n") Output.pp) - errors + (match syntax with + | Some Syntax.Latex -> + Fmt.pf ppf "\\begin{mdx-error}\n%a\n\\end{mdx-error}\n" + Fmt.(list ~sep:(any "\n") Output.pp) + errors + | _ -> + Fmt.pf ppf "```mdx-error\n%a\n```\n" + Fmt.(list ~sep:(any "\n") Output.pp) + errors) | _ -> () let pp_footer ?syntax ppf _ = @@ -221,9 +227,10 @@ let pp_header ?syntax ppf t = | Some Syntax.Cram -> pp_labels ?syntax ppf t.labels | Some Syntax.Latex -> if t.legacy_labels then - Fmt.pf ppf "\\begin{%a%a}" + let legacy_labels = Fmt.str " %%%a" pp_legacy_labels t.labels in + Fmt.pf ppf "\\begin{%a}%s" Fmt.(option Header.pp) - (header t) pp_legacy_labels t.labels + (header t) (if String.length legacy_labels > 3 then legacy_labels else "") else Fmt.pf ppf "%a\\end{%a}" (pp_labels ?syntax) t.labels Fmt.(option Header.pp) @@ -242,7 +249,7 @@ let pp ?syntax ppf b = pp_header ?syntax ppf b; pp_contents ?syntax ppf b; pp_footer ?syntax ppf b; - pp_errors ppf b + pp_errors ?syntax ppf b let directory t = t.dir let file t = match t.value with Include t -> Some t.file_included | _ -> None diff --git a/lib/lexer_tex.mll b/lib/lexer_tex.mll index 27029dc16..a2e0f0584 100644 --- a/lib/lexer_tex.mll +++ b/lib/lexer_tex.mll @@ -19,7 +19,7 @@ rule text section = parse newline lexbuf; `Section section :: text (Some section) lexbuf } | ( "%" ws* "$MDX" ws* ([^' ' '\n']* as label_cmt) ws* eol? )? - "\\begin{" ([^' ' '\n']* as header) ws* ([^'\n']* as legacy_labels) "}" eol + "\\begin{" ([^' ' '\n']* as header) "}" ("[" ([^ '\n']* as legacy_labels) "]")? eol { let start = Lexing.lexeme_start_p lexbuf in newline lexbuf; (match label_cmt with @@ -42,7 +42,7 @@ rule text section = parse let loc = loc ~start ~end_ in let block = Block.Raw.make ~loc ~section ~header ~contents ~label_cmt - ~legacy_labels ~errors + ~legacy_labels:(match legacy_labels with Some v -> v | None -> "") ~errors in `Block block :: text section lexbuf } | "%" ws* "$MDX" ws* ([^' ' '\n']* as labels) ws* eol @@ -64,7 +64,7 @@ and block = parse str :: block lexbuf } and error_block = parse - | "```mdx-error" ws* eol { newline lexbuf; block lexbuf } + | "\\begin{ocaml}" ws* eol { newline lexbuf; block lexbuf } { let latex_token lexbuf = diff --git a/test/lib/test_syntax.ml b/test/lib/test_syntax.ml index e12d8f01f..dc7693950 100644 --- a/test/lib/test_syntax.ml +++ b/test/lib/test_syntax.ml @@ -16,6 +16,7 @@ let test_infer = [ make_test ~file:"" ~expected:None (); make_test ~file:"test.md" ~expected:(Some Markdown) (); + make_test ~file:"test.tex" ~expected:(Some Latex) (); make_test ~file:"test.t" ~expected:(Some Cram) (); make_test ~file:"test.ml" ~expected:None (); make_test ~file:"test.mli" ~expected:(Some Mli) (); From 01d4b6e6f1e6674bc098c48d9488aebcefd269b9 Mon Sep 17 00:00:00 2001 From: zazedd Date: Wed, 19 Jul 2023 15:29:39 +0100 Subject: [PATCH 07/14] removed legacy labels, introduced latex arguments, needs a bug fix --- lib/block.ml | 37 +++++++++++++++++++------------------ lib/block.mli | 3 +++ lib/lexer_mdx.mll | 3 ++- lib/lexer_tex.mll | 4 ++-- lib/mli_parser.ml | 2 +- test/lib/test_block.ml | 2 +- test/lib/test_dep.ml | 2 +- 7 files changed, 29 insertions(+), 24 deletions(-) diff --git a/lib/block.ml b/lib/block.ml index 6d9c0e318..1f19db047 100644 --- a/lib/block.ml +++ b/lib/block.ml @@ -65,12 +65,13 @@ module Raw = struct header : string; contents : string list; label_cmt : string option; + latex_arguments : string option; legacy_labels : string; errors : Output.t list; } - let make ~loc ~section ~header ~contents ~label_cmt ~legacy_labels ~errors = - Any { loc; section; header; contents; label_cmt; legacy_labels; errors } + let make ~loc ~section ~header ~contents ~label_cmt ~legacy_labels ~latex_arguments ~errors = + Any { loc; section; header; contents; label_cmt; legacy_labels; latex_arguments; errors } let make_include ~loc ~section ~labels = Include { loc; section; labels } end @@ -108,6 +109,7 @@ type t = { dir : string option; labels : Label.t list; legacy_labels : bool; + latex_arguments : string option; contents : string list; skip : bool; version_enabled : bool; @@ -162,9 +164,9 @@ let rec error_padding = function let pp_errors ?syntax ppf t = match t.value with | OCaml { errors = []; _ } -> () - | OCaml { errors; _ } -> + | OCaml { errors; _ } -> ( let errors = error_padding errors in - (match syntax with + match syntax with | Some Syntax.Latex -> Fmt.pf ppf "\\begin{mdx-error}\n%a\n\\end{mdx-error}\n" Fmt.(list ~sep:(any "\n") Output.pp) @@ -199,7 +201,10 @@ let pp_labels ?syntax ppf labels = | [ Non_det (Some Nd_command) ] -> Fmt.pf ppf "<-- non-deterministic command\n" | _ -> failwith "cannot happen: checked during parsing") - | Some Syntax.Latex -> () + | Some Syntax.Latex -> ( + match labels with + | [] -> () + | l -> Fmt.pf ppf "%% $MDX %a \n" Fmt.(list ~sep:(any ",") Label.pp) l) | Some Syntax.Markdown | None -> ( match labels with | [] -> () @@ -226,15 +231,10 @@ let pp_header ?syntax ppf t = Fmt.pf ppf "{%a%a[" pp_lang_header lang_headers pp_labels other_labels | Some Syntax.Cram -> pp_labels ?syntax ppf t.labels | Some Syntax.Latex -> - if t.legacy_labels then - let legacy_labels = Fmt.str " %%%a" pp_legacy_labels t.labels in - Fmt.pf ppf "\\begin{%a}%s" - Fmt.(option Header.pp) - (header t) (if String.length legacy_labels > 3 then legacy_labels else "") - else - Fmt.pf ppf "%a\\end{%a}" (pp_labels ?syntax) t.labels - Fmt.(option Header.pp) - (header t) + (* LaTeX does not have any legacy labels *) + Fmt.pf ppf "%a\\begin{%a}" (pp_labels ?syntax) t.labels + Fmt.(option Header.pp) + (header t) | Some Syntax.Markdown | None -> if t.legacy_labels then Fmt.pf ppf "```%a%a" @@ -420,7 +420,7 @@ let infer_block ~loc ~config ~header ~contents ~errors = let+ () = check_no_errors ~loc errors in Raw { header }) -let mk ~loc ~section ~labels ~legacy_labels ~header ~contents ~errors = +let mk ~loc ~section ~labels ~legacy_labels ~latex_arguments ~header ~contents ~errors = let block_kind = get_label (function Block_kind x -> Some x | _ -> None) labels in @@ -440,6 +440,7 @@ let mk ~loc ~section ~labels ~legacy_labels ~header ~contents ~errors = dir = config.dir; labels; legacy_labels; + latex_arguments; contents; skip = config.skip; version_enabled; @@ -452,7 +453,7 @@ let mk_include ~loc ~section ~labels = match get_label (function File x -> Some x | _ -> None) labels with | Some file_inc -> let header = Header.infer_from_file file_inc in - mk ~loc ~section ~labels ~legacy_labels:false ~header ~contents:[] + mk ~loc ~section ~latex_arguments:None ~labels ~legacy_labels:false ~header ~contents:[] ~errors:[] | None -> label_required ~loc ~label:"file" ~kind:"include" @@ -471,14 +472,14 @@ let from_raw raw = | Raw.Include { loc; section; labels } -> let* labels = locate_errors ~loc (Label.of_string labels) in Util.Result.to_error_list @@ mk_include ~loc ~section ~labels - | Raw.Any { loc; section; header; contents; label_cmt; legacy_labels; errors } + | Raw.Any { loc; section; header; contents; label_cmt; latex_arguments; legacy_labels; errors } -> let header = Header.of_string header in let* labels, legacy_labels = locate_errors ~loc (parse_labels ~label_cmt ~legacy_labels) in Util.Result.to_error_list - @@ mk ~loc ~section ~header ~contents ~labels ~legacy_labels ~errors + @@ mk ~loc ~section ~header ~contents ~labels ~latex_arguments ~legacy_labels ~errors let is_active ?section:s t = let active = diff --git a/lib/block.mli b/lib/block.mli index e4334997e..1cfe42875 100644 --- a/lib/block.mli +++ b/lib/block.mli @@ -84,6 +84,7 @@ module Raw : sig contents:string list -> label_cmt:string option -> legacy_labels:string -> + latex_arguments:string option -> errors:Output.t list -> t @@ -97,6 +98,7 @@ type t = { dir : string option; labels : Label.t list; legacy_labels : bool; + latex_arguments:string option; contents : string list; skip : bool; version_enabled : bool; @@ -112,6 +114,7 @@ val mk : section:section option -> labels:Label.t list -> legacy_labels:bool -> + latex_arguments:string option -> header:Header.t option -> contents:string list -> errors:Output.t list -> diff --git a/lib/lexer_mdx.mll b/lib/lexer_mdx.mll index 683abc818..1b763ee59 100644 --- a/lib/lexer_mdx.mll +++ b/lib/lexer_mdx.mll @@ -40,9 +40,10 @@ rule text section = parse in let end_ = Lexing.lexeme_start_p lexbuf in let loc = loc ~start ~end_ in + let latex_arguments = None in let block = Block.Raw.make ~loc ~section ~header ~contents ~label_cmt - ~legacy_labels ~errors + ~legacy_labels ~latex_arguments ~errors in `Block block :: text section lexbuf } | "" ws* eol diff --git a/lib/lexer_tex.mll b/lib/lexer_tex.mll index a2e0f0584..c818b8da8 100644 --- a/lib/lexer_tex.mll +++ b/lib/lexer_tex.mll @@ -19,7 +19,7 @@ rule text section = parse newline lexbuf; `Section section :: text (Some section) lexbuf } | ( "%" ws* "$MDX" ws* ([^' ' '\n']* as label_cmt) ws* eol? )? - "\\begin{" ([^' ' '\n']* as header) "}" ("[" ([^ '\n']* as legacy_labels) "]")? eol + "\\begin{" ([^' ' '\n']* as header) "}" ("[" [^'\n']* "]" as latex_arguments)? eol { let start = Lexing.lexeme_start_p lexbuf in newline lexbuf; (match label_cmt with @@ -42,7 +42,7 @@ rule text section = parse let loc = loc ~start ~end_ in let block = Block.Raw.make ~loc ~section ~header ~contents ~label_cmt - ~legacy_labels:(match legacy_labels with Some v -> v | None -> "") ~errors + ~legacy_labels:"" ~latex_arguments ~errors in `Block block :: text section lexbuf } | "%" ws* "$MDX" ws* ([^' ' '\n']* as labels) ws* eol diff --git a/lib/mli_parser.ml b/lib/mli_parser.ml index ed0b7e95d..da4ac8460 100644 --- a/lib/mli_parser.ml +++ b/lib/mli_parser.ml @@ -148,7 +148,7 @@ let make_block code_block file_contents = in let contents = slice code_block.content |> String.split_on_char '\n' in Block.mk ~loc:code_block.code_block ~section:None ~labels ~header - ~contents ~legacy_labels:false ~errors:[] + ~contents ~legacy_labels:false ~latex_arguments:None ~errors:[] (* Given the locations of the code blocks within [file_contents], then slice it up into [Text] and [Block] parts by using the starts and ends of those blocks as diff --git a/test/lib/test_block.ml b/test/lib/test_block.ml index 033c02bbc..e10f2a152 100644 --- a/test/lib/test_block.ml +++ b/test/lib/test_block.ml @@ -23,7 +23,7 @@ let test_mk = let test_fun () = let actual = Mdx.Block.mk ~loc:Location.none ~section:None ~labels - ~legacy_labels:false ~header ~contents ~errors:[] + ~legacy_labels:false ~latex_arguments:None ~header ~contents ~errors:[] in let expected = Result.map_error diff --git a/test/lib/test_dep.ml b/test/lib/test_dep.ml index 4aacc3c2e..5ae3f8257 100644 --- a/test/lib/test_dep.ml +++ b/test/lib/test_dep.ml @@ -26,7 +26,7 @@ let test_of_block = | Ok labels -> ( match Mdx.Block.mk ~loc:Location.none ~section:None ~labels ~header:None - ~contents:[] ~legacy_labels:false ~errors:[] + ~contents:[] ~legacy_labels:false ~latex_arguments:None ~errors:[] with | Ok block -> block | Error _ -> assert false) From 7cba5cc137f3dcafbdb57632b986d1b11f804cce Mon Sep 17 00:00:00 2001 From: Francisco Santos Date: Wed, 19 Jul 2023 17:20:16 +0100 Subject: [PATCH 08/14] compilation error fix --- lib/lexer_mdx.mll | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lexer_mdx.mll b/lib/lexer_mdx.mll index 1b763ee59..d614c70df 100644 --- a/lib/lexer_mdx.mll +++ b/lib/lexer_mdx.mll @@ -86,7 +86,7 @@ and cram_text section = parse let loc = loc ~start ~end_ in let block = Block.Raw.make ~loc ~section ~header ~contents ~label_cmt - ~legacy_labels ~errors:[] + ~legacy_labels ~latex_arguments:None ~errors:[] in `Block block :: (if requires_empty_line then `Text "\n" :: rest else rest) } @@ -102,7 +102,7 @@ and cram_text section = parse let rest = cram_text section lexbuf in let block = Block.Raw.make ~loc ~section ~header ~contents ~label_cmt - ~legacy_labels ~errors:[] + ~legacy_labels ~latex_arguments:None ~errors:[] in `Block block :: (if requires_empty_line then `Text "\n" :: rest else rest) } From 4dcca29a704633e6d9504839113032385f9d4d9e Mon Sep 17 00:00:00 2001 From: zazedd Date: Wed, 19 Jul 2023 21:13:25 +0100 Subject: [PATCH 09/14] added latex arguments to result --- lib/block.ml | 52 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/lib/block.ml b/lib/block.ml index 1f19db047..c6876d475 100644 --- a/lib/block.ml +++ b/lib/block.ml @@ -70,8 +70,19 @@ module Raw = struct errors : Output.t list; } - let make ~loc ~section ~header ~contents ~label_cmt ~legacy_labels ~latex_arguments ~errors = - Any { loc; section; header; contents; label_cmt; legacy_labels; latex_arguments; errors } + let make ~loc ~section ~header ~contents ~label_cmt ~legacy_labels + ~latex_arguments ~errors = + Any + { + loc; + section; + header; + contents; + label_cmt; + legacy_labels; + latex_arguments; + errors; + } let make_include ~loc ~section ~labels = Include { loc; section; labels } end @@ -230,11 +241,17 @@ let pp_header ?syntax ppf t = in Fmt.pf ppf "{%a%a[" pp_lang_header lang_headers pp_labels other_labels | Some Syntax.Cram -> pp_labels ?syntax ppf t.labels - | Some Syntax.Latex -> + | Some Syntax.Latex -> ( (* LaTeX does not have any legacy labels *) - Fmt.pf ppf "%a\\begin{%a}" (pp_labels ?syntax) t.labels - Fmt.(option Header.pp) - (header t) + match t.latex_arguments with + | None -> + Fmt.pf ppf "%a\\begin{%a}" (pp_labels ?syntax) t.labels + Fmt.(option Header.pp) + (header t) + | Some args -> + Fmt.pf ppf "%a\\begin{%a}%s" (pp_labels ?syntax) t.labels + Fmt.(option Header.pp) + (header t) args) | Some Syntax.Markdown | None -> if t.legacy_labels then Fmt.pf ppf "```%a%a" @@ -420,7 +437,8 @@ let infer_block ~loc ~config ~header ~contents ~errors = let+ () = check_no_errors ~loc errors in Raw { header }) -let mk ~loc ~section ~labels ~legacy_labels ~latex_arguments ~header ~contents ~errors = +let mk ~loc ~section ~labels ~legacy_labels ~latex_arguments ~header ~contents + ~errors = let block_kind = get_label (function Block_kind x -> Some x | _ -> None) labels in @@ -453,8 +471,8 @@ let mk_include ~loc ~section ~labels = match get_label (function File x -> Some x | _ -> None) labels with | Some file_inc -> let header = Header.infer_from_file file_inc in - mk ~loc ~section ~latex_arguments:None ~labels ~legacy_labels:false ~header ~contents:[] - ~errors:[] + mk ~loc ~section ~latex_arguments:None ~labels ~legacy_labels:false + ~header ~contents:[] ~errors:[] | None -> label_required ~loc ~label:"file" ~kind:"include" let parse_labels ~label_cmt ~legacy_labels = @@ -472,14 +490,24 @@ let from_raw raw = | Raw.Include { loc; section; labels } -> let* labels = locate_errors ~loc (Label.of_string labels) in Util.Result.to_error_list @@ mk_include ~loc ~section ~labels - | Raw.Any { loc; section; header; contents; label_cmt; latex_arguments; legacy_labels; errors } - -> + | Raw.Any + { + loc; + section; + header; + contents; + label_cmt; + latex_arguments; + legacy_labels; + errors; + } -> let header = Header.of_string header in let* labels, legacy_labels = locate_errors ~loc (parse_labels ~label_cmt ~legacy_labels) in Util.Result.to_error_list - @@ mk ~loc ~section ~header ~contents ~labels ~latex_arguments ~legacy_labels ~errors + @@ mk ~loc ~section ~header ~contents ~labels ~latex_arguments + ~legacy_labels ~errors let is_active ?section:s t = let active = From 430e2576ff62c80197938caaf11a91c4ed2ebc15 Mon Sep 17 00:00:00 2001 From: Francisco Santos Date: Sun, 23 Jul 2023 15:58:53 +0100 Subject: [PATCH 10/14] improving lexer_tex --- lib/lexer_tex.mll | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/lexer_tex.mll b/lib/lexer_tex.mll index c818b8da8..07d44d689 100644 --- a/lib/lexer_tex.mll +++ b/lib/lexer_tex.mll @@ -56,15 +56,15 @@ rule text section = parse `Text str :: text section lexbuf } and block = parse - | eof | ws* as end_pad "\\end{ocaml}" ws* eol + | eof | ws* as end_pad "\\end{" ([^' ' '\n']*) "}" ws* eol { newline lexbuf; [end_pad] } | ([^'\n']* as str) eol - { newline lexbuf; + { newline lexbuf; str :: block lexbuf } and error_block = parse - | "\\begin{ocaml}" ws* eol { newline lexbuf; block lexbuf } + | "\\begin{mdx-error}" ws* eol { newline lexbuf; block lexbuf } { let latex_token lexbuf = From bb2a5981b5573df8e9598becf2064788f5d908d1 Mon Sep 17 00:00:00 2001 From: zazedd Date: Sun, 23 Jul 2023 17:02:02 +0100 Subject: [PATCH 11/14] some tests --- lib/block.ml | 2 +- test/bin/gen_rule_helpers/gen_rule_helpers.ml | 2 +- .../casual-file-inc/casual-file.txt | 3 ++ .../casual-file-inc/test-case.tex | 6 ++++ .../casual-file-inc/test-case.tex.expected | 9 +++++ .../mdx-test/expect-latex/code/test-case.tex | 35 +++++++++++++++++++ .../expect-latex/compenv-exit/test-case.md | 5 +++ .../compenv-exit/test-case.md.expected | 7 ++++ test/bin/mdx-test/expect-latex/dune | 15 ++++++++ test/bin/mdx-test/expect-latex/dune.inc | 24 +++++++++++++ .../ellipsis-updates/test-case.md | 22 ++++++++++++ .../ellipsis-updates/test-case.md.expected | 30 ++++++++++++++++ .../expect-latex/ellipsis/test-case.tex | 32 +++++++++++++++++ .../ellipsis/test-case.tex.corrected | 32 +++++++++++++++++ 14 files changed, 222 insertions(+), 2 deletions(-) create mode 100644 test/bin/mdx-test/expect-latex/casual-file-inc/casual-file.txt create mode 100644 test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex.expected create mode 100644 test/bin/mdx-test/expect-latex/code/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/compenv-exit/test-case.md create mode 100644 test/bin/mdx-test/expect-latex/compenv-exit/test-case.md.expected create mode 100644 test/bin/mdx-test/expect-latex/dune create mode 100644 test/bin/mdx-test/expect-latex/dune.inc create mode 100644 test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md create mode 100644 test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md.expected create mode 100644 test/bin/mdx-test/expect-latex/ellipsis/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.corrected diff --git a/lib/block.ml b/lib/block.ml index c6876d475..00e99c4ce 100644 --- a/lib/block.ml +++ b/lib/block.ml @@ -215,7 +215,7 @@ let pp_labels ?syntax ppf labels = | Some Syntax.Latex -> ( match labels with | [] -> () - | l -> Fmt.pf ppf "%% $MDX %a \n" Fmt.(list ~sep:(any ",") Label.pp) l) + | l -> Fmt.pf ppf "%% $MDX %a\n" Fmt.(list ~sep:(any ",") Label.pp) l) | Some Syntax.Markdown | None -> ( match labels with | [] -> () diff --git a/test/bin/gen_rule_helpers/gen_rule_helpers.ml b/test/bin/gen_rule_helpers/gen_rule_helpers.ml index 086ecb5ff..0326cc80a 100644 --- a/test/bin/gen_rule_helpers/gen_rule_helpers.ml +++ b/test/bin/gen_rule_helpers/gen_rule_helpers.ml @@ -39,7 +39,7 @@ let get_files dir = let cwd_options_file = "test-case.opts" let cwd_test_files = - [ "test-case.md"; "test-case.t"; "test-case.mli"; "test-case.mld" ] + [ "test-case.md"; "test-case.t"; "test-case.mli"; "test-case.mld"; "test-case.tex" ] let cwd_enabled_if_file = "test-case.enabled-if" diff --git a/test/bin/mdx-test/expect-latex/casual-file-inc/casual-file.txt b/test/bin/mdx-test/expect-latex/casual-file-inc/casual-file.txt new file mode 100644 index 000000000..5c1997bb2 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/casual-file-inc/casual-file.txt @@ -0,0 +1,3 @@ +Include me. + +Please. \ No newline at end of file diff --git a/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex b/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex new file mode 100644 index 000000000..83e9b5594 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex @@ -0,0 +1,6 @@ +Mdx can also include text from any file: + + +% $MDX file=casual-file.txt +\begin{ocaml} +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex.expected b/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex.expected new file mode 100644 index 000000000..ac53fe8bd --- /dev/null +++ b/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex.expected @@ -0,0 +1,9 @@ +Mdx can also include text from any file: + + +% $MDX file=casual-file.txt +\begin{ocaml} +Include me. + +Please. +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/code/test-case.tex b/test/bin/mdx-test/expect-latex/code/test-case.tex new file mode 100644 index 000000000..1e420c6c8 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/code/test-case.tex @@ -0,0 +1,35 @@ +Normal OCaml code: + +\begin{ocaml} +let x = 3 + +let f x = x + 1 + +let () = Printf.printf "n: %d\n%!" (f 42) +\end{ocaml} + +Yo! + +\begin{ocaml} +# let x = 3;; +val x : int = 3 +# type t = int;; +type t = int +\end{ocaml} + + +\begin{ocaml} +class istack = object end +\end{ocaml} + +\begin{ocaml} +# module type Foo = sig type t end;; +module type Foo = sig type t end +\end{ocaml} + + +% $MDX skip +\begin{ocaml} +# Pipe.f ();; +- : unit +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/compenv-exit/test-case.md b/test/bin/mdx-test/expect-latex/compenv-exit/test-case.md new file mode 100644 index 000000000..5deda90ae --- /dev/null +++ b/test/bin/mdx-test/expect-latex/compenv-exit/test-case.md @@ -0,0 +1,5 @@ +Exits from the toplevel are reported correctly: + +```ocaml +# #use "idontexist.ml";; +``` diff --git a/test/bin/mdx-test/expect-latex/compenv-exit/test-case.md.expected b/test/bin/mdx-test/expect-latex/compenv-exit/test-case.md.expected new file mode 100644 index 000000000..2023ad5bd --- /dev/null +++ b/test/bin/mdx-test/expect-latex/compenv-exit/test-case.md.expected @@ -0,0 +1,7 @@ +Exits from the toplevel are reported correctly: + +```ocaml +# #use "idontexist.ml";; +Cannot find file idontexist.ml. +[125] +``` diff --git a/test/bin/mdx-test/expect-latex/dune b/test/bin/mdx-test/expect-latex/dune new file mode 100644 index 000000000..fa81ca77d --- /dev/null +++ b/test/bin/mdx-test/expect-latex/dune @@ -0,0 +1,15 @@ +(include dune.inc) + +(rule + (target dune.gen) + (deps + (source_tree .)) + (action + (with-stdout-to + %{target} + (run ../gen_dune_rules.exe test_expect)))) + +(rule + (alias runtest) + (action + (diff dune.inc dune.gen))) diff --git a/test/bin/mdx-test/expect-latex/dune.inc b/test/bin/mdx-test/expect-latex/dune.inc new file mode 100644 index 000000000..051f95907 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/dune.inc @@ -0,0 +1,24 @@ + +(rule + (target casual-file-inc.actual) + (deps (package mdx) (source_tree casual-file-inc)) + (action + (with-stdout-to %{target} + (chdir casual-file-inc + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff casual-file-inc/test-case.tex.expected casual-file-inc.actual))) + +(rule + (target code.actual) + (deps (package mdx) (source_tree code)) + (action + (with-stdout-to %{target} + (chdir code + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff code/test-case.tex code.actual))) diff --git a/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md b/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md new file mode 100644 index 000000000..4e11f2410 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md @@ -0,0 +1,22 @@ +Ellipsis lines are preserved if possible even when the output changes + +```sh +$ for i in `seq 1 21`; do echo $i; done +1 +2 +... +10 +... +19 +20 +``` + +```sh +$ for i in `seq 1 19`; do echo $i; done +1 +2 +... +10 +... +20 +``` diff --git a/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md.expected b/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md.expected new file mode 100644 index 000000000..669c77b17 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md.expected @@ -0,0 +1,30 @@ +Ellipsis lines are preserved if possible even when the output changes + +```sh +$ for i in `seq 1 21`; do echo $i; done +1 +2 +... +10 +... +19 +20 +21 +``` + +```sh +$ for i in `seq 1 19`; do echo $i; done +1 +2 +... +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +``` diff --git a/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex b/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex new file mode 100644 index 000000000..74ebfff1d --- /dev/null +++ b/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex @@ -0,0 +1,32 @@ +Long lines can be replaced by ellipsis: + +\begin{sh} +$ for i in `seq 1 10`; do echo $i; done +1 +2 +... +10 +\end{sh} + +\begin{ocaml} +# for i = 1 to 10 do Printf.printf "%d\n%!" i; done;; +1 +2 +... +10 +- : unit = () +\end{ocaml} + +\begin{sh} +$ printf "foo\"\n\nbar" +foo" + +... +\end{sh} + +Lines ending with ellipsis + +\begin{sh} +$ echo Hello world +Hello... +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.corrected b/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.corrected new file mode 100644 index 000000000..e07428a42 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.corrected @@ -0,0 +1,32 @@ +Long lines can be replaced by ellipsis: + +\begin{sh} +$ for i in `seq 1 10`; do echo $i; done +1 +2 +... +10 +\end{ocaml} + +\begin{ocaml} +# for i = 1 to 10 do Printf.printf "%d\n%!" i; done;; +1 +2 +... +10 +- : unit = () +\end{ocaml} + +\begin{sh} +$ printf "foo\"\n\nbar" +foo" + +... +\end{ocaml} + +Lines ending with ellipsis + +\begin{sh} +$ echo Hello world +Hello... +\end{ocaml} From 22ae9505f48ab3986fcde52d47ce36628333f408 Mon Sep 17 00:00:00 2001 From: Francisco Santos Date: Sun, 23 Jul 2023 18:31:25 +0100 Subject: [PATCH 12/14] end block --- lib/block.ml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/block.ml b/lib/block.ml index 00e99c4ce..37632f475 100644 --- a/lib/block.ml +++ b/lib/block.ml @@ -188,11 +188,19 @@ let pp_errors ?syntax ppf t = errors) | _ -> () -let pp_footer ?syntax ppf _ = +let pp_footer ?syntax ppf t = match syntax with | Some Syntax.Mli | Some Syntax.Mld -> Fmt.string ppf "]}" | Some Syntax.Cram -> Fmt.string ppf "\n" - | Some Syntax.Latex -> Fmt.string ppf "\\end{ocaml}\n" + | Some Syntax.Latex -> ( + let header = header t in + match header with + | None -> Fmt.string ppf "\\end{}\n" + | Some t -> ( + Fmt.string ppf "\\end{"; + Header.pp ppf t; + Fmt.string ppf "}\n"; + )) | Some Syntax.Markdown | None -> Fmt.string ppf "```\n" let pp_legacy_labels ppf = function From 5570ff95fbe4b9a6f25e19ff0b88ecdb07b82ef5 Mon Sep 17 00:00:00 2001 From: zazedd Date: Sun, 23 Jul 2023 18:47:36 +0100 Subject: [PATCH 13/14] better end block, another test case --- lib/block.ml | 11 ++-------- .../expect-latex/ellipsis/test-case.tex | 9 -------- ...e.tex.corrected => test-case.tex.expected} | 22 ++++++++++++++----- 3 files changed, 19 insertions(+), 23 deletions(-) rename test/bin/mdx-test/expect-latex/ellipsis/{test-case.tex.corrected => test-case.tex.expected} (85%) diff --git a/lib/block.ml b/lib/block.ml index 37632f475..2310df82f 100644 --- a/lib/block.ml +++ b/lib/block.ml @@ -192,15 +192,8 @@ let pp_footer ?syntax ppf t = match syntax with | Some Syntax.Mli | Some Syntax.Mld -> Fmt.string ppf "]}" | Some Syntax.Cram -> Fmt.string ppf "\n" - | Some Syntax.Latex -> ( - let header = header t in - match header with - | None -> Fmt.string ppf "\\end{}\n" - | Some t -> ( - Fmt.string ppf "\\end{"; - Header.pp ppf t; - Fmt.string ppf "}\n"; - )) + | Some Syntax.Latex -> + Fmt.pf ppf "\\end{%a}\n" Fmt.(option Header.pp) (header t) | Some Syntax.Markdown | None -> Fmt.string ppf "```\n" let pp_legacy_labels ppf = function diff --git a/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex b/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex index 74ebfff1d..28de331a5 100644 --- a/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex +++ b/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex @@ -2,19 +2,10 @@ \begin{sh} $ for i in `seq 1 10`; do echo $i; done -1 -2 -... -10 \end{sh} \begin{ocaml} # for i = 1 to 10 do Printf.printf "%d\n%!" i; done;; -1 -2 -... -10 -- : unit = () \end{ocaml} \begin{sh} diff --git a/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.corrected b/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.expected similarity index 85% rename from test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.corrected rename to test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.expected index e07428a42..7378306cc 100644 --- a/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.corrected +++ b/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.expected @@ -4,15 +4,27 @@ Long lines can be replaced by ellipsis: $ for i in `seq 1 10`; do echo $i; done 1 2 -... +3 +4 +5 +6 +7 +8 +9 10 -\end{ocaml} +\end{sh} \begin{ocaml} # for i = 1 to 10 do Printf.printf "%d\n%!" i; done;; 1 2 -... +3 +4 +5 +6 +7 +8 +9 10 - : unit = () \end{ocaml} @@ -22,11 +34,11 @@ $ printf "foo\"\n\nbar" foo" ... -\end{ocaml} +\end{sh} Lines ending with ellipsis \begin{sh} $ echo Hello world Hello... -\end{ocaml} +\end{sh} From d6bcc9bde540d0ddcd2ee0573f01ee16b114ab75 Mon Sep 17 00:00:00 2001 From: zazedd Date: Sun, 23 Jul 2023 22:18:56 +0100 Subject: [PATCH 14/14] unit tests --- test/bin/mdx-test/expect-latex/.ocamlformat | 1 + .../expect-latex/bash-fence/test-case.tex | 19 + .../bash-fence/test-case.tex.expected | 21 + .../casual-file-inc/test-case.tex | 1 - .../casual-file-inc/test-case.tex.expected | 1 - .../mdx-test/expect-latex/code/test-case.tex | 1 - .../{test-case.md => test-case.tex} | 4 +- ...ase.md.expected => test-case.tex.expected} | 4 +- test/bin/mdx-test/expect-latex/dune.inc | 480 ++++++++++++++++++ .../{test-case.md => test-case.tex} | 8 +- ...ase.md.expected => test-case.tex.expected} | 8 +- .../expect-latex/ellipsis/test-case.tex | 10 + .../ellipsis/test-case.tex.expected | 44 -- .../expect-latex/empty-line/test-case.tex | 8 + .../expect-latex/empty-lines/test-case.tex | 17 + .../empty-lines/test-case.tex.expected | 20 + .../mdx-test/expect-latex/empty/test-case.tex | 26 + .../expect-latex/env-and-prelude/a.ml | 1 + .../expect-latex/env-and-prelude/all.ml | 1 + .../expect-latex/env-and-prelude/b.ml | 1 + .../expect-latex/env-and-prelude/default.ml | 1 + .../env-and-prelude/test-case.opts | 1 + .../env-and-prelude/test-case.tex | 60 +++ .../environment-variable-set/test-case.tex | 50 ++ .../environment-variable/test-case.tex | 19 + .../mdx-test/expect-latex/envs/test-case.tex | 145 ++++++ .../expect-latex/errors/test-case.tex | 79 +++ .../mdx-test/expect-latex/exit/test-case.tex | 13 + .../expect-latex/heredoc/test-case.tex | 26 + .../expect-latex/include-block/code.mli | 3 + .../mdx-test/expect-latex/include-block/dune | 0 .../expect-latex/include-block/test-case.tex | 7 + .../include-block/test-case.tex.expected | 18 + .../expect-latex/labels-syntax/test-case.tex | 30 ++ .../expect-latex/line-delimiters/include.ml | 4 + .../line-delimiters/test-case.tex | 6 + .../mdx-test/expect-latex/lines/test-case.tex | 73 +++ .../mdx-test/expect-latex/lwt/test-case.tex | 16 + .../mdx-test/expect-latex/mlt/test-case.tex | 45 ++ .../expect-latex/multilines/test-case.tex | 37 ++ .../non-det-default-preserved/test-case.tex | 7 + .../expect-latex/non-det/test-case.tex | 56 ++ .../ocaml-408-syntax/test-case.tex | 7 + .../ocaml-errors-ellipsis/test-case.tex | 23 + .../expect-latex/ocaml-errors/test-case.tex | 52 ++ .../ocaml-errors/test-case.tex.expected | 46 ++ .../expect-latex/padding/test-case.tex | 23 + .../parts-begin-end/parts-begin-end.ml | 36 ++ .../parts-begin-end/test-case.tex | 40 ++ .../parts-begin-end/test-case.tex.expected | 74 +++ .../expect-latex/prelude-file/prelude.ml | 8 + .../expect-latex/prelude-file/test-case.opts | 1 + .../expect-latex/prelude-file/test-case.tex | 18 + .../mdx-test/expect-latex/prelude/prelude.ml | 8 + .../expect-latex/prelude/test-case.opts | 2 + .../expect-latex/prelude/test-case.tex | 30 ++ .../expect-latex/requires/test-case.tex | 7 + .../root-option/somedir/.gitignore | 0 .../expect-latex/root-option/test-case.opts | 1 + .../expect-latex/root-option/test-case.tex | 6 + .../expect-latex/shell-file-inc/script.sh | 1 + .../expect-latex/shell-file-inc/test-case.tex | 6 + .../shell-file-inc/test-case.tex.expected | 7 + .../expect-latex/spaces/test-case.tex | 29 ++ .../sync-from-subdir/some_dir/some_module.ml | 4 + .../sync-from-subdir/test-case.tex | 5 + .../sync-from-subdir/test-case.tex.expected | 6 + .../expect-latex/sync-to-md/sync_to_md.ml | 27 + .../expect-latex/sync-to-md/test-case.opts | 0 .../expect-latex/sync-to-md/test-case.tex | 40 ++ .../sync-to-md/test-case.tex.expected | 69 +++ .../mdx-test/expect-latex/tabs/test-case.tex | 8 + .../expect-latex/tabs/test-case.tex.expected | 8 + .../toploop-getvalue/test-case.tex | 16 + .../trailing-whitespaces/test-case.tex | 21 + .../test-case.tex.expected | 21 + .../expect-latex/warnings/test-case.tex | 33 ++ 77 files changed, 1996 insertions(+), 59 deletions(-) create mode 100644 test/bin/mdx-test/expect-latex/.ocamlformat create mode 100644 test/bin/mdx-test/expect-latex/bash-fence/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/bash-fence/test-case.tex.expected rename test/bin/mdx-test/expect-latex/compenv-exit/{test-case.md => test-case.tex} (74%) rename test/bin/mdx-test/expect-latex/compenv-exit/{test-case.md.expected => test-case.tex.expected} (81%) rename test/bin/mdx-test/expect-latex/ellipsis-updates/{test-case.md => test-case.tex} (82%) rename test/bin/mdx-test/expect-latex/ellipsis-updates/{test-case.md.expected => test-case.tex.expected} (84%) delete mode 100644 test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.expected create mode 100644 test/bin/mdx-test/expect-latex/empty-line/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/empty-lines/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/empty-lines/test-case.tex.expected create mode 100644 test/bin/mdx-test/expect-latex/empty/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/env-and-prelude/a.ml create mode 100644 test/bin/mdx-test/expect-latex/env-and-prelude/all.ml create mode 100644 test/bin/mdx-test/expect-latex/env-and-prelude/b.ml create mode 100644 test/bin/mdx-test/expect-latex/env-and-prelude/default.ml create mode 100644 test/bin/mdx-test/expect-latex/env-and-prelude/test-case.opts create mode 100644 test/bin/mdx-test/expect-latex/env-and-prelude/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/environment-variable-set/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/environment-variable/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/envs/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/errors/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/exit/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/heredoc/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/include-block/code.mli create mode 100644 test/bin/mdx-test/expect-latex/include-block/dune create mode 100644 test/bin/mdx-test/expect-latex/include-block/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/include-block/test-case.tex.expected create mode 100644 test/bin/mdx-test/expect-latex/labels-syntax/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/line-delimiters/include.ml create mode 100644 test/bin/mdx-test/expect-latex/line-delimiters/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/lines/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/lwt/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/mlt/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/multilines/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/non-det-default-preserved/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/non-det/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/ocaml-408-syntax/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/ocaml-errors-ellipsis/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/ocaml-errors/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/ocaml-errors/test-case.tex.expected create mode 100644 test/bin/mdx-test/expect-latex/padding/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/parts-begin-end/parts-begin-end.ml create mode 100644 test/bin/mdx-test/expect-latex/parts-begin-end/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/parts-begin-end/test-case.tex.expected create mode 100644 test/bin/mdx-test/expect-latex/prelude-file/prelude.ml create mode 100644 test/bin/mdx-test/expect-latex/prelude-file/test-case.opts create mode 100644 test/bin/mdx-test/expect-latex/prelude-file/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/prelude/prelude.ml create mode 100644 test/bin/mdx-test/expect-latex/prelude/test-case.opts create mode 100644 test/bin/mdx-test/expect-latex/prelude/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/requires/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/root-option/somedir/.gitignore create mode 100644 test/bin/mdx-test/expect-latex/root-option/test-case.opts create mode 100644 test/bin/mdx-test/expect-latex/root-option/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/shell-file-inc/script.sh create mode 100644 test/bin/mdx-test/expect-latex/shell-file-inc/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/shell-file-inc/test-case.tex.expected create mode 100644 test/bin/mdx-test/expect-latex/spaces/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/sync-from-subdir/some_dir/some_module.ml create mode 100644 test/bin/mdx-test/expect-latex/sync-from-subdir/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/sync-from-subdir/test-case.tex.expected create mode 100644 test/bin/mdx-test/expect-latex/sync-to-md/sync_to_md.ml create mode 100644 test/bin/mdx-test/expect-latex/sync-to-md/test-case.opts create mode 100644 test/bin/mdx-test/expect-latex/sync-to-md/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/sync-to-md/test-case.tex.expected create mode 100644 test/bin/mdx-test/expect-latex/tabs/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/tabs/test-case.tex.expected create mode 100644 test/bin/mdx-test/expect-latex/toploop-getvalue/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/trailing-whitespaces/test-case.tex create mode 100644 test/bin/mdx-test/expect-latex/trailing-whitespaces/test-case.tex.expected create mode 100644 test/bin/mdx-test/expect-latex/warnings/test-case.tex diff --git a/test/bin/mdx-test/expect-latex/.ocamlformat b/test/bin/mdx-test/expect-latex/.ocamlformat new file mode 100644 index 000000000..e3346c163 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/.ocamlformat @@ -0,0 +1 @@ +disable=true diff --git a/test/bin/mdx-test/expect-latex/bash-fence/test-case.tex b/test/bin/mdx-test/expect-latex/bash-fence/test-case.tex new file mode 100644 index 000000000..8b4b7824d --- /dev/null +++ b/test/bin/mdx-test/expect-latex/bash-fence/test-case.tex @@ -0,0 +1,19 @@ +The choice of `bash` vs. `sh` code fences should be preserved: + +\begin{bash} +$ echo 'bash block runs' +\end{bash} + +\begin{sh} +$ echo 'sh block runs' +\end{sh} + +Even when the blocks are skipped: + +% $MDX skip +\begin{bash} +\end{bash} + +% $MDX skip +\begin{sh} +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/bash-fence/test-case.tex.expected b/test/bin/mdx-test/expect-latex/bash-fence/test-case.tex.expected new file mode 100644 index 000000000..5a257a019 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/bash-fence/test-case.tex.expected @@ -0,0 +1,21 @@ +The choice of `bash` vs. `sh` code fences should be preserved: + +\begin{bash} +$ echo 'bash block runs' +bash block runs +\end{bash} + +\begin{sh} +$ echo 'sh block runs' +sh block runs +\end{sh} + +Even when the blocks are skipped: + +% $MDX skip +\begin{bash} +\end{bash} + +% $MDX skip +\begin{sh} +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex b/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex index 83e9b5594..9010886eb 100644 --- a/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex +++ b/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex @@ -1,6 +1,5 @@ Mdx can also include text from any file: - % $MDX file=casual-file.txt \begin{ocaml} \end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex.expected b/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex.expected index ac53fe8bd..f60bcc360 100644 --- a/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex.expected +++ b/test/bin/mdx-test/expect-latex/casual-file-inc/test-case.tex.expected @@ -1,6 +1,5 @@ Mdx can also include text from any file: - % $MDX file=casual-file.txt \begin{ocaml} Include me. diff --git a/test/bin/mdx-test/expect-latex/code/test-case.tex b/test/bin/mdx-test/expect-latex/code/test-case.tex index 1e420c6c8..6c075ddde 100644 --- a/test/bin/mdx-test/expect-latex/code/test-case.tex +++ b/test/bin/mdx-test/expect-latex/code/test-case.tex @@ -17,7 +17,6 @@ type t = int \end{ocaml} - \begin{ocaml} class istack = object end \end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/compenv-exit/test-case.md b/test/bin/mdx-test/expect-latex/compenv-exit/test-case.tex similarity index 74% rename from test/bin/mdx-test/expect-latex/compenv-exit/test-case.md rename to test/bin/mdx-test/expect-latex/compenv-exit/test-case.tex index 5deda90ae..8edcf1bda 100644 --- a/test/bin/mdx-test/expect-latex/compenv-exit/test-case.md +++ b/test/bin/mdx-test/expect-latex/compenv-exit/test-case.tex @@ -1,5 +1,5 @@ Exits from the toplevel are reported correctly: -```ocaml +\begin{ocaml} # #use "idontexist.ml";; -``` +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/compenv-exit/test-case.md.expected b/test/bin/mdx-test/expect-latex/compenv-exit/test-case.tex.expected similarity index 81% rename from test/bin/mdx-test/expect-latex/compenv-exit/test-case.md.expected rename to test/bin/mdx-test/expect-latex/compenv-exit/test-case.tex.expected index 2023ad5bd..30de482e8 100644 --- a/test/bin/mdx-test/expect-latex/compenv-exit/test-case.md.expected +++ b/test/bin/mdx-test/expect-latex/compenv-exit/test-case.tex.expected @@ -1,7 +1,7 @@ Exits from the toplevel are reported correctly: -```ocaml +\begin{ocaml} # #use "idontexist.ml";; Cannot find file idontexist.ml. [125] -``` +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/dune.inc b/test/bin/mdx-test/expect-latex/dune.inc index 051f95907..b007d0140 100644 --- a/test/bin/mdx-test/expect-latex/dune.inc +++ b/test/bin/mdx-test/expect-latex/dune.inc @@ -1,4 +1,16 @@ +(rule + (target bash-fence.actual) + (deps (package mdx) (source_tree bash-fence)) + (action + (with-stdout-to %{target} + (chdir bash-fence + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff bash-fence/test-case.tex.expected bash-fence.actual))) + (rule (target casual-file-inc.actual) (deps (package mdx) (source_tree casual-file-inc)) @@ -22,3 +34,471 @@ (rule (alias runtest) (action (diff code/test-case.tex code.actual))) + +(rule + (target compenv-exit.actual) + (deps (package mdx) (source_tree compenv-exit)) + (action + (with-stdout-to %{target} + (chdir compenv-exit + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff compenv-exit/test-case.tex.expected compenv-exit.actual))) + +(rule + (target ellipsis.actual) + (deps (package mdx) (source_tree ellipsis)) + (action + (with-stdout-to %{target} + (chdir ellipsis + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff ellipsis/test-case.tex ellipsis.actual))) + +(rule + (target ellipsis-updates.actual) + (deps (package mdx) (source_tree ellipsis-updates)) + (action + (with-stdout-to %{target} + (chdir ellipsis-updates + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff ellipsis-updates/test-case.tex.expected ellipsis-updates.actual))) + +(rule + (target empty.actual) + (deps (package mdx) (source_tree empty)) + (action + (with-stdout-to %{target} + (chdir empty + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff empty/test-case.tex empty.actual))) + +(rule + (target empty-line.actual) + (deps (package mdx) (source_tree empty-line)) + (action + (with-stdout-to %{target} + (chdir empty-line + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff empty-line/test-case.tex empty-line.actual))) + +(rule + (target empty-lines.actual) + (deps (package mdx) (source_tree empty-lines)) + (action + (with-stdout-to %{target} + (chdir empty-lines + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff empty-lines/test-case.tex.expected empty-lines.actual))) + +(rule + (target env-and-prelude.actual) + (deps (package mdx) (source_tree env-and-prelude)) + (action + (with-stdout-to %{target} + (chdir env-and-prelude + (run ocaml-mdx test --output - --prelude all.ml --prelude " :default.ml" --prelude a:a.ml --prelude b:b.ml test-case.tex))))) + +(rule + (alias runtest) + (action (diff env-and-prelude/test-case.tex env-and-prelude.actual))) + +(rule + (target environment-variable.actual) + (deps (package mdx) (source_tree environment-variable)) + (action + (with-stdout-to %{target} + (chdir environment-variable + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff environment-variable/test-case.tex environment-variable.actual))) + +(rule + (target environment-variable-set.actual) + (deps (package mdx) (source_tree environment-variable-set)) + (action + (with-stdout-to %{target} + (chdir environment-variable-set + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff environment-variable-set/test-case.tex environment-variable-set.actual))) + +(rule + (target envs.actual) + (deps (package mdx) (source_tree envs)) + (action + (with-stdout-to %{target} + (chdir envs + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff envs/test-case.tex envs.actual))) + +(rule + (target errors.actual) + (deps (package mdx) (source_tree errors)) + (action + (with-stdout-to %{target} + (chdir errors + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff errors/test-case.tex errors.actual))) + +(rule + (target exit.actual) + (deps (package mdx) (source_tree exit)) + (action + (with-stdout-to %{target} + (chdir exit + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff exit/test-case.tex exit.actual))) + +(rule + (target heredoc.actual) + (deps (package mdx) (source_tree heredoc)) + (action + (with-stdout-to %{target} + (chdir heredoc + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff heredoc/test-case.tex heredoc.actual))) + +(rule + (target include-block.actual) + (deps (package mdx) (source_tree include-block)) + (action + (with-stdout-to %{target} + (chdir include-block + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff include-block/test-case.tex.expected include-block.actual))) + +(rule + (target labels-syntax.actual) + (deps (package mdx) (source_tree labels-syntax)) + (action + (with-stdout-to %{target} + (chdir labels-syntax + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff labels-syntax/test-case.tex labels-syntax.actual))) + +(rule + (target line-delimiters.actual) + (deps (package mdx) (source_tree line-delimiters)) + (action + (with-stdout-to %{target} + (chdir line-delimiters + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff line-delimiters/test-case.tex line-delimiters.actual))) + +(rule + (target lines.actual) + (deps (package mdx) (source_tree lines)) + (action + (with-stdout-to %{target} + (chdir lines + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff lines/test-case.tex lines.actual))) + +(rule + (target lwt.actual) + (deps (package mdx) (source_tree lwt)) + (action + (with-stdout-to %{target} + (chdir lwt + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff lwt/test-case.tex lwt.actual))) + +(rule + (target mlt.actual) + (deps (package mdx) (source_tree mlt)) + (action + (with-stdout-to %{target} + (chdir mlt + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff mlt/test-case.tex mlt.actual))) + +(rule + (target multilines.actual) + (deps (package mdx) (source_tree multilines)) + (action + (with-stdout-to %{target} + (chdir multilines + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff multilines/test-case.tex multilines.actual))) + +(rule + (target non-det.actual) + (deps (package mdx) (source_tree non-det)) + (action + (with-stdout-to %{target} + (chdir non-det + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff non-det/test-case.tex non-det.actual))) + +(rule + (target non-det-default-preserved.actual) + (deps (package mdx) (source_tree non-det-default-preserved)) + (action + (with-stdout-to %{target} + (chdir non-det-default-preserved + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff non-det-default-preserved/test-case.tex non-det-default-preserved.actual))) + +(rule + (target ocaml-408-syntax.actual) + (deps (package mdx) (source_tree ocaml-408-syntax)) + (action + (with-stdout-to %{target} + (chdir ocaml-408-syntax + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff ocaml-408-syntax/test-case.tex ocaml-408-syntax.actual))) + +(rule + (target ocaml-errors.actual) + (deps (package mdx) (source_tree ocaml-errors)) + (action + (with-stdout-to %{target} + (chdir ocaml-errors + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff ocaml-errors/test-case.tex.expected ocaml-errors.actual))) + +(rule + (target ocaml-errors-ellipsis.actual) + (deps (package mdx) (source_tree ocaml-errors-ellipsis)) + (action + (with-stdout-to %{target} + (chdir ocaml-errors-ellipsis + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff ocaml-errors-ellipsis/test-case.tex ocaml-errors-ellipsis.actual))) + +(rule + (target padding.actual) + (deps (package mdx) (source_tree padding)) + (action + (with-stdout-to %{target} + (chdir padding + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff padding/test-case.tex padding.actual))) + +(rule + (target parts-begin-end.actual) + (deps (package mdx) (source_tree parts-begin-end)) + (action + (with-stdout-to %{target} + (chdir parts-begin-end + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff parts-begin-end/test-case.tex.expected parts-begin-end.actual))) + +(rule + (target prelude.actual) + (deps (package mdx) (source_tree prelude)) + (action + (with-stdout-to %{target} + (chdir prelude + (run ocaml-mdx test --output - --prelude-str "#require \"lwt\"" --prelude-str "toto:let x = \"42\"" test-case.tex))))) + +(rule + (alias runtest) + (action (diff prelude/test-case.tex prelude.actual))) + +(rule + (target prelude-file.actual) + (deps (package mdx) (source_tree prelude-file)) + (action + (with-stdout-to %{target} + (chdir prelude-file + (run ocaml-mdx test --output - --prelude prelude.ml test-case.tex))))) + +(rule + (alias runtest) + (action (diff prelude-file/test-case.tex prelude-file.actual))) + +(rule + (target requires.actual) + (deps (package mdx) (source_tree requires)) + (action + (with-stdout-to %{target} + (chdir requires + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff requires/test-case.tex requires.actual))) + +(rule + (target root-option.actual) + (deps (package mdx) (source_tree root-option)) + (action + (with-stdout-to %{target} + (chdir root-option + (run ocaml-mdx test --output - --root=somedir test-case.tex))))) + +(rule + (alias runtest) + (action (diff root-option/test-case.tex root-option.actual))) + +(rule + (target shell-file-inc.actual) + (deps (package mdx) (source_tree shell-file-inc)) + (action + (with-stdout-to %{target} + (chdir shell-file-inc + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff shell-file-inc/test-case.tex.expected shell-file-inc.actual))) + +(rule + (target spaces.actual) + (deps (package mdx) (source_tree spaces)) + (action + (with-stdout-to %{target} + (chdir spaces + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff spaces/test-case.tex spaces.actual))) + +(rule + (target sync-from-subdir.actual) + (deps (package mdx) (source_tree sync-from-subdir)) + (action + (with-stdout-to %{target} + (chdir sync-from-subdir + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff sync-from-subdir/test-case.tex.expected sync-from-subdir.actual))) + +(rule + (target sync-to-md.actual) + (deps (package mdx) (source_tree sync-to-md)) + (action + (with-stdout-to %{target} + (chdir sync-to-md + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff sync-to-md/test-case.tex.expected sync-to-md.actual))) + +(rule + (target tabs.actual) + (deps (package mdx) (source_tree tabs)) + (action + (with-stdout-to %{target} + (chdir tabs + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff tabs/test-case.tex.expected tabs.actual))) + +(rule + (target toploop-getvalue.actual) + (deps (package mdx) (source_tree toploop-getvalue)) + (action + (with-stdout-to %{target} + (chdir toploop-getvalue + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff toploop-getvalue/test-case.tex toploop-getvalue.actual))) + +(rule + (target trailing-whitespaces.actual) + (deps (package mdx) (source_tree trailing-whitespaces)) + (action + (with-stdout-to %{target} + (chdir trailing-whitespaces + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff trailing-whitespaces/test-case.tex.expected trailing-whitespaces.actual))) + +(rule + (target warnings.actual) + (deps (package mdx) (source_tree warnings)) + (action + (with-stdout-to %{target} + (chdir warnings + (run ocaml-mdx test --output - test-case.tex))))) + +(rule + (alias runtest) + (action (diff warnings/test-case.tex warnings.actual))) diff --git a/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md b/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.tex similarity index 82% rename from test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md rename to test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.tex index 4e11f2410..9545b8837 100644 --- a/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md +++ b/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.tex @@ -1,6 +1,6 @@ Ellipsis lines are preserved if possible even when the output changes -```sh +\begin{sh} $ for i in `seq 1 21`; do echo $i; done 1 2 @@ -9,9 +9,9 @@ ... 19 20 -``` +\end{sh} -```sh +\begin{sh} $ for i in `seq 1 19`; do echo $i; done 1 2 @@ -19,4 +19,4 @@ 10 ... 20 -``` +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md.expected b/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.tex.expected similarity index 84% rename from test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md.expected rename to test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.tex.expected index 669c77b17..a806d25a7 100644 --- a/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.md.expected +++ b/test/bin/mdx-test/expect-latex/ellipsis-updates/test-case.tex.expected @@ -1,6 +1,6 @@ Ellipsis lines are preserved if possible even when the output changes -```sh +\begin{sh} $ for i in `seq 1 21`; do echo $i; done 1 2 @@ -10,9 +10,9 @@ $ for i in `seq 1 21`; do echo $i; done 19 20 21 -``` +\end{sh} -```sh +\begin{sh} $ for i in `seq 1 19`; do echo $i; done 1 2 @@ -27,4 +27,4 @@ $ for i in `seq 1 19`; do echo $i; done 17 18 19 -``` +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex b/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex index 28de331a5..4b3a6d3f5 100644 --- a/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex +++ b/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex @@ -1,11 +1,21 @@ Long lines can be replaced by ellipsis: + \begin{sh} $ for i in `seq 1 10`; do echo $i; done +1 +2 +... +10 \end{sh} \begin{ocaml} # for i = 1 to 10 do Printf.printf "%d\n%!" i; done;; +1 +2 +... +10 +- : unit = () \end{ocaml} \begin{sh} diff --git a/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.expected b/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.expected deleted file mode 100644 index 7378306cc..000000000 --- a/test/bin/mdx-test/expect-latex/ellipsis/test-case.tex.expected +++ /dev/null @@ -1,44 +0,0 @@ -Long lines can be replaced by ellipsis: - -\begin{sh} -$ for i in `seq 1 10`; do echo $i; done -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -\end{sh} - -\begin{ocaml} -# for i = 1 to 10 do Printf.printf "%d\n%!" i; done;; -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -- : unit = () -\end{ocaml} - -\begin{sh} -$ printf "foo\"\n\nbar" -foo" - -... -\end{sh} - -Lines ending with ellipsis - -\begin{sh} -$ echo Hello world -Hello... -\end{sh} diff --git a/test/bin/mdx-test/expect-latex/empty-line/test-case.tex b/test/bin/mdx-test/expect-latex/empty-line/test-case.tex new file mode 100644 index 000000000..40319a977 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/empty-line/test-case.tex @@ -0,0 +1,8 @@ +Testing empty line output + +\begin{ocaml} +# print_newline ();; +- : unit = () +# print_endline "";; +- : unit = () +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/empty-lines/test-case.tex b/test/bin/mdx-test/expect-latex/empty-lines/test-case.tex new file mode 100644 index 000000000..e4768ec87 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/empty-lines/test-case.tex @@ -0,0 +1,17 @@ +This shell block contains an empty line within a padded block: + +\begin{sh} + $ echo '' + +\end{sh} + +\begin{sh} + $ echo "Hello..." && echo "" && echo "world!" +\end{sh} + +This toplevel block contains an empty line within a padded block: + +\begin{ocaml} + # print_newline;; + +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/empty-lines/test-case.tex.expected b/test/bin/mdx-test/expect-latex/empty-lines/test-case.tex.expected new file mode 100644 index 000000000..ecf7e3a30 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/empty-lines/test-case.tex.expected @@ -0,0 +1,20 @@ +This shell block contains an empty line within a padded block: + +\begin{sh} + $ echo '' + +\end{sh} + +\begin{sh} + $ echo "Hello..." && echo "" && echo "world!" + Hello... + + world! +\end{sh} + +This toplevel block contains an empty line within a padded block: + +\begin{ocaml} + # print_newline;; + - : unit -> unit = +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/empty/test-case.tex b/test/bin/mdx-test/expect-latex/empty/test-case.tex new file mode 100644 index 000000000..45b0f2de7 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/empty/test-case.tex @@ -0,0 +1,26 @@ +Testing empty blocks + +\begin{sh} +\end{sh} + +\begin{foo} +\end{foo} + +% $MDX env=x +\begin{foo} +\end{foo} + +% $MDX skip +\begin{foo} +\end{foo} + +Empty lines are preserved: + +\begin{foo} + +\end{foo} + +% $MDX skip +\begin{foo} + +\end{foo} diff --git a/test/bin/mdx-test/expect-latex/env-and-prelude/a.ml b/test/bin/mdx-test/expect-latex/env-and-prelude/a.ml new file mode 100644 index 000000000..67bbe3ba8 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/env-and-prelude/a.ml @@ -0,0 +1 @@ +let a = 1 diff --git a/test/bin/mdx-test/expect-latex/env-and-prelude/all.ml b/test/bin/mdx-test/expect-latex/env-and-prelude/all.ml new file mode 100644 index 000000000..614ba0381 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/env-and-prelude/all.ml @@ -0,0 +1 @@ +let all = 1 diff --git a/test/bin/mdx-test/expect-latex/env-and-prelude/b.ml b/test/bin/mdx-test/expect-latex/env-and-prelude/b.ml new file mode 100644 index 000000000..95f7aae76 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/env-and-prelude/b.ml @@ -0,0 +1 @@ +let b = 1 diff --git a/test/bin/mdx-test/expect-latex/env-and-prelude/default.ml b/test/bin/mdx-test/expect-latex/env-and-prelude/default.ml new file mode 100644 index 000000000..6613cbf69 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/env-and-prelude/default.ml @@ -0,0 +1 @@ +let default = 1 diff --git a/test/bin/mdx-test/expect-latex/env-and-prelude/test-case.opts b/test/bin/mdx-test/expect-latex/env-and-prelude/test-case.opts new file mode 100644 index 000000000..1dc087f14 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/env-and-prelude/test-case.opts @@ -0,0 +1 @@ +--prelude all.ml --prelude " :default.ml" --prelude a:a.ml --prelude b:b.ml diff --git a/test/bin/mdx-test/expect-latex/env-and-prelude/test-case.tex b/test/bin/mdx-test/expect-latex/env-and-prelude/test-case.tex new file mode 100644 index 000000000..f97d9fc8a --- /dev/null +++ b/test/bin/mdx-test/expect-latex/env-and-prelude/test-case.tex @@ -0,0 +1,60 @@ +Different environments can have different preludes + +This is run with `--prelude all.ml --prelude " :default.ml" --prelude a:a.ml --prelude b:b.ml`. +Each of them defines a variable of the same name. + +\begin{ocaml} +# all;; +- : int = 1 +# default;; +- : int = 1 +# a;; +... +Error: Unbound value a +# b;; +... +Error: Unbound value b +\end{ocaml} + +% $MDX env=a +\begin{ocaml} +# all;; +- : int = 1 +# default;; +... +Error: Unbound value default +# a;; +- : int = 1 +# b;; +... +Error: Unbound value b +\end{ocaml} + +% $MDX env=b +\begin{ocaml} +# all;; +- : int = 1 +# default;; +... +Error: Unbound value default +# a;; +... +Error: Unbound value a +# b;; +- : int = 1 +\end{ocaml} + +% $MDX env=c +\begin{ocaml} +# all;; +- : int = 1 +# default;; +... +Error: Unbound value default +# a;; +... +Error: Unbound value a +# b;; +... +Error: Unbound value b +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/environment-variable-set/test-case.tex b/test/bin/mdx-test/expect-latex/environment-variable-set/test-case.tex new file mode 100644 index 000000000..aa4407ab7 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/environment-variable-set/test-case.tex @@ -0,0 +1,50 @@ +Environment variables can be loeaded in ocaml blocks + +# OCaml + +Environment variables can be loaded in an ocaml block environment. + +% $MDX set-FOO=bar,set-BAR=foo +\begin{ocaml} + # print_endline (Sys.getenv "FOO");; + bar + - : unit = () + # print_endline (Sys.getenv "BAR");; + foo + - : unit = () +\end{ocaml} + +And the variable stays available in subsequent blocks. + +\begin{ocaml} + # print_endline (Sys.getenv "FOO");; + bar + - : unit = () +\end{ocaml} + +# Sh/bash + +Environment variables can be loaded in an ocaml block environment. + +% $MDX set-FAR=boo,set-BOO=far +\begin{sh} + $ echo $FAR + boo + $ echo $BOO + far +\end{sh} + +And the variable stays available in subsequent blocks. + +\begin{sh} + $ echo $BOO + far +\end{sh} + +Environment variables can contain underscores + +% $MDX set-TWO_WORDS=success +\begin{sh} + $ echo $TWO_WORDS + success +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/environment-variable/test-case.tex b/test/bin/mdx-test/expect-latex/environment-variable/test-case.tex new file mode 100644 index 000000000..ef6868ccc --- /dev/null +++ b/test/bin/mdx-test/expect-latex/environment-variable/test-case.tex @@ -0,0 +1,19 @@ +Environment variable can also loaded in an environment + +% $MDX set-FOO=bar,set-BAR=foo +\begin{ocaml} + # print_endline (Sys.getenv "FOO");; + bar + - : unit = () + # print_endline (Sys.getenv "BAR");; + foo + - : unit = () +\end{ocaml} + +And the variable stays available in subsequent blocks + +\begin{ocaml} + # print_endline (Sys.getenv "FOO");; + bar + - : unit = () +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/envs/test-case.tex b/test/bin/mdx-test/expect-latex/envs/test-case.tex new file mode 100644 index 000000000..113d37bed --- /dev/null +++ b/test/bin/mdx-test/expect-latex/envs/test-case.tex @@ -0,0 +1,145 @@ +We can define separate environments for blocks. + +`x` holds the value `1` in the environment `e1`. + +% $MDX env=e1 +\begin{ocaml} +let x = 1;; +\end{ocaml} + +% $MDX env=e1 +\begin{ocaml} +module M = struct let k = 42 let f x = x * k end;; +\end{ocaml} + +`x` holds the value `3` in the environment `e2`. + +% $MDX env=e2 +\begin{ocaml} +let x = 3;; +\end{ocaml} + +We can retrieve the value of `x` in environment `e1`: + +% $MDX env=e1 +\begin{ocaml} +# print_int x;; +1 +- : unit = () +# print_int M.k;; +42 +- : unit = () +# M.f;; +- : int -> int = +\end{ocaml} + +More tests: +\begin{ocaml} +# let x = 42;; +val x : int = 42 +# type t1 = int;; +type t1 = int +\end{ocaml} + +% $MDX env=e1 +\begin{ocaml} +# let x = 1;; +val x : int = 1 +# type t1 = int;; +type t1 = int +\end{ocaml} + +\begin{ocaml} +# print_int x;; +42 +- : unit = () +# type t2 = t1;; +type t2 = t1 +\end{ocaml} + +% $MDX env=e1 +\begin{ocaml} +# print_int x;; +1 +- : unit = () +# type t2 = t1;; +type t2 = t1 +\end{ocaml} + +% $MDX version<4.08,env=e2 +\begin{ocaml} +# let x = 2;; +val x : int = 2 +# type t2 = int;; +type t2 = int +# type t3 = t1;; +Characters 10-12: +Error: Unbound type constructor t1 +\end{ocaml} + +% $MDX version>=4.08,env=e2 +\begin{ocaml} +# let x = 2;; +val x : int = 2 +# type t2 = int;; +type t2 = int +# type t3 = t1;; +Line 1, characters 11-13: +Error: Unbound type constructor t1 +\end{ocaml} + +\begin{ocaml} +# type t2 = t1;; +type t2 = t1 +# let (y : t1) = 4;; +val y : t2 = 4 +\end{ocaml} + +\begin{ocaml} +# type t3 = t2;; +type t3 = t2 +# print_int y;; +4 +- : unit = () +# let (x : t2) = 1;; +val x : t3 = 1 +# print_int x;; +1 +- : unit = () +# let (y : t3) = 2;; +val y : t3 = 2 +# print_int y;; +2 +- : unit = () +\end{ocaml} + +% $MDX version<4.08,env=e2 +\begin{ocaml} +# let (z : t2) = 32;; +val z : t2 = 32 +# print_int z;; +32 +- : unit = () +# let (d : t3) = 32;; +Characters 9-11: +Error: Unbound type constructor t3 +# print_int d;; +Characters 10-11: +Error: Unbound value d +\end{ocaml} + +% $MDX version>=4.08,env=e2 +\begin{ocaml} +# let (z : t3) = 32;; +Line 1, characters 10-12: +Error: Unbound type constructor t3 +# print_int z;; +Line 1, characters 11-12: +Error: Unbound value z +# let (d : t4) = 32;; +Line 1, characters 10-12: +Error: Unbound type constructor t4 +# print_int d;; +Line 1, characters 11-12: +Error: Unbound value d +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/errors/test-case.tex b/test/bin/mdx-test/expect-latex/errors/test-case.tex new file mode 100644 index 000000000..d8ac2b9d3 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/errors/test-case.tex @@ -0,0 +1,79 @@ +Errors should be well localized: + +% $MDX version<4.08 +\begin{ocaml} +# class ['a] stack init = object + val mutable v = init + + method pop = + match v with + | hd :: tl -> + v <- tl; + Some hd + | [] -> None + + method push hd = + v <- hd :: v + end;; +Characters 0-215: +Error: Some type variables are unbound in this type: + class ['a] stack : + 'b list -> + object + val mutable v : 'b list + method pop : 'b option + method push : 'b -> unit + end + The method pop has type 'b option where 'b is unbound +\end{ocaml} + +Hi! + + +% $MDX version=4.02 +\begin{ocaml} +# let x = + 1 + "42";; +Characters 14-18: +Error: This expression has type bytes but an expression was expected of type + int +\end{ocaml} + +% $MDX version=4.06 +\begin{ocaml} +# let x = + 1 + "42";; +Characters 14-18: +Error: This expression has type string but an expression was expected of type + int +\end{ocaml} + +% $MDX version=4.07 +\begin{ocaml} +# let x = + 1 + "42";; +Characters 14-18: +Error: This expression has type string but an expression was expected of type + int +\end{ocaml} + +% $MDX version>=4.08 +\begin{ocaml} +# let x = + 1 + "42";; +Line 2, characters 7-11: +Error: This expression has type string but an expression was expected of type + int +\end{ocaml} + +% $MDX non-deterministic=output +\begin{ocaml} +# raise Not_found;; +Exception: Not_found. +\end{ocaml} + +\begin{ocaml} +# print_endline "first"; failwith "second";; +first +Exception: Failure "second". +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/exit/test-case.tex b/test/bin/mdx-test/expect-latex/exit/test-case.tex new file mode 100644 index 000000000..9cd9ac504 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/exit/test-case.tex @@ -0,0 +1,13 @@ +Exit codes are updated properly: + + +\begin{sh} +$ exit 0 +\end{sh} + +\begin{sh} +$ exit 1 +[1] +$ exit 10 +[10] +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/heredoc/test-case.tex b/test/bin/mdx-test/expect-latex/heredoc/test-case.tex new file mode 100644 index 000000000..c2e394d31 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/heredoc/test-case.tex @@ -0,0 +1,26 @@ +Support for heredoc syntax: + +\begin{sh} +$ cat < hello\ +> world\ +> EOF +hello +world +$ echo foo +foo +\end{sh} + +And + +\begin{sh} +$ cat < foo \ +> hello\ +> world\ +> EOF +$ cat foo +hello +world +$ echo foo +foo +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/include-block/code.mli b/test/bin/mdx-test/expect-latex/include-block/code.mli new file mode 100644 index 000000000..a61369236 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/include-block/code.mli @@ -0,0 +1,3 @@ +type t + +val empty : t diff --git a/test/bin/mdx-test/expect-latex/include-block/dune b/test/bin/mdx-test/expect-latex/include-block/dune new file mode 100644 index 000000000..e69de29bb diff --git a/test/bin/mdx-test/expect-latex/include-block/test-case.tex b/test/bin/mdx-test/expect-latex/include-block/test-case.tex new file mode 100644 index 000000000..ecb082e25 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/include-block/test-case.tex @@ -0,0 +1,7 @@ +We include files with MDX comments: + +% $MDX file=code.mli + +% $MDX file=dune + +% $MDX file=../.ocamlformat diff --git a/test/bin/mdx-test/expect-latex/include-block/test-case.tex.expected b/test/bin/mdx-test/expect-latex/include-block/test-case.tex.expected new file mode 100644 index 000000000..f513e11bf --- /dev/null +++ b/test/bin/mdx-test/expect-latex/include-block/test-case.tex.expected @@ -0,0 +1,18 @@ +We include files with MDX comments: + +% $MDX file=code.mli +\begin{ocaml} +type t + +val empty : t +\end{ocaml} + +% $MDX file=dune +\begin{scheme} + +\end{scheme} + +% $MDX file=../.ocamlformat +\begin{} +disable=true +\end{} diff --git a/test/bin/mdx-test/expect-latex/labels-syntax/test-case.tex b/test/bin/mdx-test/expect-latex/labels-syntax/test-case.tex new file mode 100644 index 000000000..88304e08c --- /dev/null +++ b/test/bin/mdx-test/expect-latex/labels-syntax/test-case.tex @@ -0,0 +1,30 @@ +We are testing the new label syntax on some existing tests. + +# Set environment variables + +Environment variables can be loaded in an ocaml block environment. + +% $MDX set-FOO=bar,set-BAR=foo +\begin{ocaml} + # print_endline (Sys.getenv "FOO");; + bar + - : unit = () + # print_endline (Sys.getenv "BAR");; + foo + - : unit = () +\end{ocaml} + +### Non-deterministic Outputs + +% $MDX non-deterministic=output +\begin{sh} +$ echo $RANDOM +4150 +\end{sh} + +### Non-deterministic Commands + +% $MDX non-deterministic=command +\begin{sh} +$ touch toto +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/line-delimiters/include.ml b/test/bin/mdx-test/expect-latex/line-delimiters/include.ml new file mode 100644 index 000000000..44ae61358 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/line-delimiters/include.ml @@ -0,0 +1,4 @@ +(* $MDX part-begin=something *) +type t = + | Foo + | Bar (* $MDX part-end *) diff --git a/test/bin/mdx-test/expect-latex/line-delimiters/test-case.tex b/test/bin/mdx-test/expect-latex/line-delimiters/test-case.tex new file mode 100644 index 000000000..0079a04bf --- /dev/null +++ b/test/bin/mdx-test/expect-latex/line-delimiters/test-case.tex @@ -0,0 +1,6 @@ +% $MDX file=include.ml,part=something +\begin{ocaml} +type t = + | Foo + | Bar +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/lines/test-case.tex b/test/bin/mdx-test/expect-latex/lines/test-case.tex new file mode 100644 index 000000000..cdf824241 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/lines/test-case.tex @@ -0,0 +1,73 @@ +Testing lines directives + +\begin{ocaml} +let f x = + x+x + +x +\end{ocaml} + +And + +% $MDX version=4.02 +\begin{ocaml} +# let f x = x + 1;; +val f : int -> int = +# let f y = + y^"foo";; +val f : bytes -> bytes = +\end{ocaml} + +% $MDX version>=4.06 +\begin{ocaml} +# let f x = x + 1;; +val f : int -> int = +# let f y = + y^"foo";; +val f : string -> string = +\end{ocaml} + +And + +% $MDX version=4.02 +\begin{ocaml} +# let f x = function + | 0 -> 1 + | n -> + n + "foo";; +Characters 45-50: +Error: This expression has type bytes but an expression was expected of type + int +\end{ocaml} + +% $MDX version=4.06 +\begin{ocaml} +# let f x = function + | 0 -> 1 + | n -> + n + "foo";; +Characters 45-50: +Error: This expression has type string but an expression was expected of type + int +\end{ocaml} + +% $MDX version=4.07 +\begin{ocaml} +# let f x = function + | 0 -> 1 + | n -> + n + "foo";; +Characters 45-50: +Error: This expression has type string but an expression was expected of type + int +\end{ocaml} + +% $MDX version>=4.08 +\begin{ocaml} +# let f x = function + | 0 -> 1 + | n -> + n + "foo";; +Line 4, characters 7-12: +Error: This expression has type string but an expression was expected of type + int +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/lwt/test-case.tex b/test/bin/mdx-test/expect-latex/lwt/test-case.tex new file mode 100644 index 000000000..2a89a3520 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/lwt/test-case.tex @@ -0,0 +1,16 @@ +#require directives work as expected: + +\begin{ocaml} +# #require "lwt";; +# let x = Lwt.return 3;; +val x : int Lwt.t = +\end{ocaml} + +Top-level `Lwt` values are automatically evaluated with `Lwt_main.run`: + +\begin{ocaml} +# Lwt.return 4;; +- : int = 4 +# Lwt_list.map_p Lwt.return [1;2;3];; +- : int list = [1; 2; 3] +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/mlt/test-case.tex b/test/bin/mdx-test/expect-latex/mlt/test-case.tex new file mode 100644 index 000000000..3b90c9f92 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/mlt/test-case.tex @@ -0,0 +1,45 @@ +Mdx can also understand ocaml code blocks: + +% $MDX version=4.02 +\begin{ocaml} +# #require "fmt";; +# let x = 3;; +val x : int = 3 +# x + "foo";; +Characters 4-9: +Error: This expression has type bytes but an expression was expected of type + int +\end{ocaml} + +% $MDX version=4.06 +\begin{ocaml} +# #require "fmt";; +# let x = 3;; +val x : int = 3 +# x + "foo";; +Characters 4-9: +Error: This expression has type string but an expression was expected of type + int +\end{ocaml} + +% $MDX version=4.07 +\begin{ocaml} +# #require "fmt";; +# let x = 3;; +val x : int = 3 +# x + "foo";; +Characters 4-9: +Error: This expression has type string but an expression was expected of type + int +\end{ocaml} + +% $MDX version>=4.08 +\begin{ocaml} +# #require "fmt";; +# let x = 3;; +val x : int = 3 +# x + "foo";; +Line 1, characters 5-10: +Error: This expression has type string but an expression was expected of type + int +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/multilines/test-case.tex b/test/bin/mdx-test/expect-latex/multilines/test-case.tex new file mode 100644 index 000000000..a78fd677b --- /dev/null +++ b/test/bin/mdx-test/expect-latex/multilines/test-case.tex @@ -0,0 +1,37 @@ +Test multi-lines shell commands: + +\begin{sh} +$ for i in `seq 1 10`; do \ +> echo $i; \ +> done +1 +... +10 +\end{sh} + +This works trivially for normal OCaml fragments: + +\begin{ocaml} +let rec fact = function +| 1 -> 1 +| n -> n * fact (n-1) +\end{ocaml} + +And it should work fine for toplevel too: + +\begin{ocaml} +# let rec fact = function + | 1 -> 1 + | n -> n * fact (n-1) + ;; +val fact : int -> int = +\end{ocaml} + +\begin{ocaml} +# print_string "foo \ + \" \ + toto\ + \ bar\"";; +foo " toto bar" +- : unit = () +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/non-det-default-preserved/test-case.tex b/test/bin/mdx-test/expect-latex/non-det-default-preserved/test-case.tex new file mode 100644 index 000000000..616a42af5 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/non-det-default-preserved/test-case.tex @@ -0,0 +1,7 @@ +When using the `non-deterministic` label in default mode +(i.e. without passing a value), mdx should preserve that in the output. + +% $MDX non-deterministic +\begin{sh} +$ echo "paf" +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/non-det/test-case.tex b/test/bin/mdx-test/expect-latex/non-det/test-case.tex new file mode 100644 index 000000000..924a7595a --- /dev/null +++ b/test/bin/mdx-test/expect-latex/non-det/test-case.tex @@ -0,0 +1,56 @@ +`ocaml-mdx` supports non-determinitic code blocks. + +There are two kinds of blocks: + +### Non-deterministic Outputs + +Code blocks with `non-deterministic=output` have their command always +executed but their output is never checked, unless `--non-deterministic` +is passed as argument to `ocaml-mdx`. + + +% $MDX non-deterministic=output +\begin{sh} +$ echo $RANDOM +4150 +\end{sh} + +% $MDX non-deterministic=output +\begin{ocaml} +# Random.self_init (); Random.int 42;; +0 +\end{ocaml} + +Check that the command are always executed: + +% $MDX non-deterministic=output +\begin{sh} +$ touch hello-world +\end{sh} + +\begin{ocaml} +# Sys.file_exists "hello-world";; +- : bool = true +\end{ocaml} + +### Non-deterministic Commands + +Code blocks with `non-deterministic=command` are never executed unless +`--non-deterministic` is passed as argument to `ocaml-mdx`. + +% $MDX non-deterministic=command +\begin{sh} +$ touch toto +\end{sh} + +\begin{sh} +$ touch bar +\end{sh} + + +\begin{ocaml} +# Sys.file_exists "toto";; +- : bool = false +# Sys.file_exists "bar";; +- : bool = true +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/ocaml-408-syntax/test-case.tex b/test/bin/mdx-test/expect-latex/ocaml-408-syntax/test-case.tex new file mode 100644 index 000000000..6a3b51486 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/ocaml-408-syntax/test-case.tex @@ -0,0 +1,7 @@ +% $MDX version>=4.08 +\begin{ocaml} +let (let*) a f = f a +let test ma f = + let* s = ma in + f s +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/ocaml-errors-ellipsis/test-case.tex b/test/bin/mdx-test/expect-latex/ocaml-errors-ellipsis/test-case.tex new file mode 100644 index 000000000..ae61a236c --- /dev/null +++ b/test/bin/mdx-test/expect-latex/ocaml-errors-ellipsis/test-case.tex @@ -0,0 +1,23 @@ +It is possible to use ellipsis (`...`) in the error blocks attached to OCaml blocks, here it is useful as the error message depends on the OCaml version: + +\begin{ocaml} +module Counter: Irmin.Contents.S with type t = int64 = struct + type t = int64 + let t = Irmin.Type.int64 +\end{ocaml} +\begin{mdx-error} +... +Error: Syntax error: 'end' expected +... +\end{mdx-error} + +\begin{ocaml} +module Counter: Irmin.Contents.S with type t = int64 = struct + type t = int64 + let t = Irmin.Type.int64 +end +\end{ocaml} +\begin{mdx-error} +... +Error: Unbound module Irmin +\end{mdx-error} diff --git a/test/bin/mdx-test/expect-latex/ocaml-errors/test-case.tex b/test/bin/mdx-test/expect-latex/ocaml-errors/test-case.tex new file mode 100644 index 000000000..a4de7dc82 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/ocaml-errors/test-case.tex @@ -0,0 +1,52 @@ +The errors raised when evaluating OCaml blocks are displayed in a `mdx-error` block, that is immediately following the `ocaml` block it is attached to: + + +% $MDX version<4.08 +\begin{ocaml} +module Counter: Irmin.Contents.S with type t = int64 = struct + type t = int64 + let t = Irmin.Type.int64 +\end{ocaml} +\begin{mdx-error} +Characters 112-112: +Error: Syntax error: 'end' expected +Characters 55-61: +Error: This 'struct' might be unmatched +\end{mdx-error} + + +% $MDX version>=4.08 +\begin{ocaml} +module Counter: Irmin.Contents.S with type t = int64 = struct + type t = int64 + let t = Irmin.Type.int64 +\end{ocaml} +\begin{mdx-error} +Line 4, characters 3-3: +Error: Syntax error: 'end' expected +Line 1, characters 56-62: + This 'struct' might be unmatched +\end{mdx-error} + + +If no error is raised, no error block must be attached: + +\begin{ocaml} +module Counter = struct + type t = int64 +end +\end{ocaml} + +Existing error blocks attached to a valid ocaml block are removed: + +\begin{ocaml} +module Counter = struct + type t = int64 +end +\end{ocaml} +\begin{mdx-error} +Line 4, characters 3-3: +Error: Syntax error: 'end' expected +Line 1, characters 56-62: + This 'struct' might be unmatched +\end{mdx-error} diff --git a/test/bin/mdx-test/expect-latex/ocaml-errors/test-case.tex.expected b/test/bin/mdx-test/expect-latex/ocaml-errors/test-case.tex.expected new file mode 100644 index 000000000..bad7c79c2 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/ocaml-errors/test-case.tex.expected @@ -0,0 +1,46 @@ +The errors raised when evaluating OCaml blocks are displayed in a `mdx-error` block, that is immediately following the `ocaml` block it is attached to: + + +% $MDX version<4.08 +\begin{ocaml} +module Counter: Irmin.Contents.S with type t = int64 = struct + type t = int64 + let t = Irmin.Type.int64 +\end{ocaml} +\begin{mdx-error} +Characters 112-112: +Error: Syntax error: 'end' expected +Characters 55-61: +Error: This 'struct' might be unmatched +\end{mdx-error} + + +% $MDX version>=4.08 +\begin{ocaml} +module Counter: Irmin.Contents.S with type t = int64 = struct + type t = int64 + let t = Irmin.Type.int64 +\end{ocaml} +\begin{mdx-error} +Line 4, characters 3-3: +Error: Syntax error: 'end' expected +Line 1, characters 56-62: + This 'struct' might be unmatched +\end{mdx-error} + + +If no error is raised, no error block must be attached: + +\begin{ocaml} +module Counter = struct + type t = int64 +end +\end{ocaml} + +Existing error blocks attached to a valid ocaml block are removed: + +\begin{ocaml} +module Counter = struct + type t = int64 +end +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/padding/test-case.tex b/test/bin/mdx-test/expect-latex/padding/test-case.tex new file mode 100644 index 000000000..ed41149d5 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/padding/test-case.tex @@ -0,0 +1,23 @@ +Arbitrary padding is allowed, as long as it is consistent inside a code block. + +\begin{sh} + $ echo foo + foo +\end{sh} + +\begin{ocaml} + # let x = 3;; + val x : int = 3 +\end{ocaml} + +% $MDX version<4.12 +\begin{sh} +$ ocaml -warn-help | grep -E '\b9 Missing\b' + 9 Missing fields in a record pattern. +\end{sh} + +% $MDX version>=4.12 +\begin{sh} +$ ocaml -warn-help | grep -E '\b9 \[missing-record-field-pattern\] Missing\b' + 9 [missing-record-field-pattern] Missing fields in a record pattern. +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/parts-begin-end/parts-begin-end.ml b/test/bin/mdx-test/expect-latex/parts-begin-end/parts-begin-end.ml new file mode 100644 index 000000000..aed2be64d --- /dev/null +++ b/test/bin/mdx-test/expect-latex/parts-begin-end/parts-begin-end.ml @@ -0,0 +1,36 @@ +let () = + (); + () +;; + +(* $MDX part-begin=toto *) +let x = 34 +let f = 42.3 +let s = "toto" +let f x u = u x + +let () = + print_int x; + print_float f +;; + +(* $MDX part-end *) +p +(* $MDX part-begin=z_zz *) +let () = + print_string s +;; + +(* $MDX part-end *) +(* $MDX part-begin=4-2 *) + +let () = + f x print_int; +(* $MDX part-end *) + () + +let () = +(* $MDX part-begin=indented *) + let () = fooooooooooooooooooooooooooooooooooooooooooo in + if not fooooooooo then foooooooooooo +(* $MDX part-end *) diff --git a/test/bin/mdx-test/expect-latex/parts-begin-end/test-case.tex b/test/bin/mdx-test/expect-latex/parts-begin-end/test-case.tex new file mode 100644 index 000000000..d8cdc66b0 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/parts-begin-end/test-case.tex @@ -0,0 +1,40 @@ +Mdx can also understand ocaml code blocks: + + +% $MDX file=parts-begin-end.ml,part=toto +\begin{ocaml} +# let x = 3;; +val x : int = 3 +# let y = 4;; +val y : int = 4 +# print_int x;; +3 +- : unit = () +# print_int y;; +4 +- : unit = () +\end{ocaml} + +% $MDX file=parts-begin-end.ml,part=z_zz +\begin{ocaml} +\end{ocaml} + +% $MDX file=parts-begin-end.ml,part=4-2 +\begin{ocaml} +\end{ocaml} + +% $MDX file=parts-begin-end.ml +\begin{ocaml} +\end{ocaml} + +\begin{ocaml} +# let x = 2;; +val x : int = 2 +# print_int x;; +3 +- : unit = () +\end{ocaml} + +% $MDX file=parts-begin-end.ml,part=indented +\begin{ocaml} +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/parts-begin-end/test-case.tex.expected b/test/bin/mdx-test/expect-latex/parts-begin-end/test-case.tex.expected new file mode 100644 index 000000000..6dc4e9fc4 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/parts-begin-end/test-case.tex.expected @@ -0,0 +1,74 @@ +Mdx can also understand ocaml code blocks: + + +% $MDX file=parts-begin-end.ml,part=toto +\begin{ocaml} +let x = 34 +let f = 42.3 +let s = "toto" +let f x u = u x + +let () = + print_int x; + print_float f +;; +\end{ocaml} + +% $MDX file=parts-begin-end.ml,part=z_zz +\begin{ocaml} +let () = + print_string s +;; +\end{ocaml} + +% $MDX file=parts-begin-end.ml,part=4-2 +\begin{ocaml} +let () = + f x print_int; +\end{ocaml} + +% $MDX file=parts-begin-end.ml +\begin{ocaml} +let () = + (); + () +;; + +let x = 34 +let f = 42.3 +let s = "toto" +let f x u = u x + +let () = + print_int x; + print_float f +;; + +p +let () = + print_string s +;; + + +let () = + f x print_int; + () + +let () = + let () = fooooooooooooooooooooooooooooooooooooooooooo in + if not fooooooooo then foooooooooooo +\end{ocaml} + +\begin{ocaml} +# let x = 2;; +val x : int = 2 +# print_int x;; +2 +- : unit = () +\end{ocaml} + +% $MDX file=parts-begin-end.ml,part=indented +\begin{ocaml} + let () = fooooooooooooooooooooooooooooooooooooooooooo in + if not fooooooooo then foooooooooooo +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/prelude-file/prelude.ml b/test/bin/mdx-test/expect-latex/prelude-file/prelude.ml new file mode 100644 index 000000000..86aed4936 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/prelude-file/prelude.ml @@ -0,0 +1,8 @@ +#require "fmt";; + +let x = + 2 + +let y = 4 + +let time f = f () diff --git a/test/bin/mdx-test/expect-latex/prelude-file/test-case.opts b/test/bin/mdx-test/expect-latex/prelude-file/test-case.opts new file mode 100644 index 000000000..f90cfc1ea --- /dev/null +++ b/test/bin/mdx-test/expect-latex/prelude-file/test-case.opts @@ -0,0 +1 @@ +--prelude prelude.ml diff --git a/test/bin/mdx-test/expect-latex/prelude-file/test-case.tex b/test/bin/mdx-test/expect-latex/prelude-file/test-case.tex new file mode 100644 index 000000000..2e740c64b --- /dev/null +++ b/test/bin/mdx-test/expect-latex/prelude-file/test-case.tex @@ -0,0 +1,18 @@ +Prelude can also be in a file + +# A Guided Tour + +% $MDX env=toto +\begin{ocaml} +# raise Not_found;; +Exception: Not_found. +\end{ocaml} + +\begin{ocaml} +# print_int x;; +2 +- : unit = () +# print_int y;; +4 +- : unit = () +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/prelude/prelude.ml b/test/bin/mdx-test/expect-latex/prelude/prelude.ml new file mode 100644 index 000000000..86aed4936 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/prelude/prelude.ml @@ -0,0 +1,8 @@ +#require "fmt";; + +let x = + 2 + +let y = 4 + +let time f = f () diff --git a/test/bin/mdx-test/expect-latex/prelude/test-case.opts b/test/bin/mdx-test/expect-latex/prelude/test-case.opts new file mode 100644 index 000000000..c1f953c68 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/prelude/test-case.opts @@ -0,0 +1,2 @@ +--prelude-str "#require \"lwt\"" +--prelude-str "toto:let x = \"42\"" diff --git a/test/bin/mdx-test/expect-latex/prelude/test-case.tex b/test/bin/mdx-test/expect-latex/prelude/test-case.tex new file mode 100644 index 000000000..1125eee5b --- /dev/null +++ b/test/bin/mdx-test/expect-latex/prelude/test-case.tex @@ -0,0 +1,30 @@ +`ocaml-mdx test` can also take a prelude file. + +\begin{ocaml} +# Lwt.return 4;; +- : int = 4 +\end{ocaml} + +It's possible to load a prelude only in a specific environment using +`--prelude=toto:prelude.ml`: + +% $MDX env=toto +\begin{ocaml} +# print_endline x;; +42 +- : unit = () +\end{ocaml} + +% $MDX version<4.08 +\begin{ocaml} +# print_endline x;; +Characters 14-15: +Error: Unbound value x +\end{ocaml} + +% $MDX version>=4.08 +\begin{ocaml} +# print_endline x;; +Line 1, characters 15-16: +Error: Unbound value x +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/requires/test-case.tex b/test/bin/mdx-test/expect-latex/requires/test-case.tex new file mode 100644 index 000000000..cb6f45ce2 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/requires/test-case.tex @@ -0,0 +1,7 @@ +Testing requires directives + +\begin{ocaml} +# #require "astring";; +# #require "foo";; +No such package: foo +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/root-option/somedir/.gitignore b/test/bin/mdx-test/expect-latex/root-option/somedir/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/test/bin/mdx-test/expect-latex/root-option/test-case.opts b/test/bin/mdx-test/expect-latex/root-option/test-case.opts new file mode 100644 index 000000000..d1ba734fa --- /dev/null +++ b/test/bin/mdx-test/expect-latex/root-option/test-case.opts @@ -0,0 +1 @@ +--root=somedir diff --git a/test/bin/mdx-test/expect-latex/root-option/test-case.tex b/test/bin/mdx-test/expect-latex/root-option/test-case.tex new file mode 100644 index 000000000..814727841 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/root-option/test-case.tex @@ -0,0 +1,6 @@ +It's possible to run cram tests in separate directories: + +\begin{sh} +$ basename $(pwd) +somedir +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/shell-file-inc/script.sh b/test/bin/mdx-test/expect-latex/shell-file-inc/script.sh new file mode 100644 index 000000000..c2064c476 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/shell-file-inc/script.sh @@ -0,0 +1 @@ +$ sudo chmod a-x /usr diff --git a/test/bin/mdx-test/expect-latex/shell-file-inc/test-case.tex b/test/bin/mdx-test/expect-latex/shell-file-inc/test-case.tex new file mode 100644 index 000000000..e835f3d58 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/shell-file-inc/test-case.tex @@ -0,0 +1,6 @@ +Mdx can include text from any file: + + +% $MDX file=script.sh +\begin{sh} +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/shell-file-inc/test-case.tex.expected b/test/bin/mdx-test/expect-latex/shell-file-inc/test-case.tex.expected new file mode 100644 index 000000000..6cc62e702 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/shell-file-inc/test-case.tex.expected @@ -0,0 +1,7 @@ +Mdx can include text from any file: + + +% $MDX file=script.sh +\begin{sh} +$ sudo chmod a-x /usr +\end{sh} diff --git a/test/bin/mdx-test/expect-latex/spaces/test-case.tex b/test/bin/mdx-test/expect-latex/spaces/test-case.tex new file mode 100644 index 000000000..9c50e536c --- /dev/null +++ b/test/bin/mdx-test/expect-latex/spaces/test-case.tex @@ -0,0 +1,29 @@ +Mdx test should preserve empty lines in code blocks + +\begin{ocaml} + + +let x = + + 5 + +\end{ocaml} + +\begin{ocaml} + +# let x = 1 + + in x;; +- : int = 1 + + +# 3;; +- : int = 3 + + +# Printf.printf "foo\n\nbar\n";; +foo + +bar +- : unit = () +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/sync-from-subdir/some_dir/some_module.ml b/test/bin/mdx-test/expect-latex/sync-from-subdir/some_dir/some_module.ml new file mode 100644 index 000000000..a2f9b34db --- /dev/null +++ b/test/bin/mdx-test/expect-latex/sync-from-subdir/some_dir/some_module.ml @@ -0,0 +1,4 @@ +let _ = "Do not include me" + +[@@@part "1"] +let _ = "Include me" diff --git a/test/bin/mdx-test/expect-latex/sync-from-subdir/test-case.tex b/test/bin/mdx-test/expect-latex/sync-from-subdir/test-case.tex new file mode 100644 index 000000000..6062bb9fb --- /dev/null +++ b/test/bin/mdx-test/expect-latex/sync-from-subdir/test-case.tex @@ -0,0 +1,5 @@ +You can sync files from subdirs: + +% $MDX file=some_dir/some_module.ml,part=1 +\begin{ocaml} +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/sync-from-subdir/test-case.tex.expected b/test/bin/mdx-test/expect-latex/sync-from-subdir/test-case.tex.expected new file mode 100644 index 000000000..0238e163a --- /dev/null +++ b/test/bin/mdx-test/expect-latex/sync-from-subdir/test-case.tex.expected @@ -0,0 +1,6 @@ +You can sync files from subdirs: + +% $MDX file=some_dir/some_module.ml,part=1 +\begin{ocaml} +let _ = "Include me" +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/sync-to-md/sync_to_md.ml b/test/bin/mdx-test/expect-latex/sync-to-md/sync_to_md.ml new file mode 100644 index 000000000..a588699c1 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/sync-to-md/sync_to_md.ml @@ -0,0 +1,27 @@ +let () = + (); + () +;; + +[@@@part "toto"];; + +let x = 34 +let f = 42.3 +let s = "toto" +let f x u = u x + +let () = + print_int x; + print_float f +;; + +[@@@part "zzz"];; + +let () = + print_string s +;; + +[@@@part "42"];; + +let () = + f x print_int diff --git a/test/bin/mdx-test/expect-latex/sync-to-md/test-case.opts b/test/bin/mdx-test/expect-latex/sync-to-md/test-case.opts new file mode 100644 index 000000000..e69de29bb diff --git a/test/bin/mdx-test/expect-latex/sync-to-md/test-case.tex b/test/bin/mdx-test/expect-latex/sync-to-md/test-case.tex new file mode 100644 index 000000000..99063ca9f --- /dev/null +++ b/test/bin/mdx-test/expect-latex/sync-to-md/test-case.tex @@ -0,0 +1,40 @@ +Mdx can also understand ocaml code blocks: + + +% $MDX file=sync_to_md.ml,part=toto +\begin{ocaml} +# let x = 3;; +val x : int = 3 +# let y = 4;; +val y : int = 4 +# print_int x;; +3 +- : unit = () +# print_int y;; +4 +- : unit = () +\end{ocaml} + +% $MDX file=sync_to_md.ml,part=zzz +\begin{ocaml} +\end{ocaml} + +% $MDX file=sync_to_md.ml,part=42 +\begin{ocaml} +\end{ocaml} + +% $MDX file=sync_to_md.ml,part= +\begin{ocaml} +\end{ocaml} + +% $MDX file=sync_to_md.ml +\begin{ocaml} +\end{ocaml} + +\begin{ocaml} +# let x = 2;; +val x : int = 2 +# print_int x;; +3 +- : unit = () +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/sync-to-md/test-case.tex.expected b/test/bin/mdx-test/expect-latex/sync-to-md/test-case.tex.expected new file mode 100644 index 000000000..cadaeeec6 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/sync-to-md/test-case.tex.expected @@ -0,0 +1,69 @@ +Mdx can also understand ocaml code blocks: + + +% $MDX file=sync_to_md.ml,part=toto +\begin{ocaml} +let x = 34 +let f = 42.3 +let s = "toto" +let f x u = u x + +let () = + print_int x; + print_float f +;; +\end{ocaml} + +% $MDX file=sync_to_md.ml,part=zzz +\begin{ocaml} +let () = + print_string s +;; +\end{ocaml} + +% $MDX file=sync_to_md.ml,part=42 +\begin{ocaml} +let () = + f x print_int +\end{ocaml} + +% $MDX file=sync_to_md.ml,part= +\begin{ocaml} +let () = + (); + () +;; +\end{ocaml} + +% $MDX file=sync_to_md.ml +\begin{ocaml} +let () = + (); + () +;; + +let x = 34 +let f = 42.3 +let s = "toto" +let f x u = u x + +let () = + print_int x; + print_float f +;; + +let () = + print_string s +;; + +let () = + f x print_int +\end{ocaml} + +\begin{ocaml} +# let x = 2;; +val x : int = 2 +# print_int x;; +2 +- : unit = () +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/tabs/test-case.tex b/test/bin/mdx-test/expect-latex/tabs/test-case.tex new file mode 100644 index 000000000..0b09f7647 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/tabs/test-case.tex @@ -0,0 +1,8 @@ +Code indented using tabulations will be reindented using spaces: + +\begin{ocaml} +# let foo = + let bar = 14 in + [ bar ];; +val foo : int list = [14] +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/tabs/test-case.tex.expected b/test/bin/mdx-test/expect-latex/tabs/test-case.tex.expected new file mode 100644 index 000000000..57ab9d648 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/tabs/test-case.tex.expected @@ -0,0 +1,8 @@ +Code indented using tabulations will be reindented using spaces: + +\begin{ocaml} +# let foo = + let bar = 14 in + [ bar ];; +val foo : int list = [14] +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/toploop-getvalue/test-case.tex b/test/bin/mdx-test/expect-latex/toploop-getvalue/test-case.tex new file mode 100644 index 000000000..1277280c1 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/toploop-getvalue/test-case.tex @@ -0,0 +1,16 @@ +Mdx used to fail with module aliases and includes. This is a regression test to +ensure nothing breaks again in the future. + +\begin{ocaml} +# module Test = String;; +module Test = String +\end{ocaml} + +\begin{ocaml} +# include struct module M = struct type t end end;; +module M : sig type t end +\end{ocaml} + +The bug was caused by an attempt to load the newly created module without +checking if it was supposed to be in the store (advertised by the +`module_presence` type), or without using the correct name. diff --git a/test/bin/mdx-test/expect-latex/trailing-whitespaces/test-case.tex b/test/bin/mdx-test/expect-latex/trailing-whitespaces/test-case.tex new file mode 100644 index 000000000..35ecbe359 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/trailing-whitespaces/test-case.tex @@ -0,0 +1,21 @@ +# Remove trailing whitespace from output lines + +\begin{ocaml} +# let x = 13;; +val x : int = 13 +\end{ocaml} + +\begin{sh} +$ echo "bob " +bob +\end{sh} + +Also, it should be valid to terminate phrases that end with `;;` but have +trailing whitespace: + +\begin{ocaml} +# let terminated_with_space = 42;; +val terminated_with_space : int = 42 +# let terminated_with_tab = 42;; +val terminated_with_tab : int = 42 +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/trailing-whitespaces/test-case.tex.expected b/test/bin/mdx-test/expect-latex/trailing-whitespaces/test-case.tex.expected new file mode 100644 index 000000000..256a805b7 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/trailing-whitespaces/test-case.tex.expected @@ -0,0 +1,21 @@ +# Remove trailing whitespace from output lines + +\begin{ocaml} +# let x = 13;; +val x : int = 13 +\end{ocaml} + +\begin{sh} +$ echo "bob " +bob +\end{sh} + +Also, it should be valid to terminate phrases that end with `;;` but have +trailing whitespace: + +\begin{ocaml} +# let terminated_with_space = 42;; +val terminated_with_space : int = 42 +# let terminated_with_tab = 42;; +val terminated_with_tab : int = 42 +\end{ocaml} diff --git a/test/bin/mdx-test/expect-latex/warnings/test-case.tex b/test/bin/mdx-test/expect-latex/warnings/test-case.tex new file mode 100644 index 000000000..0acf82ce0 --- /dev/null +++ b/test/bin/mdx-test/expect-latex/warnings/test-case.tex @@ -0,0 +1,33 @@ +No warning is printed by default: + +\begin{ocaml} +type p = { x : int ; y : int } + +let x { x } = x +\end{ocaml} + +Warning attributes must be set to print them: + +% $MDX version<4.12 +\begin{ocaml} +[@@@warning "+9"] +let x { x } = x +\end{ocaml} +\begin{mdx-error} +... +Warning 9: the following labels are not bound in this record pattern: +y +Either bind these labels explicitly or add '; _' to the pattern. +\end{mdx-error} + +% $MDX version>=4.12 +\begin{ocaml} +[@@@warning "+9"] +let x { x } = x +\end{ocaml} +\begin{mdx-error} +Line 2, characters 9-14: +Warning 9 [missing-record-field-pattern]: the following labels are not bound in this record pattern: +y +Either bind these labels explicitly or add '; _' to the pattern. +\end{mdx-error}