| 1 | -module(hope_result_SUITE). |
| 2 | |
| 3 | %% TODO: Import only what is used. |
| 4 | -include_lib("proper/include/proper.hrl"). |
| 5 | |
| 6 | %% Callbacks |
| 7 | -export( |
| 8 | [ all/0 |
| 9 | , groups/0 |
| 10 | , init_per_group/2 |
| 11 | , end_per_group/2 |
| 12 | ]). |
| 13 | |
| 14 | %% Test cases |
| 15 | -export( |
| 16 | [ t_pipe_ok/1 |
| 17 | , t_pipe_error/1 |
| 18 | , t_hope_result_specs/1 |
| 19 | ]). |
| 20 | |
| 21 | |
| 22 | -define(GROUP_PIPE, result_pipe). |
| 23 | -define(GROUP_SPEC, result_spec). |
| 24 | |
| 25 | |
| 26 | %% ============================================================================ |
| 27 | %% Common Test callbacks |
| 28 | %% ============================================================================ |
| 29 | |
| 30 | all() -> |
| 31 | [ {group, ?GROUP_PIPE} |
| 32 | , {group, ?GROUP_SPEC} |
| 33 | ]. |
| 34 | |
| 35 | groups() -> |
| 36 | PipeTests = |
| 37 | [ t_pipe_ok |
| 38 | , t_pipe_error |
| 39 | ], |
| 40 | SpecTests = |
| 41 | [ t_hope_result_specs |
| 42 | ], |
| 43 | Properties = [parallel], |
| 44 | [ {?GROUP_PIPE, Properties, PipeTests} |
| 45 | , {?GROUP_SPEC, Properties, SpecTests} |
| 46 | ]. |
| 47 | |
| 48 | init_per_group(?GROUP_SPEC, Cfg) -> |
| 49 | Cfg; |
| 50 | init_per_group(?GROUP_PIPE, Cfg) -> |
| 51 | Steps = |
| 52 | [ fun (0) -> {ok, 1}; (X) -> {error, X} end |
| 53 | , fun (1) -> {ok, 2}; (X) -> {error, X} end |
| 54 | , fun (2) -> {ok, 3}; (X) -> {error, X} end |
| 55 | ], |
| 56 | hope_kv_list:set(Cfg, steps, Steps). |
| 57 | |
| 58 | end_per_group(?GROUP_SPEC, _Cfg) -> |
| 59 | ok; |
| 60 | end_per_group(?GROUP_PIPE, _Cfg) -> |
| 61 | ok. |
| 62 | |
| 63 | |
| 64 | %% ============================================================================= |
| 65 | %% Test cases |
| 66 | %% ============================================================================= |
| 67 | |
| 68 | t_pipe_ok(Cfg) -> |
| 69 | {some, Steps} = hope_kv_list:get(Cfg, steps), |
| 70 | {ok, 3} = hope_result:pipe(Steps, 0). |
| 71 | |
| 72 | t_pipe_error(Cfg) -> |
| 73 | {some, Steps} = hope_kv_list:get(Cfg, steps), |
| 74 | {error, 1} = hope_result:pipe(Steps, 1). |
| 75 | |
| 76 | t_hope_result_specs(_) -> |
| 77 | [] = proper:check_specs(hope_result). |