123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- -module(erlydtl_eunit_testrunner).
- -author('Andreas Stenius <kaos@astekk.se>').
- -export([run_test/1, run_compile/1, run_render/1]).
- -include_lib("eunit/include/eunit.hrl").
- -define(noimport,).
- -include("testrunner.hrl").
- run_test(T) ->
- case run_compile(T) of
- ok -> run_render(T);
- error_ok -> ok
- end.
- compile_opts(#test{ compile_vars = undefined, compile_opts = Opts }) ->
- Opts;
- compile_opts(#test{ compile_vars = Vars, compile_opts = Opts }) ->
- [{default_vars, Vars}|Opts].
- run_compile(T) ->
- case erlydtl:compile(
- T#test.source,
- T#test.module,
- compile_opts(T))
- of
- {ok, M, W0} ->
- ?assertEqual(T#test.module, M),
-
- W = lists:flatten(
- [case W1 of
- {_, [{_, sys_core_fold, useless_building}]} -> [];
- _ -> W1
- end || W1 <- W0]),
- ?assertEqual(T#test.warnings, W);
- {error, E, W} ->
- ?assertEqual(T#test.errors, E),
- ?assertEqual(T#test.warnings, W),
- error_ok
- end.
- run_render(#test{ renderer=Renderer }=T) ->
- Output = if is_atom(Renderer) ->
- (T#test.module):Renderer(T#test.render_vars, T#test.render_opts);
- is_function(Renderer) ->
- Renderer(T)
- end,
- case Output of
- {ok, O} ->
- B = iolist_to_binary(O),
- case T#test.output of
- O -> ok;
- B -> ok;
- F when is_function(F) ->
- F(B);
- _ ->
- ?assertEqual(T#test.output, B)
- end;
- RenderOutput ->
- ?assertEqual(T#test.output, RenderOutput),
- error_ok
- end.
|