From 2c07fc310e85f1eece74a325bbdf6beef4f8982d Mon Sep 17 00:00:00 2001 From: terry-xiaoyu <506895667@qq.com> Date: Fri, 20 Sep 2019 19:15:35 +0800 Subject: [PATCH] Unload meck before testcase ends --- test/emqx_ctl_SUITE.erl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/emqx_ctl_SUITE.erl b/test/emqx_ctl_SUITE.erl index cc06fa092..eaec942a5 100644 --- a/test/emqx_ctl_SUITE.erl +++ b/test/emqx_ctl_SUITE.erl @@ -67,9 +67,10 @@ t_print(_) -> ok = emqx_ctl:print("help"), ok = emqx_ctl:print("~s", [help]), % - check the output of the usage - print_mock(), + mock_print(), ?assertEqual("help", emqx_ctl:print("help")), - ?assertEqual("help", emqx_ctl:print("~s", [help])). + ?assertEqual("help", emqx_ctl:print("~s", [help])), + unmock_print(). t_usage(_) -> CmdParams1 = "emqx_cmd_1 param1 param2", @@ -80,7 +81,7 @@ t_usage(_) -> ok = emqx_ctl:usage(CmdParams1, CmdDescr1), % - check the output of the usage - print_mock(), + mock_print(), ?assertEqual(Output1, emqx_ctl:usage(CmdParams1, CmdDescr1)), ?assertEqual([Output1, Output1], emqx_ctl:usage([{CmdParams1, CmdDescr1}, {CmdParams1, CmdDescr1}])), @@ -90,7 +91,8 @@ t_usage(_) -> Output2 = "emqx_cmd_2 param1 param2 # emqx_cmd_2 is a test command\n" " ""# means nothing\n", ?assertEqual(Output2, emqx_ctl:usage(CmdParams2, CmdDescr2)), - ?assertEqual([Output2, Output2], emqx_ctl:usage([{CmdParams2, CmdDescr2}, {CmdParams2, CmdDescr2}])). + ?assertEqual([Output2, Output2], emqx_ctl:usage([{CmdParams2, CmdDescr2}, {CmdParams2, CmdDescr2}])), + unmock_print(). t_unexpected(_) -> with_ctl_server( @@ -116,10 +118,13 @@ with_ctl_server(Fun) -> _ = Fun(Pid), ok = emqx_ctl:stop(). -print_mock() -> +mock_print() -> %% proxy usage/1,2 and print/1,2 to format_xx/1,2 funcs meck:new(emqx_ctl, [non_strict, passthrough]), meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg) end), meck:expect(emqx_ctl, print, fun(Msg, Arg) -> emqx_ctl:format(Msg, Arg) end), meck:expect(emqx_ctl, usage, fun(Usages) -> emqx_ctl:format_usage(Usages) end), meck:expect(emqx_ctl, usage, fun(CmdParams, CmdDescr) -> emqx_ctl:format_usage(CmdParams, CmdDescr) end). + +unmock_print() -> + meck:unload(emqx_ctl).