diff --git a/tests/lib/dune b/tests/lib/dune index c79f0fb..3423bf6 100644 --- a/tests/lib/dune +++ b/tests/lib/dune @@ -1,5 +1,7 @@ (executable (name suite) + (preprocess + (pps ppx_deriving_rpc)) (libraries rpclib.core rpclib.json rpclib.xml alcotest test_common)) (rule diff --git a/tests/lib/pythongen_test.ml b/tests/lib/pythongen_test.ml new file mode 100644 index 0000000..436af14 --- /dev/null +++ b/tests/lib/pythongen_test.ml @@ -0,0 +1,49 @@ +type unit_variant = + | Empty + | Hollow + | Vacant + | Void +[@@deriving rpcty] + +module UnitVInterface (R : Idl.RPC) = struct + open R + + let unit_variant_p = Idl.Param.mk ~name:"unit_variant" unit_variant + let int_p = Idl.Param.mk Rpc.Types.int + + let discard_v = + R.declare + "discard_v" + [ "constant function taking a unit variant and discards it by returning an integer" + ] + (unit_variant_p @-> returning int_p Idl.DefaultError.err) + + + let implementation = + implement + { Idl.Interface.name = "UnitVInterface" + ; namespace = Some "UnitVInterface" + ; description = + [ "Unit variant interface which does absolutely nothing. Only used to test \ + whether the pythongen code can handle variants with zero argument \ + constructors." + ] + ; version = 1, 0, 0 + } +end + +module UnitVCode : sig + val implementation : unit -> Codegen.Interface.t +end = + UnitVInterface (Codegen.Gen ()) + +let interfaces = + Codegen.Interfaces.create + ~name:"unitv" + ~title:"Unit Variant" + ~description:[ "Interface for Unit variant" ] + ~interfaces:[ UnitVCode.implementation () ] + + +let run () = Pythongen.of_interfaces interfaces |> Pythongen.string_of_ts |> ignore +let tests = [ "test gen python on variants with zero-arg constructors", `Quick, run ] diff --git a/tests/lib/suite.ml b/tests/lib/suite.ml index c0b1291..14526fa 100644 --- a/tests/lib/suite.ml +++ b/tests/lib/suite.ml @@ -5,4 +5,5 @@ let () = ; "Json", Json.tests ; "Xml_xapi", Xml_xapi.tests ; "Encoding", Encoding.tests + ; "Pythongen_test", Pythongen_test.tests ]