/test/decorator_test.erl

http://github.com/nbowe/erlang_decorators · Erlang · 21 lines · 13 code · 6 blank · 2 comment · 0 complexity · e54d5345b8a86b35f5504e08358d5938 MD5 · raw file

  1. -module(decorator_test).
  2. -include_lib("eunit/include/eunit.hrl").
  3. -export([replace_return_value_decorator/2]).
  4. -compile([{parse_transform, decorators}]).
  5. % example decorator that replaces the return value with the atom 'replaced'
  6. % note that we always pass the arguments as a single list to the next fun
  7. replace_return_value_decorator(F,Args)->
  8. fun() ->
  9. _R = apply(F, [Args] ),
  10. replaced
  11. end.
  12. -decorate({ ?MODULE, replace_return_value_decorator }).
  13. replace_ret_val_decorated() -> ok.
  14. replace_ret_value_test()->
  15. ?assertEqual(replaced, replace_ret_val_decorated() ).