diff options
| author | OJ Reeves <oj@buffered.io> | 2010-02-03 22:27:09 +1000 | 
|---|---|---|
| committer | OJ Reeves <oj@buffered.io> | 2010-02-03 22:27:09 +1000 | 
| commit | 71c974e341173da9c5da6f6d6781e2ee52aec251 (patch) | |
| tree | 6abcce5d025501ca05a031118e91a926b63f4afa /src | |
| parent | 6c359a08cde153f53cb735a134d8bedf1a99919b (diff) | |
Added support for the speficiation of test suite names
eg.  rebar eunit              -- runs all tests in all modules
     rebar eunit suite=foo    -- only runs tests in foo.erl/foo_tests.erl
Added an entry to .hgignore to avoid .swp files (created by VIM).
Diffstat (limited to 'src')
| -rw-r--r-- | src/rebar_eunit.erl | 39 | 
1 files changed, 35 insertions, 4 deletions
| diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl index 6ef7a25..b98a4f9 100644 --- a/src/rebar_eunit.erl +++ b/src/rebar_eunit.erl @@ -51,9 +51,13 @@ eunit(Config, _File) ->      %% Make sure ?EUNIT_DIR/ directory exists (tack on dummy module)      ok = filelib:ensure_dir(?EUNIT_DIR ++ "/foo"), +    %% grab all the test modules for inclusion in the compile stage +    TestErls = rebar_utils:find_files("test", ".*\\.erl\$"), +      %% Compile erlang code to ?EUNIT_DIR, using a tweaked config -    %% with appropriate defines for eunit -    rebar_erlc_compiler:doterl_compile(eunit_config(Config), ?EUNIT_DIR), +    %% with appropriate defines for eunit, and include all the test modules +    %% as well. +    rebar_erlc_compiler:doterl_compile(eunit_config(Config), ?EUNIT_DIR, TestErls),      %% 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 @@ -62,8 +66,35 @@ eunit(Config, _File) ->      %% we do it by hand. :(      %%      %% TODO: Not currently compatible with package modules -    Modules = [list_to_atom(filename:basename(N, ".beam")) || -                  N <- filelib:wildcard("*.beam", ?EUNIT_DIR)], +    Beams = [filename:basename(N, ".beam") || N <- filelib:wildcard("*.beam", ?EUNIT_DIR)], + +    %% Grab two lists of test and non-test beam files +    {TestBeams, ModuleBeams} = lists:partition(fun(B) -> +                                    lists:suffix("_tests", B) end, Beams), + +    case rebar_config:get_global(suite, undefined) of +        undefined -> +            %% no suite defined, so include all modules +            RealModules = ModuleBeams, + +            %% exclude any test modules that have a matching module +            TestModules = [T || T <- TestBeams, +                              lists:member(string:left(T, length(T) - 6), RealModules) == false]; +        SuiteName -> +            %% suite defined, so only specify the module that relates to the +            %% suite (if any) +            RealModules = [M || M <- ModuleBeams, SuiteName =:= M], + +            %% only include the test suite if the main module doesn't exist +            TestModules = case length(RealModules) of +                              0 -> [T || T <- TestBeams, T =:= SuiteName ++ "_tests"]; +                              _ -> [] +                          end +    end, + +    %% combine the modules and associated test modules into the resulting list +    %% of modules to run tests on. +    Modules = [list_to_atom(M) || M <- RealModules ++ TestModules],      %% TODO: If there are other wildcards specified in eunit_sources, compile them | 
