use meck for testing
This commit is contained in:
parent
ff59289098
commit
c50f42a70c
4 changed files with 73 additions and 17 deletions
18
makefile
18
makefile
|
@ -1,8 +1,20 @@
|
||||||
compile:
|
compile: clean get-deps
|
||||||
./rebar --jobs=1 compile
|
./rebar --jobs=1 compile
|
||||||
|
|
||||||
|
compile-test: get-test-deps
|
||||||
|
./rebar --config rebar.test.config --jobs 1 compile
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
./rebar clean
|
./rebar clean
|
||||||
|
|
||||||
test: clean
|
clean-test:
|
||||||
./rebar --jobs=1 eunit
|
./rebar --config rebar.test.config clean
|
||||||
|
|
||||||
|
get-deps:
|
||||||
|
./rebar get-deps
|
||||||
|
|
||||||
|
get-test-deps:
|
||||||
|
./rebar --config rebar.test.config get-deps
|
||||||
|
|
||||||
|
test: clean-test compile-test
|
||||||
|
./rebar --config rebar.test.config --jobs 1 skip_deps=true eunit
|
|
@ -1,10 +1,3 @@
|
||||||
%% edit eunit_test_path if you want to run your own tests, use "../" not "./" as
|
|
||||||
%% rebar changes to working dir to .eunit when running tests
|
|
||||||
{eunit_compile_opts, [{d, eunit_test_path, "../test/cases"}]}.
|
|
||||||
|
|
||||||
%% uncomment to get verbose output from test suite
|
|
||||||
%% {eunit_opts, [verbose]}.
|
|
||||||
|
|
||||||
{erl_opts, [{i, "src"}, {src_dirs, ["src"]},
|
{erl_opts, [{i, "src"}, {src_dirs, ["src"]},
|
||||||
warn_unused_vars,
|
warn_unused_vars,
|
||||||
warn_export_all,
|
warn_export_all,
|
||||||
|
|
30
rebar.test.config
Normal file
30
rebar.test.config
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
%% edit eunit_test_path if you want to run your own tests, use "../" not "./" as
|
||||||
|
%% rebar changes to working dir to .eunit when running tests
|
||||||
|
{eunit_compile_opts, [{d, eunit_test_path, "../test/cases"}]}.
|
||||||
|
|
||||||
|
%% uncomment to get verbose output from test suite
|
||||||
|
%% {eunit_opts, [verbose]}.
|
||||||
|
|
||||||
|
{erl_opts, [{i, "src"}, {src_dirs, ["src"]},
|
||||||
|
warn_unused_vars,
|
||||||
|
warn_export_all,
|
||||||
|
warn_shadow_vars,
|
||||||
|
warn_unused_import,
|
||||||
|
warn_unused_function,
|
||||||
|
warn_bif_clash,
|
||||||
|
warn_unused_record,
|
||||||
|
warn_deprecated_function,
|
||||||
|
warn_obsolete_guard,
|
||||||
|
strict_validation,
|
||||||
|
warn_export_vars,
|
||||||
|
warn_exported_vars]}.
|
||||||
|
{dialyzer_opts, [{warnings, [unmatched_returns, error_handling, race_conditions, behaviours]}]}.
|
||||||
|
{xref_checks, [undefined_function_calls]}.
|
||||||
|
{cover_enabled, true}.
|
||||||
|
|
||||||
|
{deps, [
|
||||||
|
{'meck',
|
||||||
|
".*",
|
||||||
|
{git, "git://github.com/eproxus/meck.git"}
|
||||||
|
}
|
||||||
|
]}.
|
|
@ -176,12 +176,24 @@ indent_or_space(Opts) ->
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
|
setup_nicedecimal_meck(Return) ->
|
||||||
|
ok = meck:new(nicedecimal),
|
||||||
|
ok = meck:expect(nicedecimal, format, fun(1.23) -> Return end).
|
||||||
|
|
||||||
|
teardown_nicedecimal_meck(_) ->
|
||||||
|
?assert(meck:validate(nicedecimal)),
|
||||||
|
ok = meck:unload(nicedecimal).
|
||||||
|
|
||||||
basic_format_test_() ->
|
basic_format_test_() ->
|
||||||
[
|
[
|
||||||
{"empty object", ?_assert(format(<<"{}">>, []) =:= <<"{}">>)},
|
{"empty object", ?_assert(format(<<"{}">>, []) =:= <<"{}">>)},
|
||||||
{"empty array", ?_assert(format(<<"[]">>, []) =:= <<"[]">>)},
|
{"empty array", ?_assert(format(<<"[]">>, []) =:= <<"[]">>)},
|
||||||
{"naked integer", ?_assert(format(<<"123">>, []) =:= <<"123">>)},
|
{"naked integer", ?_assert(format(<<"123">>, []) =:= <<"123">>)},
|
||||||
{"naked float", ?_assert(format(<<"1.23">>, []) =:= <<"1.23">>)},
|
{foreach,
|
||||||
|
fun() -> setup_nicedecimal_meck(<<"1.23">>) end,
|
||||||
|
fun(R) -> teardown_nicedecimal_meck(R) end,
|
||||||
|
[{"naked float", ?_assert(format(<<"1.23">>, []) =:= <<"1.23">>)}]
|
||||||
|
},
|
||||||
{"naked string", ?_assert(format(<<"\"hi\"">>, []) =:= <<"\"hi\"">>)},
|
{"naked string", ?_assert(format(<<"\"hi\"">>, []) =:= <<"\"hi\"">>)},
|
||||||
{"naked literal", ?_assert(format(<<"true">>, []) =:= <<"true">>)},
|
{"naked literal", ?_assert(format(<<"true">>, []) =:= <<"true">>)},
|
||||||
{"simple object",
|
{"simple object",
|
||||||
|
@ -229,7 +241,11 @@ basic_to_json_test_() ->
|
||||||
{"empty object", ?_assert(to_json([{}], []) =:= <<"{}">>)},
|
{"empty object", ?_assert(to_json([{}], []) =:= <<"{}">>)},
|
||||||
{"empty array", ?_assert(to_json([], []) =:= <<"[]">>)},
|
{"empty array", ?_assert(to_json([], []) =:= <<"[]">>)},
|
||||||
{"naked integer", ?_assert(to_json(123, []) =:= <<"123">>)},
|
{"naked integer", ?_assert(to_json(123, []) =:= <<"123">>)},
|
||||||
{"naked float", ?_assert(to_json(1.23, []) =:= <<"1.23">>)},
|
{foreach,
|
||||||
|
fun() -> setup_nicedecimal_meck(<<"1.23">>) end,
|
||||||
|
fun(R) -> teardown_nicedecimal_meck(R) end,
|
||||||
|
[{"naked float", ?_assert(to_json(1.23, []) =:= <<"1.23">>)}]
|
||||||
|
},
|
||||||
{"naked string", ?_assert(to_json(<<"hi">>, []) =:= <<"\"hi\"">>)},
|
{"naked string", ?_assert(to_json(<<"hi">>, []) =:= <<"\"hi\"">>)},
|
||||||
{"naked literal", ?_assert(to_json(true, []) =:= <<"true">>)},
|
{"naked literal", ?_assert(to_json(true, []) =:= <<"true">>)},
|
||||||
{"simple object",
|
{"simple object",
|
||||||
|
@ -316,11 +332,16 @@ opts_test_() ->
|
||||||
) =:= <<"{\"a\": true, \"b\": true, \"c\": true}">>
|
) =:= <<"{\"a\": true, \"b\": true, \"c\": true}">>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
{"array indent",
|
{foreach,
|
||||||
?_assert(format(<<"[1.0, 2.0, 3.0]">>,
|
fun() -> setup_nicedecimal_meck(<<"1.23">>) end,
|
||||||
|
fun(R) -> teardown_nicedecimal_meck(R) end,
|
||||||
|
[{
|
||||||
|
"array indent",
|
||||||
|
?_assert(format(<<"[1.23, 1.23, 1.23]">>,
|
||||||
[{indent, 2}]
|
[{indent, 2}]
|
||||||
) =:= <<"[\n 1.0,\n 2.0,\n 3.0\n]">>
|
) =:= <<"[\n 1.23,\n 1.23,\n 1.23\n]">>
|
||||||
)
|
)
|
||||||
|
}]
|
||||||
},
|
},
|
||||||
{"object indent",
|
{"object indent",
|
||||||
?_assert(format(<<"{\"a\":true,\"b\":true,\"c\":true}">>,
|
?_assert(format(<<"{\"a\":true,\"b\":true,\"c\":true}">>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue