Permalink
Browse files

Use separate dirs for eunit and qc

  • Loading branch information...
1 parent b5e0d6d commit e47d643ea3b490fd4835629e86d90fa3121122de @tuncer tuncer committed Aug 9, 2012
Showing with 57 additions and 52 deletions.
  1. +1 −1 dialyzer_reference
  2. +0 −2 include/rebar.hrl
  3. +9 −9 src/rebar_erlc_compiler.erl
  4. +23 −17 src/rebar_eunit.erl
  5. +11 −6 src/rebar_qc.erl
  6. +0 −4 src/rebar_utils.erl
  7. +13 −13 test/rebar_eunit_tests.erl
View
@@ -1,2 +1,2 @@
-rebar_utils.erl:164: Call to missing or unexported function escript:foldl/3
+rebar_utils.erl:163: Call to missing or unexported function escript:foldl/3
View
@@ -12,5 +12,3 @@
-define(ERROR(Str, Args), rebar_log:log(error, Str, Args)).
-define(FMT(Str, Args), lists:flatten(io_lib:format(Str, Args))).
-
--define(TEST_DIR, ".test").
@@ -30,7 +30,7 @@
clean/2]).
%% for internal use by only eunit and qc
--export([test_compile/2]).
+-export([test_compile/3]).
-include("rebar.hrl").
@@ -114,7 +114,7 @@ clean(_Config, _AppFile) ->
%% .erl Compilation API (externally used by only eunit and qc)
%% ===================================================================
-test_compile(Config, Cmd) ->
+test_compile(Config, Cmd, OutDir) ->
%% Obtain all the test modules for inclusion in the compile stage.
%% Notice: this could also be achieved with the following
%% rebar.config option: {test_compile_opts, [{src_dirs, ["test"]}]}
@@ -133,16 +133,16 @@ test_compile(Config, Cmd) ->
end, [], SrcDirs),
%% If it is not the first time rebar eunit is executed, there will be source
- %% files already present in ?TEST_DIR. Since some SCMs (like Perforce) set
+ %% files already present in OutDir. Since some SCMs (like Perforce) set
%% the source files as being read only (unless they are checked out), we
- %% need to be sure that the files already present in ?TEST_DIR are writable
+ %% need to be sure that the files already present in OutDir are writable
%% before doing the copy. This is done here by removing any file that was
%% already present before calling rebar_file_utils:cp_r.
- %% Get the full path to a file that was previously copied in ?TEST_DIR
+ %% Get the full path to a file that was previously copied in OutDir
ToCleanUp = fun(F, Acc) ->
F2 = filename:basename(F),
- F3 = filename:join([?TEST_DIR, F2]),
+ F3 = filename:join([OutDir, F2]),
case filelib:is_regular(F3) of
true -> [F3|Acc];
false -> Acc
@@ -152,12 +152,12 @@ test_compile(Config, Cmd) ->
ok = rebar_file_utils:delete_each(lists:foldl(ToCleanUp, [], TestErls)),
ok = rebar_file_utils:delete_each(lists:foldl(ToCleanUp, [], SrcErls)),
- ok = rebar_file_utils:cp_r(SrcErls ++ TestErls, ?TEST_DIR),
+ ok = rebar_file_utils:cp_r(SrcErls ++ TestErls, OutDir),
- %% Compile erlang code to ?TEST_DIR, using a tweaked config
+ %% Compile erlang code to OutDir, using a tweaked config
%% with appropriate defines for eunit, and include all the test modules
%% as well.
- ok = doterl_compile(test_compile_config(Config, Cmd), ?TEST_DIR, TestErls),
+ ok = doterl_compile(test_compile_config(Config, Cmd), OutDir, TestErls),
{ok, SrcErls}.
View
@@ -28,7 +28,7 @@
%% @doc rebar_eunit supports the following commands:
%% <ul>
%% <li>eunit - runs eunit tests</li>
-%% <li>clean - remove ?TEST_DIR directory</li>
+%% <li>clean - remove ?EUNIT_DIR directory</li>
%% <li>reset_after_eunit::boolean() - default = true.
%% If true, try to "reset" VM state to approximate state prior to
%% running the EUnit tests:
@@ -58,6 +58,8 @@
-include("rebar.hrl").
+-define(EUNIT_DIR, ".eunit").
+
%% ===================================================================
%% Public API
%% ===================================================================
@@ -68,7 +70,8 @@ eunit(Config, _AppFile) ->
CodePath = setup_code_path(),
CompileOnly = rebar_utils:get_experimental_global(Config, compile_only,
false),
- {ok, SrcErls} = rebar_erlc_compiler:test_compile(Config, "eunit"),
+ {ok, SrcErls} = rebar_erlc_compiler:test_compile(Config, "eunit",
+ ?EUNIT_DIR),
case CompileOnly of
"true" ->
true = code:set_path(CodePath),
@@ -78,14 +81,14 @@ eunit(Config, _AppFile) ->
end.
clean(_Config, _File) ->
- rebar_file_utils:rm_rf(?TEST_DIR).
+ rebar_file_utils:rm_rf(?EUNIT_DIR).
%% ===================================================================
%% Internal functions
%% ===================================================================
run_eunit(Config, CodePath, SrcErls) ->
- %% Build a list of all the .beams in ?TEST_DIR -- use this for
+ %% Build a list of all the .beams in ?EUNIT_DIR -- use this for
%% cover and eunit testing. Normally you can just tell cover
%% and/or eunit to scan the directory for you, but eunit does a
%% code:purge in conjunction with that scan and causes any cover
@@ -105,14 +108,14 @@ run_eunit(Config, CodePath, SrcErls) ->
%% the _tests module should only contain test cases that use the
%% public interface of the main module (and no other code)."
- AllBeamFiles = rebar_utils:beams(?TEST_DIR),
+ AllBeamFiles = rebar_utils:beams(?EUNIT_DIR),
{BeamFiles, TestBeamFiles} =
lists:partition(fun(N) -> string:str(N, "_tests.beam") =:= 0 end,
AllBeamFiles),
OtherBeamFiles = TestBeamFiles --
[filename:rootname(N) ++ "_tests.beam" || N <- AllBeamFiles],
ModuleBeamFiles = BeamFiles ++ OtherBeamFiles,
- Modules = [rebar_utils:beam_to_mod(?TEST_DIR, N) || N <- ModuleBeamFiles],
+ Modules = [rebar_utils:beam_to_mod(?EUNIT_DIR, N) || N <- ModuleBeamFiles],
SrcModules = [rebar_utils:erl_to_mod(M) || M <- SrcErls],
FilteredModules = filter_modules(Config, Modules),
@@ -144,17 +147,20 @@ run_eunit(Config, CodePath, SrcErls) ->
ok.
ensure_dirs() ->
- %% Make sure ?TEST_DIR/ and ebin/ directory exists (append dummy module)
- ok = filelib:ensure_dir(filename:join(rebar_utils:test_dir(), "dummy")),
+ %% Make sure ?EUNIT_DIR/ and ebin/ directory exists (append dummy module)
+ ok = filelib:ensure_dir(filename:join(eunit_dir(), "dummy")),
ok = filelib:ensure_dir(filename:join(rebar_utils:ebin_dir(), "dummy")).
+eunit_dir() ->
+ filename:join(rebar_utils:get_cwd(), ?EUNIT_DIR).
+
setup_code_path() ->
%% Setup code path prior to compilation so that parse_transforms
%% and the like work properly. Also, be sure to add ebin_dir()
%% to the END of the code path so that we don't have to jump
%% through hoops to access the .app file
CodePath = code:get_path(),
- true = code:add_patha(rebar_utils:test_dir()),
+ true = code:add_patha(eunit_dir()),
true = code:add_pathz(rebar_utils:ebin_dir()),
CodePath.
@@ -171,10 +177,10 @@ filter_modules1(Modules, Suites) ->
perform_eunit(Config, FilteredModules) ->
EunitOpts = get_eunit_opts(Config),
- %% Move down into ?TEST_DIR while we run tests so any generated files
+ %% Move down into ?EUNIT_DIR while we run tests so any generated files
%% are created there (versus in the source dir)
Cwd = rebar_utils:get_cwd(),
- ok = file:set_cwd(?TEST_DIR),
+ ok = file:set_cwd(?EUNIT_DIR),
EunitResult = (catch eunit:test(FilteredModules, EunitOpts)),
@@ -218,7 +224,7 @@ cover_analyze(Config, FilteredModules, SrcModules) ->
[html])
end, Coverage),
- Index = filename:join([rebar_utils:get_cwd(), ?TEST_DIR, "index.html"]),
+ Index = filename:join([rebar_utils:get_cwd(), ?EUNIT_DIR, "index.html"]),
?CONSOLE("Cover analysis: ~s\n", [Index]),
%% Export coverage data, if configured
@@ -246,7 +252,7 @@ cover_init(false, _BeamFiles) ->
{ok, not_enabled};
cover_init(true, BeamFiles) ->
%% Attempt to start the cover server, then set it's group leader to
- %% ?TEST_DIR/cover.log, so all cover log messages will go there instead of
+ %% ?EUNIT_DIR/cover.log, so all cover log messages will go there instead of
%% to stdout. If the cover server is already started we'll reuse that
%% pid.
{ok, CoverPid} = case cover:start() of
@@ -259,7 +265,7 @@ cover_init(true, BeamFiles) ->
end,
{ok, F} = OkOpen = file:open(
- filename:join([?TEST_DIR, "cover.log"]),
+ filename:join([?EUNIT_DIR, "cover.log"]),
[write]),
group_leader(F, CoverPid),
@@ -334,7 +340,7 @@ align_notcovered_count(Module, Covered, NotCovered, true) ->
{Module, Covered, NotCovered - 1}.
cover_write_index(Coverage, SrcModules) ->
- {ok, F} = file:open(filename:join([?TEST_DIR, "index.html"]), [write]),
+ {ok, F} = file:open(filename:join([?EUNIT_DIR, "index.html"]), [write]),
ok = file:write(F, "<html><head><title>Coverage Summary</title></head>\n"),
IsSrcCoverage = fun({Mod,_C,_N}) -> lists:member(Mod, SrcModules) end,
{SrcCoverage, TestCoverage} = lists:partition(IsSrcCoverage, Coverage),
@@ -392,10 +398,10 @@ cover_print_coverage(Coverage) ->
?CONSOLE("~n~*s : ~s~n", [Width, "Total", TotalCoverage]).
cover_file(Module) ->
- filename:join([?TEST_DIR, atom_to_list(Module) ++ ".COVER.html"]).
+ filename:join([?EUNIT_DIR, atom_to_list(Module) ++ ".COVER.html"]).
cover_export_coverdata() ->
- ExportFile = filename:join(rebar_utils:test_dir(), "eunit.coverdata"),
+ ExportFile = filename:join(eunit_dir(), "eunit.coverdata"),
case cover:export(ExportFile) of
ok ->
?CONSOLE("Coverdata export: ~s~n", [ExportFile]);
View
@@ -30,6 +30,8 @@
-include("rebar.hrl").
+-define(QC_DIR, ".qc").
+
%% ===================================================================
%% Public API
%% ===================================================================
@@ -104,22 +106,25 @@ load_qc_mod(Mod) ->
setup_codepath() ->
CodePath = code:get_path(),
- true = code:add_patha(rebar_utils:test_dir()),
- true = code:add_patha(rebar_utils:ebin_dir()),
+ true = code:add_patha(qc_dir()),
+ true = code:add_pathz(rebar_utils:ebin_dir()),
CodePath.
+qc_dir() ->
+ filename:join(rebar_utils:get_cwd(), ?QC_DIR).
+
run(Config, QC, QCOpts) ->
?DEBUG("qc_opts: ~p~n", [QCOpts]),
- ok = filelib:ensure_dir(?TEST_DIR ++ "/foo"),
+ ok = filelib:ensure_dir(filename:join(qc_dir(), "foo")),
CodePath = setup_codepath(),
CompileOnly = rebar_utils:get_experimental_global(Config, compile_only,
false),
- %% Compile erlang code to ?TEST_DIR, using a tweaked config
+ %% Compile erlang code to ?QC_DIR, using a tweaked config
%% with appropriate defines, and include all the test modules
%% as well.
- {ok, _SrcErls} = rebar_erlc_compiler:test_compile(Config, "qc"),
+ {ok, _SrcErls} = rebar_erlc_compiler:test_compile(Config, "qc", ?QC_DIR),
case CompileOnly of
"true" ->
@@ -150,7 +155,7 @@ qc_module(QC=triq, _QCOpts, M) ->
qc_module(QC=eqc, QCOpts, M) -> QC:module(QCOpts, M).
find_prop_mods() ->
- Beams = rebar_utils:find_files(?TEST_DIR, ".*\\.beam\$"),
+ Beams = rebar_utils:find_files(?QC_DIR, ".*\\.beam\$"),
[M || M <- [rebar_utils:erl_to_mod(Beam) || Beam <- Beams], has_prop(M)].
has_prop(Mod) ->
View
@@ -51,7 +51,6 @@
delayed_halt/1,
erl_opts/1,
src_dirs/1,
- test_dir/0,
ebin_dir/0,
processing_base_dir/1, processing_base_dir/2]).
@@ -319,9 +318,6 @@ src_dirs([]) ->
src_dirs(SrcDirs) ->
SrcDirs.
-test_dir() ->
- filename:join(get_cwd(), ?TEST_DIR).
-
ebin_dir() ->
filename:join(get_cwd(), "ebin").
@@ -35,7 +35,7 @@
-include_lib("eunit/include/eunit.hrl").
%% Assuming this test is run inside the rebar 'eunit'
-%% command, the current working directory will be '.test'
+%% command, the current working directory will be '.eunit'
-define(REBAR_SCRIPT, "../rebar").
-define(TMP_DIR, "tmp_eunit/").
@@ -70,7 +70,7 @@ cover_test_() ->
{"Only production modules get coverage reports",
assert_files_not_in("the temporary eunit directory",
- [".test/myapp_mymod_tests.COVER.html"])}]}.
+ [".eunit/myapp_mymod_tests.COVER.html"])}]}.
cover_with_suite_test_() ->
{"Ensure Cover runs with Tests in a test dir and a test suite",
@@ -83,21 +83,21 @@ cover_with_suite_test_() ->
[{"Cover reports are generated for module",
assert_files_in("the temporary eunit directory",
- [".test/index.html",
- ".test/mysuite.COVER.html"])},
+ [".eunit/index.html",
+ ".eunit/mysuite.COVER.html"])},
{"Only production modules get coverage reports",
assert_files_not_in("the temporary eunit directory",
- [".test/myapp_app.COVER.html",
- ".test/myapp_mymod.COVER.html",
- ".test/myapp_sup.COVER.html",
- ".test/myapp_mymod_tests.COVER.html"])}]}.
+ [".eunit/myapp_app.COVER.html",
+ ".eunit/myapp_mymod.COVER.html",
+ ".eunit/myapp_sup.COVER.html",
+ ".eunit/myapp_mymod_tests.COVER.html"])}]}.
expected_cover_generated_files() ->
- [".test/index.html",
- ".test/myapp_app.COVER.html",
- ".test/myapp_mymod.COVER.html",
- ".test/myapp_sup.COVER.html"].
+ [".eunit/index.html",
+ ".eunit/myapp_app.COVER.html",
+ ".eunit/myapp_mymod.COVER.html",
+ ".eunit/myapp_sup.COVER.html"].
cover_coverage_test_() ->
{"Coverage is accurately calculated",
@@ -246,7 +246,7 @@ assert_files_not_in(_, []) -> [].
assert_full_coverage(Mod) ->
fun() ->
- {ok, F} = file:read_file(".test/index.html"),
+ {ok, F} = file:read_file(".eunit/index.html"),
Result = [X || X <- string:tokens(binary_to_list(F), "\n"),
string:str(X, Mod) =/= 0,
string:str(X, "100%") =/= 0],

0 comments on commit e47d643

Please sign in to comment.