Abort if xref emits warnings

This commit is contained in:
Shunichi Shinohara 2011-03-29 22:43:53 +09:00 committed by Tuncer Ayaz
parent d7f5016920
commit 862ae1f192

View file

@ -61,54 +61,59 @@ xref(Config, _) ->
undefined_function_calls]), undefined_function_calls]),
%% Look for exports that are unused by anything %% Look for exports that are unused by anything
ExportsNoWarn =
case lists:member(exports_not_used, XrefChecks) of case lists:member(exports_not_used, XrefChecks) of
true -> true ->
check_exports_not_used(Config); check_exports_not_used();
false -> false ->
ok true
end, end,
%% Look for calls to undefined functions %% Look for calls to undefined functions
UndefNoWarn =
case lists:member(undefined_function_calls, XrefChecks) of case lists:member(undefined_function_calls, XrefChecks) of
true -> true ->
check_undefined_function_calls(Config); check_undefined_function_calls();
false -> false ->
ok true
end, end,
%% Restore the original code path %% Restore the original code path
true = code:set_path(OrigPath), true = code:set_path(OrigPath),
%% Stop xref %% Stop xref
stopped = xref:stop(xref), stopped = xref:stop(xref),
ok. case lists:all(fun(NoWarn) -> NoWarn end, [ExportsNoWarn, UndefNoWarn]) of
true ->
ok;
false ->
?FAIL
end.
%% =================================================================== %% ===================================================================
%% Internal functions %% Internal functions
%% =================================================================== %% ===================================================================
check_exports_not_used(_Config) -> check_exports_not_used() ->
{ok, UnusedExports0} = xref:analyze(xref, exports_not_used), {ok, UnusedExports0} = xref:analyze(xref, exports_not_used),
UnusedExports = filter_away_ignored(UnusedExports0), UnusedExports = filter_away_ignored(UnusedExports0),
%% Report all the unused functions %% Report all the unused functions
display_mfas(UnusedExports, "is unused export (Xref)"), display_mfas(UnusedExports, "is unused export (Xref)"),
ok. UnusedExports =:= [].
check_undefined_function_calls(_Config) -> check_undefined_function_calls() ->
{ok, UndefinedCalls0} = xref:analyze(xref, undefined_function_calls), {ok, UndefinedCalls0} = xref:analyze(xref, undefined_function_calls),
UndefinedCalls = UndefinedCalls =
[{find_mfa_source(Caller), format_fa(Caller), format_mfa(Target)} || [{find_mfa_source(Caller), format_fa(Caller), format_mfa(Target)}
{Caller, Target} <- UndefinedCalls0], || {Caller, Target} <- UndefinedCalls0],
lists:foreach( lists:foreach(
fun({{Source, Line}, FunStr, Target}) -> fun({{Source, Line}, FunStr, Target}) ->
?CONSOLE("~s:~w: Warning ~s calls undefined function ~s\n", ?CONSOLE("~s:~w: Warning ~s calls undefined function ~s\n",
[Source, Line, FunStr, Target]) [Source, Line, FunStr, Target])
end, UndefinedCalls), end, UndefinedCalls),
ok. UndefinedCalls =:= [].
code_path() -> code_path() ->
[P || P <- code:get_path(), [P || P <- code:get_path(),