1 -module(hope_result_SUITE).
3 %% TODO: Import only what is used.
4 -include_lib("proper/include/proper.hrl").
18 , t_hope_result_specs/1
25 -define(GROUP_PIPE, result_pipe).
26 -define(GROUP_SPEC, result_spec).
27 -define(GROUP_LIFT, result_lift_exn).
28 -define(GROUP_OTHER, result_other).
31 %% ============================================================================
32 %% Common Test callbacks
33 %% ============================================================================
36 [ {group, ?GROUP_PIPE}
37 , {group, ?GROUP_SPEC}
38 , {group, ?GROUP_LIFT}
39 , {group, ?GROUP_OTHER}
57 Properties = [parallel],
58 [ {?GROUP_PIPE, Properties, PipeTests}
59 , {?GROUP_SPEC, Properties, SpecTests}
60 , {?GROUP_LIFT, Properties, LiftTests}
61 , {?GROUP_OTHER, Properties, OtherTests}
64 init_per_group(?GROUP_PIPE, Cfg) ->
66 [ fun (0) -> {ok, 1}; (X) -> {error, X} end
67 , fun (1) -> {ok, 2}; (X) -> {error, X} end
68 , fun (2) -> {ok, 3}; (X) -> {error, X} end
70 hope_kv_list:set(Cfg, steps, Steps);
71 init_per_group(_, Cfg) ->
74 end_per_group(_, _Cfg) ->
78 %% =============================================================================
80 %% =============================================================================
83 {some, Steps} = hope_kv_list:get(Cfg, steps),
84 {ok, 3} = hope_result:pipe(Steps, 0).
87 {some, Steps} = hope_kv_list:get(Cfg, steps),
88 {error, 1} = hope_result:pipe(Steps, 1).
90 t_hope_result_specs(_) ->
91 [] = proper:check_specs(hope_result).
97 F = fun (ok) -> apply(erlang, Class, [Reason]) end,
98 G = hope_result:lift_exn(F),
99 H = hope_result:lift_exn(F, Label),
100 {error, {Class, Reason}} = G(ok),
101 {error, {Label, {Class, Reason}}} = H(ok).
105 {ok, X} = hope_result:return(X).
110 F = fun (foo) -> Y end,
111 {ok, Y} = hope_result:map({ok, X}, F),
112 {error, X} = hope_result:map({error, X}, F).