I'd like to be able to use proper_types:is_inst/2 for RPC schema validation
currently proper_types:is_inst/2 is marked as @private
https://github.com/proper-testing/proper/blob/d42964bcdbf8852664ce52656676c06e5ac5a511/src/proper_types.erl#L422
Erlang RPC presents a problem for rolling upgrades, where one release may have changes to the RPC functions. I'd like to use proper_types:is_inst/2 during testing when rpc is called and validate that a module, function exists and is expecting the arguments according to a proper raw_type schema.
For example, very simplified:
call(Mod, Fun, Args) ->
ValidRPCs = [
% {Key, RawTypes} when Key :: {Module, Function, Arity}
{{my_module, my_fun_v1, 1}, [list(atom())]},
{{my_module, my_otherfun_v1, 2}, [integer(), integer()]}
],
{_Key, RawTypes} = lists:keyfind({Mod, Fun, length(Args)}, 1, ValidRPCs),
true = lists:all(fun(Value, RawType) -> is_inst(Value, RawType) end, lists:zip(Args, RawTypes)),
% continue_with_call or crash to let me know the API has a braking change
The other issue is that proper type any() is not erlang any() or term(), it fails with missing types like pid(). It would be really great to add more missing types, even if for validation only, but a catchall to ignore missing types would suffice to catch the rest. I've added an ignore() and pid() types locally to test and it worked.
Please let me know if this use can can be accommodated.
I am able to expand types in my own code, but I still hope that using this for schema validation can be supported officially.
-module(more_proper_types).
-export([pid/0]).
-import(proper_types, [new_type/2]).
-spec pid() -> proper_types:type().
pid() ->
new_type([{generator, fun() -> spawn(fun() -> ok end) end},
{is_instance, fun is_pid/1}],
basic).