Skip to content

Commit

Permalink
Add unit test for pythongen code
Browse files Browse the repository at this point in the history
This tests whether it can handle the case where a varaiant consist only
of zero-arg constructors.

Signed-off-by: Vincent Liu <[email protected]>
  • Loading branch information
Vincent-lau committed Feb 29, 2024
1 parent 6cacde3 commit d610d47
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/rpc/test_pythongen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,50 @@ module Interface (R : Idl.RPC) = struct
end

module IfCode = Interface (Codegen.Gen ())
module UnitVInterface (R : Idl.RPC) = struct
open R

type unit_variant =
| Empty
| Hollow
| Vacant
| Void
[@@deriving rpcty]

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 unitv_interface =
Codegen.Interfaces.create
~name:"unitv"
~title:"Unit Variant"
~description:[ "Interface for Unit variant" ]
~interfaces:[ UnitVCode.implementation () ]

let interfaces =
Codegen.Interfaces.create
Expand Down Expand Up @@ -146,6 +190,8 @@ let check_exceptions () =
gen_python_bindings "python/bindings.py";
run_cmd "Exceptions should be correctly generated" "python python/exn_test.py"

let check_unit_variants () =
Pythongen.of_interfaces interfaces |> Pythongen.string_of_ts |> ignore

let tests =
[ ( "Check generated test interface bindings with pylint & pycodestyle"
Expand All @@ -154,4 +200,5 @@ let tests =
; "Check generated commandline bindings", `Slow, test_commandline
; "Check generated test class with commandline bindings", `Slow, check_test_class
; "Cehck generated exceptions", `Slow, check_exceptions
; "Check python generation on variants with zero-arg constructors", `Quick, check_unit_variants
]

0 comments on commit d610d47

Please sign in to comment.