Skip to content

Commit 74054d0

Browse files
authored
Merge pull request #147 from mbarbin/use-mdexp
Use mdexp
2 parents 3922f41 + a053842 commit 74054d0

File tree

10 files changed

+169
-16
lines changed

10 files changed

+169
-16
lines changed

dune-project

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
(documentation "https://mbarbin.github.io/vcs/")
1717

18-
(using mdx 0.4)
1918

2019
;; The value for the [implicit_transitive_deps] option is set during the CI
2120
;; depending on the OCaml compiler version.
@@ -398,8 +397,6 @@
398397
(>= 1.3.0))
399398
conf-git
400399
conf-hg
401-
(mdx
402-
(>= 2.4))
403400
(ppx_js_style
404401
(>= v0.17))
405402
(ppxlib

dunolint

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@
2525
(equals volgo-base-tests))
2626
(name
2727
(equals volgo_base_test)))))))
28+
((path
29+
(glob test/toplevel/**))
30+
(enforce
31+
(dune
32+
(library
33+
(and
34+
(not
35+
(has_field public_name))
36+
(has_field inline_tests)
37+
(package
38+
(equals volgo-dev))
39+
(name
40+
(equals volgo_toplevel_test)))))))
2841
((path
2942
(or
3043
(glob test/**)

test/toplevel/dune

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
1-
(mdx
1+
(toplevel
2+
(name volgo_toplevel)
3+
(libraries volgo))
4+
5+
(library
6+
(name volgo_toplevel_test)
27
(package volgo-dev)
3-
(deps
4-
(package volgo)
5-
(package volgo-tests))
6-
(preludes prelude.txt))
8+
(inline_tests
9+
(deps volgo_toplevel.exe))
10+
(flags
11+
:standard
12+
-w
13+
+a-4-40-41-42-44-45-48-66
14+
-warn-error
15+
+a
16+
-open
17+
Volgo_stdlib)
18+
(libraries unix volgo_stdlib)
19+
(instrumentation
20+
(backend bisect_ppx))
21+
(lint
22+
(pps ppx_js_style -allow-let-operators -check-doc-comments))
23+
(preprocess
24+
(pps ppx_expect)))
25+
26+
(rule
27+
(package volgo-dev)
28+
(enabled_if %{bin-available:mdexp})
29+
(target process_output.md.gen)
30+
(deps process_output.ml)
31+
(action
32+
(with-stdout-to
33+
%{target}
34+
(run mdexp pp %{deps}))))
35+
36+
(rule
37+
(package volgo-dev)
38+
(enabled_if %{bin-available:mdexp})
39+
(alias runtest)
40+
(action
41+
(diff process_output.md process_output.md.gen)))

test/toplevel/ocaml_toplevel.ml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
(*********************************************************************************)
2+
(* Volgo - A Versatile OCaml Library for Git Operations *)
3+
(* SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
4+
(* SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
5+
(*********************************************************************************)
6+
7+
module Unix = UnixLabels
8+
9+
let toplevel_exe = "./volgo_toplevel.exe"
10+
11+
let eval ~code =
12+
let code = String.trim code in
13+
print_endline "```ocaml";
14+
print_endline code;
15+
print_endline "```";
16+
print_endline "";
17+
print_endline "```terminal";
18+
let cmd = toplevel_exe ^ " -noprompt -no-version -color always" in
19+
let ic, oc, ec = Unix.open_process_full cmd ~env:[||] in
20+
output_string oc code;
21+
output_char oc '\n';
22+
close_out oc;
23+
let stdout_content = In_channel.input_all ic in
24+
let stderr_content = In_channel.input_all ec in
25+
let status = Unix.close_process_full (ic, oc, ec) in
26+
let stdout_trimmed = String.trim stdout_content in
27+
if not (String.is_empty stdout_trimmed) then print_endline stdout_trimmed;
28+
let stderr_trimmed = String.trim stderr_content in
29+
if not (String.is_empty stderr_trimmed)
30+
then print_endline stderr_trimmed [@coverage off];
31+
(match status with
32+
| WEXITED 0 -> ()
33+
| _ ->
34+
(match[@coverage off] status with
35+
| WEXITED n -> Printf.printf "[%d]\n" n
36+
| WSIGNALED n -> Printf.printf "[signal %d]\n" n
37+
| WSTOPPED n -> Printf.printf "[stopped %d]\n" n));
38+
print_endline "```"
39+
;;

test/toplevel/ocaml_toplevel.mli

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(*_********************************************************************************)
2+
(*_ Volgo - A Versatile OCaml Library for Git Operations *)
3+
(*_ SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
4+
(*_ SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
5+
(*_********************************************************************************)
6+
7+
val eval : code:string -> unit

test/toplevel/prelude.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/toplevel/process_output.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
# Process output
22

3-
This test monitors that the types to manipulate the output of the `git` and `hg` processes are not unifiable, for the purpose of added type safety.
3+
This test monitors that the types to manipulate the output of the `git` and
4+
`hg` processes are not unifiable, for the purpose of added type safety.
45

56
```ocaml
7+
open Volgo;;
8+
69
let process_git_output (_ : Vcs.Git.Output.t) = ()
710
811
let () =
912
let hg_output = { Vcs.Hg.Output.exit_code = 0; stdout = ""; stderr = "" } in
1013
process_git_output hg_output
14+
;;
1115
```
12-
```mdx-error
13-
Line 5, characters 24-33:
14-
Error: The value hg_output has type Vcs.Hg.Output.t
15-
but an expression was expected of type Vcs.Git.Output.t
16+
17+
```terminal
18+
Line 6, characters 21-30:
19+
6 | process_git_output hg_output
20+
^^^^^^^^^
21+
Error: The value hg_output has type
22+
Volgo.Vcs.Hg.Output.t = Volgo__Hg.Output.t
23+
but an expression was expected of type
24+
Volgo.Vcs.Git.Output.t = Volgo__Git.Output.t
1625
```

test/toplevel/process_output.ml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
(*********************************************************************************)
2+
(* Volgo - A Versatile OCaml Library for Git Operations *)
3+
(* SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
4+
(* SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
5+
(*********************************************************************************)
6+
7+
(* @mdexp
8+
9+
# Process output
10+
11+
This test monitors that the types to manipulate the output of the `git` and
12+
`hg` processes are not unifiable, for the purpose of added type safety. *)
13+
14+
let%expect_test "git and hg output types are incompatible" =
15+
Ocaml_toplevel.eval
16+
~code:
17+
{|
18+
open Volgo;;
19+
20+
let process_git_output (_ : Vcs.Git.Output.t) = ()
21+
22+
let () =
23+
let hg_output = { Vcs.Hg.Output.exit_code = 0; stdout = ""; stderr = "" } in
24+
process_git_output hg_output
25+
;;
26+
|};
27+
(* @mdexp.snapshot *)
28+
[%expect
29+
{|
30+
```ocaml
31+
open Volgo;;
32+
33+
let process_git_output (_ : Vcs.Git.Output.t) = ()
34+
35+
let () =
36+
let hg_output = { Vcs.Hg.Output.exit_code = 0; stdout = ""; stderr = "" } in
37+
process_git_output hg_output
38+
;;
39+
```
40+
41+
```terminal
42+
Line 6, characters 21-30:
43+
6 | process_git_output hg_output
44+
^^^^^^^^^
45+
Error: The value hg_output has type
46+
Volgo.Vcs.Hg.Output.t = Volgo__Hg.Output.t
47+
but an expression was expected of type
48+
Volgo.Vcs.Git.Output.t = Volgo__Git.Output.t
49+
```
50+
|}]
51+
;;

test/toplevel/process_output.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(*_********************************************************************************)
2+
(*_ Volgo - A Versatile OCaml Library for Git Operations *)
3+
(*_ SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
4+
(*_ SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
5+
(*_********************************************************************************)

volgo-dev.opam

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ depends: [
1515
"cmdliner" {>= "1.3.0"}
1616
"conf-git"
1717
"conf-hg"
18-
"mdx" {>= "2.4"}
1918
"ppx_js_style" {>= "v0.17"}
2019
"ppxlib" {>= "0.33"}
2120
"vcs-test-helpers" {= version}

0 commit comments

Comments
 (0)