diff --git a/0001-Add-introspection-of-which-modules-are-currently-moc.patch b/0001-Add-introspection-of-which-modules-are-currently-moc.patch deleted file mode 100644 index 1f567cfefeebdf55e82f3ad6f987fcd45d298b1e..0000000000000000000000000000000000000000 --- a/0001-Add-introspection-of-which-modules-are-currently-moc.patch +++ /dev/null @@ -1,131 +0,0 @@ -From 1ed7933038d709faae7d7fa8152e2c07ad2d6e50 Mon Sep 17 00:00:00 2001 -From: Filipe Cristovao -Date: Tue, 12 May 2020 22:13:51 +0200 -Subject: [PATCH] Add introspection of which modules are currently mocked - -There's already an `meck:expects/[1,2]`, allowing introspection into -what kind of expectations are set. -This allows one to also check which modules is meck handling at any -point. - -Introduced a `foldl_mocks` internal function to reuse the same logic -for both `unload/0` and `mocked/0` ---- - src/meck.erl | 47 ++++++++++++++++++++++++++------------------- - test/meck_tests.erl | 21 ++++++++++++++++++++ - 2 files changed, 48 insertions(+), 20 deletions(-) - -diff --git a/src/meck.erl b/src/meck.erl -index 9f4efc2..8eb0365 100644 ---- a/src/meck.erl -+++ b/src/meck.erl -@@ -54,6 +54,7 @@ - -export([wait/4]). - -export([wait/5]). - -export([wait/6]). -+-export([mocked/0]). - - %% Syntactic sugar - -export([loop/1]). -@@ -460,7 +461,15 @@ history(Mod, OptCallerPid) - -spec unload() -> Unloaded when - Unloaded :: [Mod], - Mod :: atom(). --unload() -> lists:foldl(fun unload_if_mocked/2, [], registered()). -+unload() -> -+ foldl_mocks(fun(Mod, Acc) -> -+ try -+ unload(Mod), -+ [Mod | Acc] -+ catch error:{not_mocked, Mod} -> -+ Acc -+ end -+ end, []). - - %% @doc Unload a mocked module or a list of mocked modules. - %% -@@ -723,6 +732,11 @@ capture(Occur, Mod, Func, OptArgsSpec, ArgNum, OptCallerPid) -> - capture(Occur, Mod, Func, OptArgsSpec, ArgNum) -> - meck_history:capture(Occur, '_', Mod, Func, OptArgsSpec, ArgNum). - -+%% @doc Returns the currently mocked modules. -+-spec mocked() -> list(atom()). -+mocked() -> -+ foldl_mocks(fun(M, Acc) -> [M | Acc] end, []). -+ - %%%============================================================================ - %%% Internal functions - %%%============================================================================ -@@ -732,25 +746,18 @@ wait_for_exit(Mod) -> - MonitorRef = erlang:monitor(process, meck_util:proc_name(Mod)), - receive {'DOWN', MonitorRef, _Type, _Object, _Info} -> ok end. - ---spec unload_if_mocked(Mod::atom() | string(), Unloaded::[atom()]) -> -- NewUnloaded::[atom()]. --unload_if_mocked(Mod, Unloaded) when is_atom(Mod) -> -- unload_if_mocked(atom_to_list(Mod), Unloaded); --unload_if_mocked(ModName, Unloaded) when length(ModName) > 5 -> -- case lists:split(length(ModName) - 5, ModName) of -- {Name, "_meck"} -> -- Mocked = erlang:list_to_existing_atom(Name), -- try -- unload(Mocked) -- catch error:{not_mocked, Mocked} -> -- ok -- end, -- [Mocked | Unloaded]; -- _Else -> -- Unloaded -- end; --unload_if_mocked(_P, Unloaded) -> -- Unloaded. -+-spec foldl_mocks(Fun, AccIn) -> AccOut when -+ Fun :: fun((Elem :: module(), AccIn) -> AccOut), -+ AccIn :: term(), -+ AccOut :: term(). -+foldl_mocks(Fun, Acc0) when is_function(Fun, 2) -> -+ lists:foldl(fun(Mod, Acc) -> -+ ModName = atom_to_list(Mod), -+ case lists:split(max(length(ModName) - 5, 0), ModName) of -+ {Name, "_meck"} -> Fun(erlang:list_to_existing_atom(Name), Acc); -+ _Else -> Acc -+ end -+ end, Acc0, erlang:registered()). - - -spec check_expect_result(ok | {error, Reason::any()}) -> ok. - check_expect_result(ok) -> ok; -diff --git a/test/meck_tests.erl b/test/meck_tests.erl -index f17223c..988ded7 100644 ---- a/test/meck_tests.erl -+++ b/test/meck_tests.erl -@@ -1547,6 +1547,27 @@ wait_purge_expired_tracker_test() -> - %% Clean - meck:unload(). - -+mocked_test() -> -+ %% At start, no modules should be mocked: -+ [] = meck:mocked(), -+ -+ %% Mocking a new module adds it to the list of mocked modules: -+ meck:new(mocked_test, [non_strict]), -+ [mocked_test] = meck:mocked(), -+ -+ %% Mocking with implicit `meck:new` also adds to the list of mocked modules: -+ meck:expect(meck_test_module, c, 2, ok), -+ [meck_test_module, mocked_test] = lists:sort(meck:mocked()), -+ -+ meck:new([foo, bar], [non_strict]), -+ [bar, foo, meck_test_module, mocked_test] = lists:sort(meck:mocked()), -+ -+ ok = meck:unload([foo, meck_test_module]), -+ [bar, mocked_test] = lists:sort(meck:mocked()), -+ -+ meck:unload(), -+ %% After unload all, no modules should be mocked again -+ [] = meck:mocked(). - - meck_passthrough_test_() -> - {foreach, fun setup_passthrough/0, fun teardown/1, --- -2.42.0.windows.2 - diff --git a/0001-Change-to-matrix-build.patch b/0001-Change-to-matrix-build.patch new file mode 100644 index 0000000000000000000000000000000000000000..ad44c82b46d1175b09ca493f2a87e4b7cd373911 --- /dev/null +++ b/0001-Change-to-matrix-build.patch @@ -0,0 +1,46 @@ +From f37000b6106aad736b2c8d2c1cd925ed390fcabf Mon Sep 17 00:00:00 2001 +From: Adam Lindberg +Date: Wed, 5 Feb 2020 17:33:34 +0100 +Subject: [PATCH] Change to matrix build + +--- + .github/workflows/erlang.yml | 24 ++++++++++-------------- + 1 file changed, 10 insertions(+), 14 deletions(-) + +diff --git a/.github/workflows/erlang.yml b/.github/workflows/erlang.yml +index 316568b..e005215 100644 +--- a/.github/workflows/erlang.yml ++++ b/.github/workflows/erlang.yml +@@ -1,19 +1,15 @@ +-name: Erlang CI +- +-on: [push] ++on: push + + jobs: +- +- build: +- ++ test: + runs-on: ubuntu-latest +- + container: +- image: erlang:22.0.7 +- ++ image: erlang:${{matrix.otp}} ++ name: OTP ${{matrix.otp}} ++ strategy: ++ matrix: ++ otp: [22.0.7] + steps: +- - uses: actions/checkout@v2 +- - name: Compile +- run: rebar3 compile +- - name: Run tests +- run: rebar3 do eunit, ct ++ - uses: actions/checkout@v2 ++ - run: rebar3 compile ++ - run: rebar3 do eunit, ct +-- +2.42.0.windows.2 + diff --git a/0001-Create-FUNDING.yml.patch b/0001-Create-FUNDING.yml.patch new file mode 100644 index 0000000000000000000000000000000000000000..9002cea1d3ce6622dbac2a5210268945cb6be0da --- /dev/null +++ b/0001-Create-FUNDING.yml.patch @@ -0,0 +1,23 @@ +From 9753464ac1ebc0fc1a6777322bc871eaed82be35 Mon Sep 17 00:00:00 2001 +From: Adam Lindberg +Date: Tue, 27 Aug 2019 14:19:08 +0200 +Subject: [PATCH] Create FUNDING.yml + +--- + .github/FUNDING.yml | 4 ++++ + 1 file changed, 4 insertions(+) + create mode 100644 .github/FUNDING.yml + +diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml +new file mode 100644 +index 0000000..18e5524 +--- /dev/null ++++ b/.github/FUNDING.yml +@@ -0,0 +1,4 @@ ++# These are supported funding model platforms ++ ++# github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] ++liberapay: eproxus +-- +2.42.0.windows.2 + diff --git a/0001-Create-first-GitHub-action.patch b/0001-Create-first-GitHub-action.patch new file mode 100644 index 0000000000000000000000000000000000000000..950bfee65786ebb551ec86aea980303c1d769314 --- /dev/null +++ b/0001-Create-first-GitHub-action.patch @@ -0,0 +1,38 @@ +From 01e349825c95f499e37c1a043582fa7f1f0c1f20 Mon Sep 17 00:00:00 2001 +From: Adam Lindberg +Date: Wed, 5 Feb 2020 17:24:21 +0100 +Subject: [PATCH] Create first GitHub action + +--- + .github/workflows/erlang.yml | 19 +++++++++++++++++++ + 1 file changed, 19 insertions(+) + create mode 100644 .github/workflows/erlang.yml + +diff --git a/.github/workflows/erlang.yml b/.github/workflows/erlang.yml +new file mode 100644 +index 0000000..316568b +--- /dev/null ++++ b/.github/workflows/erlang.yml +@@ -0,0 +1,19 @@ ++name: Erlang CI ++ ++on: [push] ++ ++jobs: ++ ++ build: ++ ++ runs-on: ubuntu-latest ++ ++ container: ++ image: erlang:22.0.7 ++ ++ steps: ++ - uses: actions/checkout@v2 ++ - name: Compile ++ run: rebar3 compile ++ - name: Run tests ++ run: rebar3 do eunit, ct +-- +2.42.0.windows.2 + diff --git a/0001-Do-not-attempt-to-generate-dependencies-when-mocking.patch b/0001-Do-not-attempt-to-generate-dependencies-when-mocking.patch new file mode 100644 index 0000000000000000000000000000000000000000..937be0d8a717b1b6d161a968f94a96d2041ef7cf --- /dev/null +++ b/0001-Do-not-attempt-to-generate-dependencies-when-mocking.patch @@ -0,0 +1,35 @@ +From 9b3ce754bd69e84127f82d482b8b23b22f7bf866 Mon Sep 17 00:00:00 2001 +From: Jesper Eskilson +Date: Wed, 5 Feb 2020 13:35:42 +0100 +Subject: [PATCH] Do not attempt to generate dependencies when mocking + +Fixed in #207 +--- + src/meck_code.erl | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/src/meck_code.erl b/src/meck_code.erl +index d0b524a..803b41c 100644 +--- a/src/meck_code.erl ++++ b/src/meck_code.erl +@@ -126,8 +126,16 @@ load_binary(Name, Binary) -> + % Furthermore, since Erlang/OTP 20, a code may be compiled from core but + % still have abstract code, so we make sure to remove the from_core option + % as we always compile it as a form. ++% ++% The -MMD option (makedep_side_effect) needs to be removed, otherwise ++% the compiler will attempt to generate a dependency file. + filter_options (Options) -> + case Options of + undefined -> []; +- _ -> lists:filter(fun({parse_transform,_}) -> false; (from_core) -> false; (_) -> true end, Options) ++ _ -> lists:filter( ++ fun({parse_transform,_}) -> false; ++ (makedep_side_effect) -> false; ++ (from_core) -> false; ++ (_) -> true ++ end, Options) + end. +-- +2.42.0.windows.2 + diff --git a/0001-Update-badges-to-use-GitHub-Actions.patch b/0001-Update-badges-to-use-GitHub-Actions.patch new file mode 100644 index 0000000000000000000000000000000000000000..c8aea1053eb763ea4417a3207a0935854f6e72e4 --- /dev/null +++ b/0001-Update-badges-to-use-GitHub-Actions.patch @@ -0,0 +1,43 @@ +From 3d70c4ea4b38699667a1bfea30df00f98ea11ef0 Mon Sep 17 00:00:00 2001 +From: Adam Lindberg +Date: Wed, 5 Feb 2020 19:13:12 +0100 +Subject: [PATCH] Update badges to use GitHub Actions + +--- + README.md | 11 ++++++----- + 1 file changed, 6 insertions(+), 5 deletions(-) + +diff --git a/README.md b/README.md +index 1ada0d7..cab38bc 100644 +--- a/README.md ++++ b/README.md +@@ -1,7 +1,7 @@ +-[![Travis][travis badge]][travis] ++[![GitHub Actions][actions badge]][actions] + [![Hex.pm Version][hex version badge]][hex] + [![Hex.pm License][hex license badge]][hex] +-[![Erlang Versions][erlang version badge]][travis] ++[![Erlang Versions][erlang versions badge]][erlang versions] + [![Build Tool][build tool]][hex] + [![Donations][liberapay badge]][liberapay] + +@@ -261,12 +261,13 @@ If you or your company use Meck and find it useful, [donations][liberapay] are g + + + +-[travis]: https://travis-ci.org/eproxus/meck +-[travis badge]: https://img.shields.io/travis/eproxus/meck/master.svg?style=flat-square ++[actions badge]: https://img.shields.io/github/workflow/status/eproxus/meck/CI?style=flat-square ++[actions]: https://github.com/eproxus/meck/actions?query=workflow%3ACI + [hex]: https://hex.pm/packages/meck + [hex version badge]: https://img.shields.io/hexpm/v/meck.svg?style=flat-square + [hex license badge]: https://img.shields.io/hexpm/l/meck.svg?style=flat-square +-[erlang version badge]: https://img.shields.io/badge/erlang-17--21-blue.svg?style=flat-square ++[erlang versions badge]: https://img.shields.io/badge/erlang-18--22-blue.svg?style=flat-square ++[erlang versions]: https://github.com/eproxus/meck/blob/master/.github/workflows/erlang.yml#L13-L18 + [build tool]: https://img.shields.io/badge/build%20tool-rebar3-orange.svg?style=flat-square + [liberapay badge]: https://img.shields.io/liberapay/receives/eproxus.svg?logo=liberapay&style=flat-square + +-- +2.42.0.windows.2 + diff --git a/0001-Validate-the-options-being-passed-to-meck-new-204.patch b/0001-Validate-the-options-being-passed-to-meck-new-204.patch new file mode 100644 index 0000000000000000000000000000000000000000..dc2b41a807d1cf418415d7fc6cdd7ac1c4e75cfb --- /dev/null +++ b/0001-Validate-the-options-being-passed-to-meck-new-204.patch @@ -0,0 +1,79 @@ +From 2c7ba603416e95401500d7e116c5a829cb558665 Mon Sep 17 00:00:00 2001 +From: Francois Brodeur +Date: Thu, 21 Mar 2019 06:29:58 -0400 +Subject: [PATCH] Validate the options being passed to meck:new (#204) + +* Validate the options being passed +* Add a new test for validate_options +* Fix a typo of passthrough option in a test case +--- + src/meck_proc.erl | 16 ++++++++++++++++ + test/meck_history_tests.erl | 2 +- + test/meck_tests.erl | 9 +++++++++ + 3 files changed, 26 insertions(+), 1 deletion(-) + +diff --git a/src/meck_proc.erl b/src/meck_proc.erl +index eebf2df..3cd02cb 100644 +--- a/src/meck_proc.erl ++++ b/src/meck_proc.erl +@@ -193,8 +193,24 @@ stop(Mod) -> + %%% gen_server callbacks + %%%============================================================================ + ++%% @hidden ++validate_options([]) -> ok; ++validate_options([no_link|Options]) -> validate_options(Options); ++validate_options([spawn_opt|Options]) -> validate_options(Options); ++validate_options([unstick|Options]) -> validate_options(Options); ++validate_options([no_passthrough_cover|Options]) -> validate_options(Options); ++validate_options([merge_expects|Options]) -> validate_options(Options); ++validate_options([enable_on_load|Options]) -> validate_options(Options); ++validate_options([passthrough|Options]) -> validate_options(Options); ++validate_options([no_history|Options]) -> validate_options(Options); ++validate_options([non_strict|Options]) -> validate_options(Options); ++validate_options([stub_all|Options]) -> validate_options(Options); ++validate_options([{stub_all, _}|Options]) -> validate_options(Options); ++validate_options([UnknownOption|_]) -> erlang:error({bad_arg, UnknownOption}). ++ + %% @hidden + init([Mod, Options]) -> ++ validate_options(Options), + Exports = normal_exports(Mod), + WasSticky = case proplists:get_bool(unstick, Options) of + true -> {module, Mod} = code:ensure_loaded(Mod), +diff --git a/test/meck_history_tests.erl b/test/meck_history_tests.erl +index 0b0bfbc..3c0a419 100644 +--- a/test/meck_history_tests.erl ++++ b/test/meck_history_tests.erl +@@ -163,7 +163,7 @@ result_different_caller() -> + + history_kept_while_reloading() -> + NumCalls = 10, +- meck:new(historical, [non_strict, passtrough]), ++ meck:new(historical, [non_strict, passthrough]), + meck:expect(historical, test_fn, fun(Arg) -> {mocked, Arg} end), + Test = self(), + Caller = spawn(fun() -> +diff --git a/test/meck_tests.erl b/test/meck_tests.erl +index 270186c..f17223c 100644 +--- a/test/meck_tests.erl ++++ b/test/meck_tests.erl +@@ -811,6 +811,15 @@ expect_ret_specs_(Mod) -> + + %% --- Tests with own setup ---------------------------------------------------- + ++validate_options_test() -> ++ Mod = validate_options, ++ try ++ meck:new(Mod, passthrought), ++ throw(failed) ++ catch ++ error:function_clause -> ok ++ end. ++ + merge_expects_module_test() -> + Mod = merge_mod, + meck:new(Mod, [non_strict, merge_expects]), +-- +2.42.0.windows.2 + diff --git a/erlang-meck.spec b/erlang-meck.spec index 9d8c196d162da14b6993474c6f15b9cdd10600e5..e3d1a00f057ed77a597888129566bfe4acaba2bf 100644 --- a/erlang-meck.spec +++ b/erlang-meck.spec @@ -2,7 +2,7 @@ %global upstream eproxus Name: erlang-meck Version: 0.8.13 -Release: 2 +Release: 3 BuildArch: noarch Summary: A mocking library for Erlang License: ASL 2.0 @@ -14,6 +14,9 @@ BuildRequires: erlang-rebar Patch0002: 0001-Add-introspection-of-which-modules-are-currently-moc.patch + +Patch0008: 0001-Validate-the-options-being-passed-to-meck-new-204.patch + %description With meck you can easily mock modules in Erlang. Since meck is intended to be used in testing, you can also perform some basic validations on the mocked @@ -37,6 +40,9 @@ modules, such as making sure no function is called in a way it should not. %{erlang_appdir}/ %changelog +* Wed Jan 10 2024 liubo - 0.8.13-3 +- 0001-Change-to-matrix-build.patch + * Tue Dec 5 2023 liubo - 0.8.13-2 - Add introspection of which modules are currently mocked