Skip to content

Commit

Permalink
use eqc(mini) if it's defined, fetching proper otherwise
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Watson committed Nov 16, 2012
1 parent a45de8a commit 4e8d990
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ test/logs/
ebin/*.beam
logs/*
include/hamcrest.hrl
qc.hrl
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

all: clean build test
.PHONY: clean build test

all: clean test

clean:
@(./rebar clean)

build:
@(./rebar get-deps compile)

test:
@(./rebar skip_deps=true ct)
@(./rebar compile xref)

.PHONY: deps test clean build
test: build
@(./rebar -C test.config get-deps compile)
@(./rebar -C test.config skip_deps=true ct)
61 changes: 61 additions & 0 deletions priv/build/plugins/eqc_resolver.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
%% -----------------------------------------------------------------------------
%%
%% Hamcrest Erlang.
%%
%% Copyright (c) 2010 Tim Watson (watson.timothy@gmail.com)
%%
%% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal
%% in the Software without restriction, including without limitation the rights
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
%% copies of the Software, and to permit persons to whom the Software is
%% furnished to do so, subject to the following conditions:
%%
%% The above copyright notice and this permission notice shall be included in
%% all copies or substantial portions of the Software.
%%
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
%% THE SOFTWARE.
%% -----------------------------------------------------------------------------
%% @author Tim Watson <watson.timothy@gmail.com>
%% @copyright 2010 Tim Watson.
%%
%% Generates hamcrest.hrl header file during build process. Loaded by rebar.
%% -----------------------------------------------------------------------------
-module(eqc_resolver).

-export([preprocess/2]).

preprocess(Config, _) ->
case rebar_utils:processing_base_dir(Config) of
false -> {ok, []};
true -> case code:lib_dir(eqc, include) of
{error, bad_name} ->
write_include("proper"),
{ok, []};
_ ->
write_include("eqc"),
Deps = rebar_config:get_local(Config, deps, []),
DepsNoPropEr = proplists:delete(proper, Deps),
Config2 = rebar_config:set(Config, deps, DepsNoPropEr),
{ok, Config2, []}
end
end.

write_include(Lib) ->
file:write_file(filename:join(test_dir(), "qc.hrl"),
include(Lib)).

test_dir() ->
filename:join(rebar_utils:get_cwd(), "test").

include(Lib) ->
[<<"-include_lib(\"">>,
Lib, <<"/include/">>,
Lib, <<".hrl\").\n">>,
<<"-define(">>, Lib, <<", true).">>].
29 changes: 20 additions & 9 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@

{lib_dirs, ["deps"]}.
{erl_opts, [debug_info, fail_on_warning]}.
{cover_enabled, true}.
{clean_files, ["logs", "build", "include/hamcrest.hrl"]}.
{deps, [
{proper, "1.0", {git, "http://github.com/manopapad/proper.git", "master"}}
]}.

%{pre_hooks, [
% {compile, "sh priv/build/scripts/bootstrap-deps.sh"}
%]}.

{plugin_dir, "priv/build/plugins"}.
{plugins, [header_generator]}.
{plugins, [header_generator, eqc_resolver]}.

{xref_checks, []}.
{xref_queries,
[{"((XC - UC) || (XU - X - B))",[]}, %% calls to undefined functions
{"(L - LU)", []}, %% local unused
{"(LU * (X - XU))", [ %% exported functions only used locally
{hamcrest,assert_that,2}, %% NB: we're a library so this is expected...
{hamcrest,assert_that,3},
{hamcrest,check,2},
{hamcrest,describe,2},
{hamcrest,heckle,2},
{hamcrest,match,3},
{hamcrest_matchers,check_member,2}, %% called via apply/3
{hamcrest_matchers,equal_to,1},
{hamcrest_matchers,foreach,1},
{hamcrest_matchers,is_not,1},
{hamcrest_matchers,match_mfa,3},
{hamcrest_matchers,reverse_match_mfa,3}]},
{"(DF * (XU + LU))", []}]}.
9 changes: 9 additions & 0 deletions test.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

{cover_enabled, true}.
{deps, [
%% TODO: bind to a specific commit or tag instead of 'master'
{proper, "1.0", {git, "http://github.com/manopapad/proper.git", "master"}}
]}.

{plugin_dir, "priv/build/plugins"}.
{plugins, [eqc_resolver]}.
13 changes: 7 additions & 6 deletions include/test.hrl → test/test.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
Mod:module_info(exports)
)
],
ct:pal("registering ~p~n", [All]),
ct:log("registering ~p~n", [All]),
All).

%% NB: copied verbatim from eunit.hrl because proper_common.hrl redefined the LET macro,
Expand Down Expand Up @@ -71,9 +71,10 @@
end)())).

-define(EQC(P),
case code:lib_dir(eqc, include) of
{error, bad_name} ->
proper:quickcheck(P);
_ ->
eqc:check(P)
begin
Mod = case code:lib_dir(eqc, include) of
{error, bad_name} -> proper;
_ -> eqc
end,
true = Mod:quickcheck(P)
end).

0 comments on commit 4e8d990

Please sign in to comment.