Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
dc6bebc
add 17.0 to the test matrix
myers May 3, 2014
c5114e1
Merge pull request #122 from myers/erlang-17-travis
eproxus May 5, 2014
4a3b5c6
Update changelog
eproxus May 5, 2014
dde7590
Version 0.8.2
eproxus May 5, 2014
2eb1952
Clarify non_strict documentation
eproxus May 8, 2014
30a116a
Removed test and doc from target all in Makefile, since it was causin…
jfacorro Jun 18, 2014
b17651c
Updated README with instructions on how to run tests and generate the…
jfacorro Jun 23, 2014
3fa3e9b
Merge pull request #126 from inaka/jfacorro.remove.targets.from.make.all
eproxus Jul 1, 2014
63187e5
Add Hex.pm package specification
eproxus Aug 15, 2014
ba8c69d
Fix variable exported from case
Aug 26, 2014
eb479aa
Merge pull request #128 from hazardfn/variable-exported-from-case
eproxus Aug 26, 2014
b1f313b
Use flat badges
eproxus Sep 8, 2014
04d67d2
Swap out rebar for latest version (fix #124)
eproxus Oct 14, 2014
df1f877
Add erts to dialyzer apps
eproxus Nov 17, 2014
7fb5c61
Export missing type specification
eproxus Nov 17, 2014
dac5b77
Ignore dialyzer PLT file
eproxus Nov 17, 2014
0b571ef
Allow hiding 'on_load' attribute.
rlipscombe Nov 18, 2014
1643078
Rename 'hide_on_load' to 'enable_on_load'. Default false.
rlipscombe Nov 25, 2014
1ab5e23
Merge pull request #131 from rlipscombe/rl-hide-on-load
eproxus Nov 25, 2014
d15955c
Add Erlang 17.1 and 17.3 to build targets list
eproxus Dec 2, 2014
5064e36
Remove old version of R16B
eproxus Dec 2, 2014
78a2169
Update code climate badge to 17.3
eproxus Dec 2, 2014
fd1c793
Update Rebar example to use version 0.8.2
eproxus Dec 2, 2014
98cdc40
Document problematic modules
eproxus Feb 2, 2015
2b5bc62
Run tests in travis
Mar 29, 2015
b7024d3
Merge pull request #138 from gomoripeti/travis-run-tests
eproxus Mar 30, 2015
79cb5c9
Change macro name for namespaced types
Mar 28, 2015
e3c9d24
Update meck_cover for OTP 18.0
Mar 28, 2015
fa3cd97
Merge pull request #139 from gomoripeti/fix-cover-otp-18.0
eproxus Apr 1, 2015
247ba4b
Update build environment to 17.5
eproxus Apr 8, 2015
69664df
Use 17.5 since 17.5 is not available on Travis yet
eproxus Apr 8, 2015
81c8ab3
Fix typo
derek121 May 19, 2015
8de4a66
Merge pull request #143 from derek121/readme-typo
eproxus May 20, 2015
18a8e8c
Update Rebar to 2.5.1-19-g9c7dae7
eproxus Jun 9, 2015
ceb58ed
Inline import_original_cover
eproxus Jun 9, 2015
024ac69
Fix #114
eproxus Jun 9, 2015
e073427
Fix type specification
eproxus Jun 9, 2015
21034e6
Version 0.8.3
eproxus Jun 9, 2015
6c752a4
Add Hex.pm specification when tagging
eproxus Jun 9, 2015
17b0ea5
Update Hex.pm version
eproxus Jun 9, 2015
d0a3e5b
Bump Erlang version to 17.5
eproxus Jun 18, 2015
b066eeb
Update README.md to specify version 0.8.3
eproxus Jun 18, 2015
0c1c777
Revert "Bump Erlang version to 17.5"
eproxus Jun 18, 2015
e0c7c18
Document the caveat with mocking module-local calls.
bpuzon Jun 27, 2015
40e33d3
Merge pull request #145 from bpuzon/feature/local-call-caveat-doc
eproxus Jun 27, 2015
fc362e0
Set correct mix file
eproxus Jun 30, 2015
6b3eaf9
Tests for a race condition between meck:unload/1 and calls to the moc…
dszoboszlay Aug 19, 2015
4a941a2
Fix race condition between meck:unload/1 and calls to the mocked module
dszoboszlay Aug 20, 2015
710ad9a
Merge pull request #150 from dszoboszlay/bug/unload-race-condition
eproxus Aug 22, 2015
52b7a3f
FIX: optional_callbacks (but, it isn't the best practice)
soranoba Sep 7, 2015
796964c
Merge pull request #151 from soranoba/fix/optional_callbacks
eproxus Sep 7, 2015
01b9ad8
Update 'problematic modules list'
lilrooness Sep 17, 2015
0845277
Merge pull request #156 from lilrooness/master
eproxus Sep 19, 2015
403e2dd
Add donations section
eproxus Nov 5, 2015
762cd2f
Add merge_expects option to meck_proc
edgurgel Sep 8, 2015
b80f342
Merge pull request #153 from edgurgel/add-merge-expects-option
eproxus Nov 9, 2015
6eacbd7
Detail problems with mocking `timer`
eproxus Nov 9, 2015
be12fdf
Replace contributor list with link
eproxus Nov 9, 2015
4e05910
Merge remote-tracking branch 'upstream/master' into dr/merge_upstream…
Dec 22, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ tags
*.sublime-project
deps/*
.rebar
.deps.plt
4 changes: 4 additions & 0 deletions .scripts/tag_with_changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ git add CHANGELOG
# Update version in .app file
sed -i "" -e "s/{vsn, .*}/{vsn, \"$1\"}/g" src/meck.app.src
sed -i "" -e "s/@version .*/@version $1/g" doc/overview.edoc
sed -i "" -e "s/version: \".*\"/version: \"$1\"/g" package.exs
git add src/meck.app.src
git add doc/overview.edoc
git add package.exs

# Commit, tag and push
git commit -m "Version $1"
git tag -s $1 -m "Version $

$CHANGELOG"
git push && git push --tags
MIX_EXS=package.exs mix hex.publish

5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ notifications:
email:
- hello@alind.io
otp_release:
- 17.4
- R16B03-1
- R16B
- R15B03
before_script: "make get-deps"
script: "make all"
script: "make test"

3 changes: 1 addition & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
- The return value from passthrough/1 can now be used in expect
functions before returning

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PLTFILE=$(CURDIR)/.deps.plt
APP_DEPS=kernel stdlib eunit tools compiler
APP_DEPS=kernel stdlib eunit tools compiler erts
ERLFLAGS= -pa $(CURDIR)/.eunit -pa $(CURDIR)/ebin -pa $(CURDIR)/deps/*/ebin

REBAR="./rebar"
Expand All @@ -18,7 +18,7 @@ DIALYZER_INC=$(shell test -d include && echo '-I include') $(shell test -d deps
.PHONY: all rebuild compile doc clean test dialyzer typer get-deps clean-deps \
shell clean-plt clean-doc distclean

all: get-deps compile test doc
all: get-deps compile

rebuild: distclean get-deps all

Expand Down
101 changes: 71 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Release](http://img.shields.io/github/release/eproxus/meck.svg)](https://github.com/eproxus/meck/releases/latest)
[![Build Status](http://img.shields.io/travis/eproxus/meck.svg)](http://travis-ci.org/eproxus/meck)
[![Code Climate](http://img.shields.io/badge/code_climate-17.0-brightgreen.svg)](https://travis-ci.org/eproxus/meck)
[![Release](http://img.shields.io/github/release/eproxus/meck.svg?style=flat-square)](https://github.com/eproxus/meck/releases/latest)
[![Build Status](http://img.shields.io/travis/eproxus/meck.svg?style=flat-square)](http://travis-ci.org/eproxus/meck)
[![Code Climate](http://img.shields.io/badge/code_climate-Erlang_17.4-brightgreen.svg?style=flat-square)](https://travis-ci.org/eproxus/meck)

Meck
====
Expand Down Expand Up @@ -147,22 +147,33 @@ ok
Build
-----

Meck requires `make` and [rebar][1] to build. To build Meck and run tests, go to the Meck
directory and simply type:
Meck requires `make` and [rebar][1] to build. To build Meck go to the Meck directory
and simply type:

```sh
make
```

In order to run all tests for Meck type the following command from the same directory:

```sh
make test
```

Two things might seem alarming when running the tests:

1. Warnings emitted by cover
2. En exception printed by SASL
2. An exception printed by SASL

Both are expected due to the way Erlang currently prints errors. The
important line you should look for is `All XX tests passed`, if that
appears all is correct.

Documentation can be generated through the use of the following command:

```sh
make doc
```

<a name='install'>

Expand All @@ -175,7 +186,7 @@ your `rebar.config` in your project root:
```erlang
{deps, [
{meck, ".*",
{git, "https://github.com/eproxus/meck.git", {tag, "0.8"}}}
{git, "https://github.com/eproxus/meck.git", {tag, "0.8.3"}}}
]}.
```

Expand All @@ -187,6 +198,53 @@ environment variable.

<a name='contribute'>

Caveats
-------

Meck will have trouble mocking certain modules since Meck works by
recompiling and reloading modules. Since Erlang have a flat module
namespace, replacing a module has to be done globally in the
Erlang VM. This means certain modules cannot be mocked. The
following is a non-exhaustive list of modules that can either be
problematic to mock or not possible at all:

* `erlang`
* `os`
* `crypto`
* `compile`
* `global`
* `timer` (possible to mock, but used by some test frameworks, like Elixir's ExUnit)

Also, a meck expectation set up for a function _f_ does not apply to the module-local invocation of _f_ within the mocked module.
Consider the following module:
```
-module(test).
-export([a/0, b/0, c/0]).

a() ->
c().

b() ->
?MODULE:c().

c() ->
original.
```
Note how the module-local call to `c/0` in `a/0` stays unchanged even though the expectation changes the externally visible behaviour of `c/0`:

```
3> meck:new(test, [passthrough]).
ok
4> meck:expect(test,c,0,changed).
ok
5> test:a().
original
6> test:b().
changed
6> test:c().
changed
```

Contribute
----------

Expand All @@ -198,33 +256,16 @@ when developing new features or fixes for meck.
Should you find yourself using Meck and have issues, comments or
feedback please [create an issue here on GitHub][4].

Contributors:

- Maxim Vladimirsky (@horkhe)
- Ryan Zezeski (@rzezeski)
- David Haglund (@daha)
- Magnus Henoch (@legoscia)
- Susan Potter (@mbbx6spp)
- Andreas Amsenius (@adbl)
- Anthony Molinaro (@djnym)
- Matt Campbell (@xenolinguist)
- Martynas Pumputis (@brb)
- Shunichi Shinohara (@shino)
- Miëtek Bak
- Henry Nystrom
- Ward Bekker (@wardbekker)
- Damon Richardson
- Christopher Meiklejohn
- Joseph Wayne Norton (@norton)
- Erkan Yilmaz (@Erkan-Yilmaz)
- Joe Williams (@joewilliams)
- Russell Brown
- Michael Klishin (@michaelklishin)
- Magnus Klaar
Meck has been greatly improved by [many contributors]
(https://github.com/eproxus/meck/graphs/contributors)!

### Donations

If you or your company use Meck and find it useful, Bitcoin donations to the address `1M7pLbBpjkwxffT7kZPKhxiPGKf4eHDqtz` are greatly appreciated!

[1]: https://github.com/eproxus/meck/wiki/0.8-Release-Notes
"0.8 Release Notes"
[2]: https://github.com/hyperthunk/hamcrest-erlang "Hamcrest for Erlang"
[3]: https://github.com/basho/rebar "Rebar - A build tool for Erlang"
[4]: https://github.com/eproxus/meck/issues "Meck issues"

2 changes: 1 addition & 1 deletion doc/overview.edoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@author Adam Lindberg <eproxus@gmail.com>
@copyright 2011, Adam Lindberg & Erlang Solutions Ltd
@version "0.7.2"
@version 0.8.3
@title meck, a Mocking Library for Erlang

@doc
Expand Down
45 changes: 45 additions & 0 deletions package.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
defmodule Meck.Mixfile do
use Mix.Project

def project do
[
app: :meck,
version: "0.8.3",
description: description,
package: package,
deps: [],
]
end

defp description do
"""
A mocking framework for Erlang
"""
end

defp package do
[
files: [
"Makefile",
"rebar.config",
"test.config",
"src",
"test/*.erl",
"test/cover_test_module.dontcompile",
"test/include",
"README.md",
"LICENSE",
"CHANGELOG",
],
contributors: [
"Adam Lindberg",
],
licenses: [
"Apache 2.0",
],
links: %{
"GitHub" => "https://github.com/eproxus/meck",
},
]
end
end
Binary file modified rebar
Binary file not shown.
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% Compiler Options ===========================================================
{erl_opts, [
%% Erlang releases after 17 don't put R in front of their name, and also require dict() to be written like dict:dict()
{platform_define, "^[0-9]+", namespaced_dicts},
{platform_define, "^[0-9]+", namespaced_types},
warn_export_all,
warn_export_vars,
warn_shadow_vars,
Expand Down
9 changes: 8 additions & 1 deletion src/meck.erl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ new(Mod) when is_list(Mod) -> lists:foreach(fun new/1, Mod), ok.
%%
%% <dt>`non_strict'</dt>
%% <dd>A mock created with this option will allow setting expectations on
%% functions that are not exported from the mocked module. With this
%% functions that does not exist in the mocked module. With this
%% option on it is even possible to mock non existing modules.</dd>
%%
%% <dt>`{stub_all, '{@link ret_spec()}`}'</dt>
Expand All @@ -182,6 +182,13 @@ new(Mod) when is_list(Mod) -> lists:foreach(fun new/1, Mod), ok.
%% passed in. It is possible to specify this option as just `stub_all'
%% then stubs will return atom `ok'. If used along with `passthrough'
%% then `stub_all' is ignored. </dd>
%%
%% <dt>`merge_expects'</dt>
%% <dd>The expectations for the function/arity signature are merged with
%% existing ones instead of replacing all of them each time an
%% expectation is added. Expectations are added to the end of the
%% function clause list, meaning that pattern matching will be performed
%% in the order the expectations were added.</dd>
%% </dl>
-spec new(Mods, Options) -> ok when
Mods :: Mod | [Mod],
Expand Down
9 changes: 9 additions & 0 deletions src/meck_code.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
-export([compile_and_load_forms/1]).
-export([compile_and_load_forms/2]).
-export([compile_options/1]).
-export([enable_on_load/2]).
-export([rename_module/2]).

%% Types
Expand Down Expand Up @@ -89,6 +90,14 @@ compile_options(BeamFile) when is_binary(BeamFile) ->
compile_options(Module) ->
filter_options(proplists:get_value(options, Module:module_info(compile))).

enable_on_load(Forms, false) ->
Map = fun({attribute,L,on_load,{F,A}}) -> {attribute,L,export,[{F,A}]};
(Other) -> Other
end,
lists:map(Map, Forms);
enable_on_load(Forms, _) ->
Forms.

-spec rename_module(erlang_form(), module()) -> erlang_form().
rename_module([{attribute, Line, module, OldAttribute}|T], NewName) ->
case OldAttribute of
Expand Down
7 changes: 5 additions & 2 deletions src/meck_code_gen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ attributes(Mod) ->
try
[?attribute(Key, Val) || {Key, Val} <-
proplists:get_value(attributes, Mod:module_info(), []),
Key =/= vsn, Key =/= deprecated]
Key =/= vsn, Key =/= deprecated, Key =/= optional_callbacks]
catch
error:undef -> []
end.
Expand Down Expand Up @@ -144,7 +144,7 @@ var_name(A) -> list_to_atom("A"++integer_to_list(A)).
-spec exec(CallerPid::pid(), Mod::atom(), Func::atom(), Args::[any()]) ->
Result::any().
exec(Pid, Mod, Func, Args) ->
case meck_proc:get_result_spec(Mod, Func, Args) of
try meck_proc:get_result_spec(Mod, Func, Args) of
undefined ->
meck_proc:invalidate(Mod),
raise(Pid, Mod, Func, Args, error, function_clause);
Expand All @@ -160,6 +160,9 @@ exec(Pid, Mod, Func, Args) ->
after
erase(?CURRENT_CALL)
end
catch
error:{not_mocked, Mod} ->
apply(Mod, Func, Args)
end.

-spec handle_exception(CallerPid::pid(), Mod::atom(), Func::atom(),
Expand Down
Loading