Skip to content

Commit

Permalink
test: add repro for ocaml#10264
Browse files Browse the repository at this point in the history
This is only one part of the issue; the other part is more difficult to
test because it is related to `Modules.t` round-tripping correctly.

Signed-off-by: Etienne Millon <[email protected]>
  • Loading branch information
emillon committed Mar 14, 2024
1 parent 40ea41f commit 73b9257
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/dune_rules/module.mli
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module Kind : sig
| Root

include Dune_lang.Conv.S with type t := t

val to_dyn : t -> Dyn.t
end

module Source : sig
Expand Down
47 changes: 47 additions & 0 deletions test/expect-tests/module_tests.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
open Stdune
module Kind = Dune_rules.Module.Kind

(* See #10264 *)
let%expect_test "Module.Kind encoding round trip" =
let module_name s = Dune_rules.Module_name.of_string s in
let test k =
let ast = Kind.encode k in
let sexp = Dune_sexp.Ast.add_loc ~loc:Loc.none ast in
let decoded =
match Dune_lang.Decoder.parse Kind.decode Univ_map.empty sexp with
| r -> Ok r
| exception e -> Error e
in
let dyn =
Dyn.record
[ "ast", Dyn.string (Dune_sexp.to_string ast)
; "decoded", Or_exn.to_dyn Kind.to_dyn decoded
]
in
Dune_tests_common.print_dyn dyn
in
test Impl;
[%expect {| { ast = "impl"; decoded = Ok Impl } |}];
test (Alias []);
[%expect {| { ast = "alias"; decoded = Ok Alias [] } |}];
test (Alias [ module_name "A" ]);
[%expect
{|
{ ast = "(alias (A))"
; decoded =
Error
"File \"<none>\", line 1, characters 0-0:\n\
Error: Atom or quoted string expected\n\
"
} |}];
test (Alias [ module_name "A"; module_name "B" ]);
[%expect
{|
{ ast = "(alias (A B))"
; decoded =
Error
"File \"<none>\", line 1, characters 0-0:\n\
Error: Atom or quoted string expected\n\
"
} |}]
;;

0 comments on commit 73b9257

Please sign in to comment.