Test hope_result:lift_exn/1
[hope.git] / test / hope_result_SUITE.erl
CommitLineData
7e9d7f2c
SK
1-module(hope_result_SUITE).
2
8857d0f0 3%% TODO: Import only what is used.
8bbf6f4d
PO
4-include_lib("proper/include/proper.hrl").
5
7e9d7f2c
SK
6%% Callbacks
7-export(
8 [ all/0
9 , groups/0
126c8880
SK
10 , init_per_group/2
11 , end_per_group/2
7e9d7f2c
SK
12 ]).
13
14%% Test cases
15-export(
126c8880
SK
16 [ t_pipe_ok/1
17 , t_pipe_error/1
8bbf6f4d 18 , t_hope_result_specs/1
371e6333 19 , t_lift_exn/1
7e9d7f2c
SK
20 ]).
21
22
23-define(GROUP_PIPE, result_pipe).
8857d0f0 24-define(GROUP_SPEC, result_spec).
371e6333 25-define(GROUP_LIFT, result_lift_exn).
7e9d7f2c
SK
26
27
28%% ============================================================================
29%% Common Test callbacks
30%% ============================================================================
31
32all() ->
8857d0f0
SK
33 [ {group, ?GROUP_PIPE}
34 , {group, ?GROUP_SPEC}
371e6333 35 , {group, ?GROUP_LIFT}
8857d0f0 36 ].
7e9d7f2c
SK
37
38groups() ->
8857d0f0 39 PipeTests =
126c8880
SK
40 [ t_pipe_ok
41 , t_pipe_error
8857d0f0
SK
42 ],
43 SpecTests =
44 [ t_hope_result_specs
7e9d7f2c 45 ],
371e6333
SK
46 LiftTests =
47 [ t_lift_exn
48 ],
8bbf6f4d 49 Properties = [parallel],
8857d0f0
SK
50 [ {?GROUP_PIPE, Properties, PipeTests}
51 , {?GROUP_SPEC, Properties, SpecTests}
371e6333 52 , {?GROUP_LIFT, Properties, LiftTests}
8857d0f0 53 ].
7e9d7f2c 54
371e6333
SK
55init_per_group(?GROUP_LIFT, Cfg) ->
56 Cfg;
8857d0f0
SK
57init_per_group(?GROUP_SPEC, Cfg) ->
58 Cfg;
126c8880 59init_per_group(?GROUP_PIPE, Cfg) ->
7e9d7f2c 60 Steps =
55182c1b
SK
61 [ fun (0) -> {ok, 1}; (X) -> {error, X} end
62 , fun (1) -> {ok, 2}; (X) -> {error, X} end
63 , fun (2) -> {ok, 3}; (X) -> {error, X} end
7e9d7f2c 64 ],
126c8880
SK
65 hope_kv_list:set(Cfg, steps, Steps).
66
371e6333
SK
67end_per_group(?GROUP_LIFT, _Cfg) ->
68 ok;
8857d0f0
SK
69end_per_group(?GROUP_SPEC, _Cfg) ->
70 ok;
126c8880
SK
71end_per_group(?GROUP_PIPE, _Cfg) ->
72 ok.
73
74
75%% =============================================================================
76%% Test cases
77%% =============================================================================
78
79t_pipe_ok(Cfg) ->
80 {some, Steps} = hope_kv_list:get(Cfg, steps),
55182c1b 81 {ok, 3} = hope_result:pipe(Steps, 0).
126c8880
SK
82
83t_pipe_error(Cfg) ->
84 {some, Steps} = hope_kv_list:get(Cfg, steps),
85 {error, 1} = hope_result:pipe(Steps, 1).
8bbf6f4d
PO
86
87t_hope_result_specs(_) ->
88 [] = proper:check_specs(hope_result).
371e6333
SK
89
90t_lift_exn(_Cfg) ->
91 Class = throw,
92 Reason = foofoo,
93 F = fun (ok) -> apply(erlang, Class, [Reason]) end,
94 G = hope_result:lift_exn(F),
95 {error, {Class, Reason}} = G(ok).
This page took 0.037944 seconds and 4 git commands to generate.