You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/02/03 13:59:41 UTC
[02/27] Build with rebar
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f84eb4fc/src/rebar/src/rebar_utils.erl
----------------------------------------------------------------------
diff --git a/src/rebar/src/rebar_utils.erl b/src/rebar/src/rebar_utils.erl
deleted file mode 100644
index 618427f..0000000
--- a/src/rebar/src/rebar_utils.erl
+++ /dev/null
@@ -1,510 +0,0 @@
-%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ts=4 sw=4 et
-%% -------------------------------------------------------------------
-%%
-%% rebar: Erlang Build Tools
-%%
-%% Copyright (c) 2009, 2010 Dave Smith (dizzyd@dizzyd.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.
-%% -------------------------------------------------------------------
--module(rebar_utils).
-
--export([get_cwd/0,
- is_arch/1,
- get_arch/0,
- wordsize/0,
- sh/2,
- find_files/2, find_files/3,
- now_str/0,
- ensure_dir/1,
- beam_to_mod/2, beams/1,
- erl_to_mod/1,
- abort/0, abort/2,
- escript_foldl/3,
- find_executable/1,
- prop_check/3,
- expand_code_path/0,
- expand_env_variable/3,
- vcs_vsn/3,
- deprecated/3, deprecated/4,
- get_deprecated_global/4, get_deprecated_global/5,
- get_experimental_global/3, get_experimental_local/3,
- get_deprecated_list/4, get_deprecated_list/5,
- get_deprecated_local/4, get_deprecated_local/5,
- delayed_halt/1,
- erl_opts/1,
- src_dirs/1,
- ebin_dir/0,
- processing_base_dir/1, processing_base_dir/2]).
-
--include("rebar.hrl").
-
-%% ====================================================================
-%% Public API
-%% ====================================================================
-
-get_cwd() ->
- {ok, Dir} = file:get_cwd(),
- Dir.
-
-is_arch(ArchRegex) ->
- case re:run(get_arch(), ArchRegex, [{capture, none}]) of
- match ->
- true;
- nomatch ->
- false
- end.
-
-get_arch() ->
- Words = wordsize(),
- erlang:system_info(otp_release) ++ "-"
- ++ erlang:system_info(system_architecture) ++ "-" ++ Words.
-
-wordsize() ->
- try erlang:system_info({wordsize, external}) of
- Val ->
- integer_to_list(8 * Val)
- catch
- error:badarg ->
- integer_to_list(8 * erlang:system_info(wordsize))
- end.
-
-%%
-%% Options = [Option] -- defaults to [use_stdout, abort_on_error]
-%% Option = ErrorOption | OutputOption | {cd, string()} | {env, Env}
-%% ErrorOption = return_on_error | abort_on_error | {abort_on_error, string()}
-%% OutputOption = use_stdout | {use_stdout, bool()}
-%% Env = [{string(), Val}]
-%% Val = string() | false
-%%
-sh(Command0, Options0) ->
- ?INFO("sh info:\n\tcwd: ~p\n\tcmd: ~s\n", [get_cwd(), Command0]),
- ?DEBUG("\topts: ~p\n", [Options0]),
-
- DefaultOptions = [use_stdout, abort_on_error],
- Options = [expand_sh_flag(V)
- || V <- proplists:compact(Options0 ++ DefaultOptions)],
-
- ErrorHandler = proplists:get_value(error_handler, Options),
- OutputHandler = proplists:get_value(output_handler, Options),
-
- Command = patch_on_windows(Command0, proplists:get_value(env, Options, [])),
- PortSettings = proplists:get_all_values(port_settings, Options) ++
- [exit_status, {line, 16384}, use_stdio, stderr_to_stdout, hide],
- ?DEBUG("Port Cmd: ~p\nPort Opts: ~p\n", [Command, PortSettings]),
- Port = open_port({spawn, Command}, PortSettings),
-
- case sh_loop(Port, OutputHandler, []) of
- {ok, _Output} = Ok ->
- Ok;
- {error, {_Rc, _Output}=Err} ->
- ErrorHandler(Command, Err)
- end.
-
-find_files(Dir, Regex) ->
- find_files(Dir, Regex, true).
-
-find_files(Dir, Regex, Recursive) ->
- filelib:fold_files(Dir, Regex, Recursive,
- fun(F, Acc) -> [F | Acc] end, []).
-
-now_str() ->
- {{Year, Month, Day}, {Hour, Minute, Second}} = calendar:local_time(),
- lists:flatten(io_lib:format("~4b/~2..0b/~2..0b ~2..0b:~2..0b:~2..0b",
- [Year, Month, Day, Hour, Minute, Second])).
-
-%% TODO: filelib:ensure_dir/1 corrected in R13B04. Remove when we drop
-%% support for OTP releases older than R13B04.
-ensure_dir(Path) ->
- case filelib:ensure_dir(Path) of
- ok ->
- ok;
- {error,eexist} ->
- ok;
- Error ->
- Error
- end.
-
--spec abort() -> no_return().
-abort() ->
- throw(rebar_abort).
-
--spec abort(string(), [term()]) -> no_return().
-abort(String, Args) ->
- ?ERROR(String, Args),
- abort().
-
-%% TODO: Rename emulate_escript_foldl to escript_foldl and remove
-%% this function when the time is right. escript:foldl/3 was an
-%% undocumented exported fun and has been removed in R14.
-escript_foldl(Fun, Acc, File) ->
- {module, zip} = code:ensure_loaded(zip),
- case erlang:function_exported(zip, foldl, 3) of
- true ->
- emulate_escript_foldl(Fun, Acc, File);
- false ->
- escript:foldl(Fun, Acc, File)
- end.
-
-find_executable(Name) ->
- case os:find_executable(Name) of
- false -> false;
- Path ->
- "\"" ++ filename:nativename(Path) ++ "\""
- end.
-
-%% Helper function for checking values and aborting when needed
-prop_check(true, _, _) -> true;
-prop_check(false, Msg, Args) -> ?ABORT(Msg, Args).
-
-%% Convert all the entries in the code path to absolute paths.
-expand_code_path() ->
- CodePath = lists:foldl(fun(Path, Acc) ->
- [filename:absname(Path) | Acc]
- end, [], code:get_path()),
- code:set_path(lists:reverse(CodePath)).
-
-%%
-%% Given env. variable FOO we want to expand all references to
-%% it in InStr. References can have two forms: $FOO and ${FOO}
-%% The end of form $FOO is delimited with whitespace or eol
-%%
-expand_env_variable(InStr, VarName, RawVarValue) ->
- case string:chr(InStr, $$) of
- 0 ->
- %% No variables to expand
- InStr;
- _ ->
- ReOpts = [global, unicode, {return, list}],
- VarValue = re:replace(RawVarValue, "\\\\", "\\\\\\\\", ReOpts),
- %% Use a regex to match/replace:
- %% Given variable "FOO": match $FOO\s | $FOOeol | ${FOO}
- RegEx = io_lib:format("\\\$(~s(\\s|$)|{~s})", [VarName, VarName]),
- re:replace(InStr, RegEx, [VarValue, "\\2"], ReOpts)
- end.
-
-vcs_vsn(Config, Vsn, Dir) ->
- Key = {Vsn, Dir},
- Cache = rebar_config:get_xconf(Config, vsn_cache),
- case dict:find(Key, Cache) of
- error ->
- VsnString = vcs_vsn_1(Vsn, Dir),
- Cache1 = dict:store(Key, VsnString, Cache),
- Config1 = rebar_config:set_xconf(Config, vsn_cache, Cache1),
- {Config1, VsnString};
- {ok, VsnString} ->
- {Config, VsnString}
- end.
-
-get_deprecated_global(Config, OldOpt, NewOpt, When) ->
- get_deprecated_global(Config, OldOpt, NewOpt, undefined, When).
-
-get_deprecated_global(Config, OldOpt, NewOpt, Default, When) ->
- get_deprecated_3(fun rebar_config:get_global/3,
- Config, OldOpt, NewOpt, Default, When).
-
-get_experimental_global(Config, Opt, Default) ->
- get_experimental_3(fun rebar_config:get_global/3, Config, Opt, Default).
-
-get_experimental_local(Config, Opt, Default) ->
- get_experimental_3(fun rebar_config:get_local/3, Config, Opt, Default).
-
-get_deprecated_list(Config, OldOpt, NewOpt, When) ->
- get_deprecated_list(Config, OldOpt, NewOpt, undefined, When).
-
-get_deprecated_list(Config, OldOpt, NewOpt, Default, When) ->
- get_deprecated_3(fun rebar_config:get_list/3,
- Config, OldOpt, NewOpt, Default, When).
-
-get_deprecated_local(Config, OldOpt, NewOpt, When) ->
- get_deprecated_local(Config, OldOpt, NewOpt, undefined, When).
-
-get_deprecated_local(Config, OldOpt, NewOpt, Default, When) ->
- get_deprecated_3(fun rebar_config:get_local/3,
- Config, OldOpt, NewOpt, Default, When).
-
-deprecated(Old, New, Opts, When) when is_list(Opts) ->
- case lists:member(Old, Opts) of
- true ->
- deprecated(Old, New, When);
- false ->
- ok
- end;
-deprecated(Old, New, Config, When) ->
- case rebar_config:get(Config, Old, undefined) of
- undefined ->
- ok;
- _ ->
- deprecated(Old, New, When)
- end.
-
-deprecated(Old, New, When) ->
- io:format(
- <<"WARNING: deprecated ~p option used~n"
- "Option '~p' has been deprecated~n"
- "in favor of '~p'.~n"
- "'~p' will be removed ~s.~n~n">>,
- [Old, Old, New, Old, When]).
-
--spec delayed_halt(integer()) -> no_return().
-delayed_halt(Code) ->
- %% Work around buffer flushing issue in erlang:halt if OTP older
- %% than R15B01.
- %% TODO: remove workaround once we require R15B01 or newer
- %% R15B01 introduced erlang:halt/2
- case erlang:is_builtin(erlang, halt, 2) of
- true ->
- halt(Code);
- false ->
- case os:type() of
- {win32, nt} ->
- timer:sleep(100),
- halt(Code);
- _ ->
- halt(Code),
- %% workaround to delay exit until all output is written
- receive after infinity -> ok end
- end
- end.
-
-%% @doc Return list of erl_opts
--spec erl_opts(rebar_config:config()) -> list().
-erl_opts(Config) ->
- RawErlOpts = filter_defines(rebar_config:get(Config, erl_opts, []), []),
- Defines = [{d, list_to_atom(D)} ||
- D <- rebar_config:get_xconf(Config, defines, [])],
- Opts = Defines ++ RawErlOpts,
- case proplists:is_defined(no_debug_info, Opts) of
- true ->
- [O || O <- Opts, O =/= no_debug_info];
- false ->
- [debug_info|Opts]
- end.
-
--spec src_dirs([string()]) -> [file:filename(), ...].
-src_dirs([]) ->
- ["src"];
-src_dirs(SrcDirs) ->
- SrcDirs.
-
-ebin_dir() ->
- filename:join(get_cwd(), "ebin").
-
-processing_base_dir(Config) ->
- Cwd = rebar_utils:get_cwd(),
- processing_base_dir(Config, Cwd).
-
-processing_base_dir(Config, Dir) ->
- Dir =:= rebar_config:get_xconf(Config, base_dir).
-
-%% ====================================================================
-%% Internal functions
-%% ====================================================================
-
-get_deprecated_3(Get, Config, OldOpt, NewOpt, Default, When) ->
- case Get(Config, NewOpt, Default) of
- Default ->
- case Get(Config, OldOpt, Default) of
- Default ->
- Default;
- Old ->
- deprecated(OldOpt, NewOpt, When),
- Old
- end;
- New ->
- New
- end.
-
-get_experimental_3(Get, Config, Opt, Default) ->
- Val = Get(Config, Opt, Default),
- case Val of
- Default ->
- Default;
- Val ->
- ?CONSOLE("NOTICE: Using experimental option '~p'~n", [Opt]),
- Val
- end.
-
-%% We do the shell variable substitution ourselves on Windows and hope that the
-%% command doesn't use any other shell magic.
-patch_on_windows(Cmd, Env) ->
- case os:type() of
- {win32,nt} ->
- Cmd1 = "cmd /q /c "
- ++ lists:foldl(fun({Key, Value}, Acc) ->
- expand_env_variable(Acc, Key, Value)
- end, Cmd, Env),
- %% Remove left-over vars
- re:replace(Cmd1, "\\\$\\w+|\\\${\\w+}", "",
- [global, {return, list}]);
- _ ->
- Cmd
- end.
-
-expand_sh_flag(return_on_error) ->
- {error_handler,
- fun(_Command, Err) ->
- {error, Err}
- end};
-expand_sh_flag({abort_on_error, Message}) ->
- {error_handler,
- log_msg_and_abort(Message)};
-expand_sh_flag(abort_on_error) ->
- {error_handler,
- fun log_and_abort/2};
-expand_sh_flag(use_stdout) ->
- {output_handler,
- fun(Line, Acc) ->
- ?CONSOLE("~s", [Line]),
- [Line | Acc]
- end};
-expand_sh_flag({use_stdout, false}) ->
- {output_handler,
- fun(Line, Acc) ->
- [Line | Acc]
- end};
-expand_sh_flag({cd, _CdArg} = Cd) ->
- {port_settings, Cd};
-expand_sh_flag({env, _EnvArg} = Env) ->
- {port_settings, Env}.
-
--type err_handler() :: fun((string(), {integer(), string()}) -> no_return()).
--spec log_msg_and_abort(string()) -> err_handler().
-log_msg_and_abort(Message) ->
- fun(_Command, {_Rc, _Output}) ->
- ?ABORT(Message, [])
- end.
-
--spec log_and_abort(string(), {integer(), string()}) -> no_return().
-log_and_abort(Command, {Rc, Output}) ->
- ?ABORT("~s failed with error: ~w and output:~n~s~n",
- [Command, Rc, Output]).
-
-sh_loop(Port, Fun, Acc) ->
- receive
- {Port, {data, {eol, Line}}} ->
- sh_loop(Port, Fun, Fun(Line ++ "\n", Acc));
- {Port, {data, {noeol, Line}}} ->
- sh_loop(Port, Fun, Fun(Line, Acc));
- {Port, {exit_status, 0}} ->
- {ok, lists:flatten(lists:reverse(Acc))};
- {Port, {exit_status, Rc}} ->
- {error, {Rc, lists:flatten(lists:reverse(Acc))}}
- end.
-
-beam_to_mod(Dir, Filename) ->
- [Dir | Rest] = filename:split(Filename),
- list_to_atom(filename:basename(string:join(Rest, "."), ".beam")).
-
-erl_to_mod(Filename) ->
- list_to_atom(filename:rootname(filename:basename(Filename))).
-
-beams(Dir) ->
- filelib:fold_files(Dir, ".*\.beam\$", true,
- fun(F, Acc) -> [F | Acc] end, []).
-
-emulate_escript_foldl(Fun, Acc, File) ->
- case escript:extract(File, [compile_source]) of
- {ok, [_Shebang, _Comment, _EmuArgs, Body]} ->
- case Body of
- {source, BeamCode} ->
- GetInfo = fun() -> file:read_file_info(File) end,
- GetBin = fun() -> BeamCode end,
- {ok, Fun(".", GetInfo, GetBin, Acc)};
- {beam, BeamCode} ->
- GetInfo = fun() -> file:read_file_info(File) end,
- GetBin = fun() -> BeamCode end,
- {ok, Fun(".", GetInfo, GetBin, Acc)};
- {archive, ArchiveBin} ->
- zip:foldl(Fun, Acc, {File, ArchiveBin})
- end;
- {error, _} = Error ->
- Error
- end.
-
-vcs_vsn_1(Vcs, Dir) ->
- case vcs_vsn_cmd(Vcs) of
- {plain, VsnString} ->
- VsnString;
- {cmd, CmdString} ->
- vcs_vsn_invoke(CmdString, Dir);
- unknown ->
- ?ABORT("vcs_vsn: Unknown vsn format: ~p\n", [Vcs]);
- Cmd ->
- %% If there is a valid VCS directory in the application directory,
- %% use that version info
- Extension = lists:concat([".", Vcs]),
- case filelib:is_dir(filename:join(Dir, Extension)) of
- true ->
- ?DEBUG("vcs_vsn: Primary vcs used for ~s\n", [Dir]),
- vcs_vsn_invoke(Cmd, Dir);
- false ->
- %% No VCS directory found for the app. Depending on source
- %% tree structure, there may be one higher up, but that can
- %% yield unexpected results when used with deps. So, we
- %% fallback to searching for a priv/vsn.Vcs file.
- VsnFile = filename:join([Dir, "priv", "vsn" ++ Extension]),
- case file:read_file(VsnFile) of
- {ok, VsnBin} ->
- ?DEBUG("vcs_vsn: Read ~s from priv/vsn.~p\n",
- [VsnBin, Vcs]),
- string:strip(binary_to_list(VsnBin), right, $\n);
- {error, enoent} ->
- ?DEBUG("vcs_vsn: Fallback to vcs for ~s\n", [Dir]),
- vcs_vsn_invoke(Cmd, Dir)
- end
- end
- end.
-
-vcs_vsn_cmd(git) -> "git describe --always --tags";
-vcs_vsn_cmd(hg) -> "hg identify -i";
-vcs_vsn_cmd(bzr) -> "bzr revno";
-vcs_vsn_cmd(svn) -> "svnversion";
-vcs_vsn_cmd(fossil) -> "fossil info";
-vcs_vsn_cmd({cmd, _Cmd}=Custom) -> Custom;
-vcs_vsn_cmd(Version) when is_list(Version) -> {plain, Version};
-vcs_vsn_cmd(_) -> unknown.
-
-vcs_vsn_invoke(Cmd, Dir) ->
- {ok, VsnString} = rebar_utils:sh(Cmd, [{cd, Dir}, {use_stdout, false}]),
- string:strip(VsnString, right, $\n).
-
-%%
-%% Filter a list of erl_opts platform_define options such that only
-%% those which match the provided architecture regex are returned.
-%%
-filter_defines([], Acc) ->
- lists:reverse(Acc);
-filter_defines([{platform_define, ArchRegex, Key} | Rest], Acc) ->
- case rebar_utils:is_arch(ArchRegex) of
- true ->
- filter_defines(Rest, [{d, Key} | Acc]);
- false ->
- filter_defines(Rest, Acc)
- end;
-filter_defines([{platform_define, ArchRegex, Key, Value} | Rest], Acc) ->
- case rebar_utils:is_arch(ArchRegex) of
- true ->
- filter_defines(Rest, [{d, Key, Value} | Acc]);
- false ->
- filter_defines(Rest, Acc)
- end;
-filter_defines([Opt | Rest], Acc) ->
- filter_defines(Rest, [Opt | Acc]).
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f84eb4fc/src/rebar/src/rebar_xref.erl
----------------------------------------------------------------------
diff --git a/src/rebar/src/rebar_xref.erl b/src/rebar/src/rebar_xref.erl
deleted file mode 100644
index eaf6d03..0000000
--- a/src/rebar/src/rebar_xref.erl
+++ /dev/null
@@ -1,287 +0,0 @@
-%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ts=4 sw=4 et
-%% -------------------------------------------------------------------
-%%
-%% rebar: Erlang Build Tools
-%%
-%% Copyright (c) 2009 Dave Smith (dizzyd@dizzyd.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.
-%%
-%% -------------------------------------------------------------------
-
-%% -------------------------------------------------------------------
-%% This module borrows heavily from http://github.com/etnt/exrefcheck project as
-%% written by Torbjorn Tornkvist <to...@kreditor.se>, Daniel Luna
-%% <da...@lunas.se> and others.
-%% -------------------------------------------------------------------
--module(rebar_xref).
-
--include("rebar.hrl").
-
--export([xref/2]).
-
-%% for internal use only
--export([info/2]).
-
-%% ===================================================================
-%% Public API
-%% ===================================================================
-
-xref(Config, _) ->
- %% Spin up xref
- {ok, _} = xref:start(xref),
- ok = xref:set_library_path(xref, code_path(Config)),
-
- xref:set_default(xref, [{warnings,
- rebar_config:get(Config, xref_warnings, false)},
- {verbose, rebar_config:is_verbose(Config)}]),
-
- {ok, _} = xref:add_directory(xref, "ebin"),
-
- %% Save the code path prior to doing anything
- OrigPath = code:get_path(),
- true = code:add_path(rebar_utils:ebin_dir()),
-
- %% Get list of xref checks we want to run
- ConfXrefChecks = rebar_config:get(Config, xref_checks,
- [exports_not_used,
- undefined_function_calls]),
-
- SupportedXrefs = [undefined_function_calls, undefined_functions,
- locals_not_used, exports_not_used,
- deprecated_function_calls, deprecated_functions],
-
- XrefChecks = sets:to_list(sets:intersection(
- sets:from_list(SupportedXrefs),
- sets:from_list(ConfXrefChecks))),
-
- %% Run xref checks
- XrefNoWarn = xref_checks(XrefChecks),
-
- %% Run custom queries
- QueryChecks = rebar_config:get(Config, xref_queries, []),
- QueryNoWarn = lists:all(fun check_query/1, QueryChecks),
-
- %% Restore the original code path
- true = code:set_path(OrigPath),
-
- %% Stop xref
- stopped = xref:stop(xref),
-
- case lists:member(false, [XrefNoWarn, QueryNoWarn]) of
- true ->
- ?FAIL;
- false ->
- ok
- end.
-
-%% ===================================================================
-%% Internal functions
-%% ===================================================================
-
-info(help, xref) ->
- ?CONSOLE(
- "Run cross reference analysis.~n"
- "~n"
- "Valid rebar.config options:~n"
- " ~p~n"
- " ~p~n"
- " ~p~n",
- [
- {xref_warnings, false},
- {xref_checks, [undefined_function_calls, undefined_functions,
- locals_not_used, exports_not_used,
- deprecated_function_calls, deprecated_functions]},
- {xref_queries,
- [{"(xc - uc) || (xu - x - b"
- " - (\"mod\":\".*foo\"/\"4\"))",[]}]}
- ]).
-
-xref_checks(XrefChecks) ->
- XrefWarnCount = lists:foldl(fun run_xref_check/2, 0, XrefChecks),
- XrefWarnCount =:= 0.
-
-run_xref_check(XrefCheck, Acc) ->
- {ok, Results} = xref:analyze(xref, XrefCheck),
- FilteredResults =filter_xref_results(XrefCheck, Results),
- lists:foreach(fun(Res) ->
- display_xref_result(XrefCheck, Res)
- end,
- FilteredResults),
- Acc + length(FilteredResults).
-
-check_query({Query, Value}) ->
- {ok, Answer} = xref:q(xref, Query),
- case Answer =:= Value of
- false ->
- ?CONSOLE("Query ~s~n answer ~p~n did not match ~p~n",
- [Query, Answer, Value]),
- false;
- _ ->
- true
- end.
-
-code_path(Config) ->
- %% Slight hack to ensure that sub_dirs get properly included
- %% in code path for xref -- otherwise one gets a lot of undefined
- %% functions, even though those functions are present as part
- %% of compilation. H/t to @dluna. Long term we should tie more
- %% properly into the overall compile code path if possible.
- BaseDir = rebar_config:get_xconf(Config, base_dir),
- [P || P <- code:get_path() ++
- [filename:join(BaseDir, filename:join(SubDir, "ebin"))
- || SubDir <- rebar_config:get(Config, sub_dirs, [])],
- filelib:is_dir(P)].
-
-%%
-%% Ignore behaviour functions, and explicitly marked functions
-%%
-%% Functions can be ignored by using
-%% -ignore_xref([{F, A}, {M, F, A}...]).
-
-get_xref_ignorelist(Mod, XrefCheck) ->
- %% Get ignore_xref attribute and combine them in one list
- Attributes =
- try
- Mod:module_info(attributes)
- catch
- _Class:_Error -> []
- end,
-
- IgnoreXref = keyall(ignore_xref, Attributes),
-
- BehaviourCallbacks = get_behaviour_callbacks(XrefCheck, Attributes),
-
- %% And create a flat {M,F,A} list
- lists:foldl(
- fun({F, A}, Acc) -> [{Mod,F,A} | Acc];
- ({M, F, A}, Acc) -> [{M,F,A} | Acc]
- end, [], lists:flatten([IgnoreXref, BehaviourCallbacks])).
-
-keyall(Key, List) ->
- lists:flatmap(fun({K, L}) when Key =:= K -> L; (_) -> [] end, List).
-
-get_behaviour_callbacks(exports_not_used, Attributes) ->
- [B:behaviour_info(callbacks) || B <- keyall(behaviour, Attributes)];
-get_behaviour_callbacks(_XrefCheck, _Attributes) ->
- [].
-
-parse_xref_result({_, MFAt}) -> MFAt;
-parse_xref_result(MFAt) -> MFAt.
-
-filter_xref_results(XrefCheck, XrefResults) ->
- SearchModules = lists:usort(
- lists:map(
- fun({Mt,_Ft,_At}) -> Mt;
- ({{Ms,_Fs,_As},{_Mt,_Ft,_At}}) -> Ms;
- (_) -> undefined
- end, XrefResults)),
-
- Ignores = lists:flatmap(fun(Module) ->
- get_xref_ignorelist(Module, XrefCheck)
- end, SearchModules),
-
- [Result || Result <- XrefResults,
- not lists:member(parse_xref_result(Result), Ignores)].
-
-display_xref_result(Type, XrefResult) ->
- { Source, SMFA, TMFA } = case XrefResult of
- {MFASource, MFATarget} ->
- {format_mfa_source(MFASource),
- format_mfa(MFASource),
- format_mfa(MFATarget)};
- MFATarget ->
- {format_mfa_source(MFATarget),
- format_mfa(MFATarget),
- undefined}
- end,
- case Type of
- undefined_function_calls ->
- ?CONSOLE("~sWarning: ~s calls undefined function ~s (Xref)\n",
- [Source, SMFA, TMFA]);
- undefined_functions ->
- ?CONSOLE("~sWarning: ~s is undefined function (Xref)\n",
- [Source, SMFA]);
- locals_not_used ->
- ?CONSOLE("~sWarning: ~s is unused local function (Xref)\n",
- [Source, SMFA]);
- exports_not_used ->
- ?CONSOLE("~sWarning: ~s is unused export (Xref)\n",
- [Source, SMFA]);
- deprecated_function_calls ->
- ?CONSOLE("~sWarning: ~s calls deprecated function ~s (Xref)\n",
- [Source, SMFA, TMFA]);
- deprecated_functions ->
- ?CONSOLE("~sWarning: ~s is deprecated function (Xref)\n",
- [Source, SMFA]);
- Other ->
- ?CONSOLE("~sWarning: ~s - ~s xref check: ~s (Xref)\n",
- [Source, SMFA, TMFA, Other])
- end.
-
-format_mfa({M, F, A}) ->
- ?FMT("~s:~s/~w", [M, F, A]).
-
-format_mfa_source(MFA) ->
- case find_mfa_source(MFA) of
- {module_not_found, function_not_found} -> "";
- {Source, function_not_found} -> ?FMT("~s: ", [Source]);
- {Source, Line} -> ?FMT("~s:~w: ", [Source, Line])
- end.
-
-%%
-%% Extract an element from a tuple, or undefined if N > tuple size
-%%
-safe_element(N, Tuple) ->
- case catch(element(N, Tuple)) of
- {'EXIT', {badarg, _}} ->
- undefined;
- Value ->
- Value
- end.
-
-%%
-%% Given a MFA, find the file and LOC where it's defined. Note that
-%% xref doesn't work if there is no abstract_code, so we can avoid
-%% being too paranoid here.
-%%
-find_mfa_source({M, F, A}) ->
- case code:get_object_code(M) of
- error -> {module_not_found, function_not_found};
- {M, Bin, _} -> find_function_source(M,F,A,Bin)
- end.
-
-find_function_source(M, F, A, Bin) ->
- AbstractCode = beam_lib:chunks(Bin, [abstract_code]),
- {ok, {M, [{abstract_code, {raw_abstract_v1, Code}}]}} = AbstractCode,
- %% Extract the original source filename from the abstract code
- [{attribute, 1, file, {Source, _}} | _] = Code,
- %% Extract the line number for a given function def
- Fn = [E || E <- Code,
- safe_element(1, E) == function,
- safe_element(3, E) == F,
- safe_element(4, E) == A],
- case Fn of
- [{function, Line, F, _, _}] -> {Source, Line};
- %% do not crash if functions are exported, even though they
- %% are not in the source.
- %% parameterized modules add new/1 and instance/1 for example.
- [] -> {Source, function_not_found}
- end.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f84eb4fc/src/rebar/test/rebar_eunit_tests.erl
----------------------------------------------------------------------
diff --git a/src/rebar/test/rebar_eunit_tests.erl b/src/rebar/test/rebar_eunit_tests.erl
deleted file mode 100644
index 61a9bbf..0000000
--- a/src/rebar/test/rebar_eunit_tests.erl
+++ /dev/null
@@ -1,434 +0,0 @@
-%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ts=4 sw=4 et
-%% -------------------------------------------------------------------
-%%
-%% rebar: Erlang Build Tools
-%%
-%% Copyright (c) 2009, 2010 Dave Smith (dizzyd@dizzyd.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 Chris Bernard <ce...@gmail.com>
-%% @doc This tests functionality provided by the rebar command 'eunit'.
-%% @copyright 2009, 2010 Dave Smith
-%% -------------------------------------------------------------------
--module(rebar_eunit_tests).
-
--compile(export_all).
-
--include_lib("eunit/include/eunit.hrl").
-
-%% Assuming this test is run inside the rebar 'eunit'
-%% command, the current working directory will be '.eunit'
--define(REBAR_SCRIPT, "../rebar").
-
--define(TMP_DIR, "tmp_eunit/").
-
-%% ====================================================================
-%% Rebar EUnit and Cover Tests
-%% ====================================================================
-
-eunit_test_() ->
- {"Ensure EUnit runs with tests in a 'test' dir and no defined suite",
- setup, fun() -> setup_basic_project(), rebar("-v eunit") end,
- fun teardown/1,
- fun(RebarOut) ->
- [{"Tests in 'test' directory are found and run",
- ?_assert(string:str(RebarOut, "myapp_mymod_tests:") =/= 0)},
-
- {"Tests in 'src' directory are found and run",
- ?_assert(string:str(RebarOut, "myapp_mymod:") =/= 0)},
-
- {"Tests are only run once",
- ?_assert(string:str(RebarOut, "All 2 tests passed") =/= 0)}]
- end}.
-
-eunit_with_suites_and_tests_test_() ->
- [{"Ensure EUnit runs selected suites",
- setup, fun() ->
- setup_project_with_multiple_modules(),
- rebar("-v eunit suites=myapp_mymod2")
- end,
- fun teardown/1,
- fun(RebarOut) ->
- [{"Selected suite tests in 'test' directory are found and run",
- ?_assert(string:str(RebarOut, "myapp_mymod2_tests:") =/= 0)},
-
- {"Selected suite tests in 'src' directory are found and run",
- ?_assert(string:str(RebarOut, "myapp_mymod2:") =/= 0)},
-
- {"Unselected suite tests in 'test' directory are not run",
- ?_assert(string:str(RebarOut, "myapp_mymod_tests:") =:= 0)},
-
- {"Unselected suite tests in 'src' directory are not run",
- ?_assert(string:str(RebarOut, "myapp_mymod:") =:= 0)},
-
- {"Selected suite tests are only run once",
- ?_assert(string:str(RebarOut, "All 4 tests passed") =/= 0)}]
- end},
- {"Ensure EUnit runs selected _tests suites",
- setup, fun() ->
- setup_project_with_multiple_modules(),
- rebar("-v eunit suites=myapp_mymod2_tests")
- end,
- fun teardown/1,
- fun(RebarOut) ->
- [{"Selected suite tests in 'test' directory are found and run",
- ?_assert(string:str(RebarOut, "myapp_mymod2_tests:") =/= 0)},
-
- {"Selected suite tests in 'src' directory are not run",
- ?_assert(string:str(RebarOut, "myapp_mymod2:") =:= 0)},
-
- {"Unselected suite tests in 'test' directory are not run",
- ?_assert(string:str(RebarOut, "myapp_mymod_tests:") =:= 0)},
-
- {"Unselected suite tests in 'src' directory are not run",
- ?_assert(string:str(RebarOut, "myapp_mymod:") =:= 0)},
-
- {"Selected suite tests are only run once",
- ?_assert(string:str(RebarOut, "All 2 tests passed") =/= 0)}]
- end},
- {"Ensure EUnit runs a specific test defined in a selected suite",
- setup, fun() ->
- setup_project_with_multiple_modules(),
- rebar("-v eunit suites=myapp_mymod2 tests=myprivate2")
- end,
- fun teardown/1,
- fun(RebarOut) ->
- [{"Selected suite tests are found and run",
- ?_assert(string:str(RebarOut,
- "myapp_mymod2:myprivate2_test/0") =/= 0)},
-
- {"Selected suite tests is run once",
- ?_assert(string:str(RebarOut, "Test passed") =/= 0)}]
- end},
- {"Ensure EUnit runs a specific generator test defined in a selected suite",
- setup, fun() ->
- setup_project_with_multiple_modules(),
- rebar("-v eunit suites=myapp_mymod3 tests=mygenerator")
- end,
- fun teardown/1,
- fun(RebarOut) ->
- [{"Selected suite's generator test is found and run",
- ?_assert(string:str(RebarOut,
- "myapp_mymod3:mygenerator_test_/0") =/= 0)},
-
- {"Selected suite's generator test raises an error",
- ?_assert(string:str(RebarOut,
- "assertEqual_failed") =/= 0)},
-
- {"Selected suite tests is run once",
- ?_assert(string:str(RebarOut, "Failed: 1.") =/= 0)}]
- end},
- {"Ensure EUnit runs specific tests defined in selected suites",
- setup, fun() ->
- setup_project_with_multiple_modules(),
- rebar("-v eunit suites=myapp_mymod,myapp_mymod2"
- " tests=myprivate,myfunc2")
- end,
- fun teardown/1,
- fun(RebarOut) ->
- [{"Selected suite tests are found and run",
- [?_assert(string:str(RebarOut,
- "myapp_mymod:myprivate_test/0") =/= 0),
- ?_assert(string:str(RebarOut,
- "myapp_mymod2:myprivate2_test/0") =/= 0),
- ?_assert(
- string:str(RebarOut,
- "myapp_mymod2_tests:myfunc2_test/0") =/= 0)]},
-
- {"Selected suite tests are run once",
- ?_assert(string:str(RebarOut, "All 3 tests passed") =/= 0)}]
- end},
- {"Ensure EUnit runs specific test in a _tests suite",
- setup,
- fun() ->
- setup_project_with_multiple_modules(),
- rebar("-v eunit suites=myapp_mymod2_tests tests=common_name_test")
- end,
- fun teardown/1,
- fun(RebarOut) ->
- [{"Only selected suite tests are found and run",
- [?_assert(string:str(RebarOut,
- "myapp_mymod2:common_name_test/0") =:= 0),
- ?_assert(string:str(RebarOut,
- "myapp_mymod2_tests:common_name_test/0")
- =/= 0)]},
-
- {"Selected suite tests is run once",
- ?_assert(string:str(RebarOut, "Test passed") =/= 0)}]
- end},
- {"Ensure EUnit runs a specific test without a specified suite",
- setup,
- fun() ->
- setup_project_with_multiple_modules(),
- rebar("-v eunit tests=myprivate")
- end,
- fun teardown/1,
- fun(RebarOut) ->
- [{"Only selected suite tests are found and run",
- [?_assert(string:str(RebarOut,
- "myapp_mymod:myprivate_test/0") =/= 0),
- ?_assert(string:str(RebarOut,
- "myapp_mymod2:myprivate2_test/0")
- =/= 0)]},
-
- {"Selected suite tests is run once",
- ?_assert(string:str(RebarOut, "All 2 tests passed") =/= 0)}]
- end}].
-
-cover_test_() ->
- {"Ensure Cover runs with tests in a test dir and no defined suite",
- setup, fun() -> setup_cover_project(), rebar("-v eunit") end,
- fun teardown/1,
-
- fun(RebarOut) ->
- [{"Error messages are not present",
- ?_assert(string:str(RebarOut, "Cover analyze failed for") =:= 0)},
-
- {"All cover reports are generated",
- assert_files_in("the temporary eunit directory",
- expected_cover_generated_files())},
-
- {"Only production modules get coverage reports",
- assert_files_not_in("the temporary eunit directory",
- [".eunit/myapp_mymod_tests.COVER.html"])}]
- end}.
-
-cover_with_suite_test_() ->
- {"Ensure Cover runs with Tests in a test dir and a test suite",
- setup,
- fun() ->
- setup_cover_project_with_suite(),
- rebar("-v eunit suites=mysuite")
- end,
- fun teardown/1,
-
- fun(RebarOut) ->
- [{"Error messages are not present",
- ?_assert(string:str(RebarOut, "Cover analyze failed for") =:= 0)},
-
- {"Cover reports are generated for module",
- assert_files_in("the temporary eunit directory",
- [".eunit/index.html",
- ".eunit/mysuite.COVER.html"])},
-
- {"Only production modules get coverage reports",
- assert_files_not_in("the temporary eunit directory",
- [".eunit/myapp_app.COVER.html",
- ".eunit/myapp_mymod.COVER.html",
- ".eunit/myapp_sup.COVER.html",
- ".eunit/myapp_mymod_tests.COVER.html"])}]
- end}.
-
-expected_cover_generated_files() ->
- [".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",
- setup, fun() -> setup_cover_project(), rebar("-v eunit") end,
- fun teardown/1,
-
- [{"Modules that include the EUnit header can still have 100% coverage",
- %% cover notices the implicit EUnit test/0 func that never gets
- %% called during eunit:test(TestRepresentation), so NotCounted
- %% needs to be decremented in this case.
- assert_full_coverage("myapp_mymod")}]}.
-
-%% ====================================================================
-%% Environment and Setup Tests
-%% ====================================================================
-
-environment_test_() ->
- {"Sanity check the testing environment",
- setup, fun make_tmp_dir/0, fun remove_tmp_dir/1,
-
- [{"Ensure a test project can be created",
- ?_assert(filelib:is_dir(?TMP_DIR))},
-
- {"Ensure the rebar script can be found, copied, and run",
- [?_assert(filelib:is_regular(?REBAR_SCRIPT)),
- fun assert_rebar_runs/0]}]}.
-
-assert_rebar_runs() ->
- prepare_rebar_script(),
- ?assert(string:str(os:cmd(filename:nativename("./" ++ ?TMP_DIR ++ "rebar")),
- "No command to run specified!") =/= 0).
-
-basic_setup_test_() ->
- {"Create a simple project with a 'test' directory, a test, and a module",
- setup, fun setup_basic_project/0, fun teardown/1,
-
- %% Test the setup function
- assert_dirs_in("Basic Project",
- ["src", "ebin", "test"]) ++
- assert_files_in("Basic Project",
- ["test/myapp_mymod_tests.erl",
- "src/myapp_mymod.erl"])}.
-
-%% ====================================================================
-%% Setup and Teardown
-%% ====================================================================
-
--define(myapp_mymod,
- ["-module(myapp_mymod).\n",
- "-export([myfunc/0]).\n",
- "-include_lib(\"eunit/include/eunit.hrl\").\n",
- "myfunc() -> ok.\n",
- "myprivate_test() -> ?assert(true).\n"]).
-
--define(myapp_mymod_tests,
- ["-module(myapp_mymod_tests).\n",
- "-compile([export_all]).\n",
- "-include_lib(\"eunit/include/eunit.hrl\").\n",
- "myfunc_test() -> ?assertMatch(ok, myapp_mymod:myfunc()).\n"]).
-
--define(myapp_mymod2,
- ["-module(myapp_mymod2).\n",
- "-export([myfunc2/0]).\n",
- "-include_lib(\"eunit/include/eunit.hrl\").\n",
- "myfunc2() -> ok.\n",
- "myprivate2_test() -> ?assert(true).\n",
- "common_name_test() -> ?assert(true).\n"]).
-
--define(myapp_mymod2_tests,
- ["-module(myapp_mymod2_tests).\n",
- "-compile([export_all]).\n",
- "-include_lib(\"eunit/include/eunit.hrl\").\n",
- "myfunc2_test() -> ?assertMatch(ok, myapp_mymod2:myfunc2()).\n",
- "common_name_test() -> ?assert(true).\n"]).
-
--define(myapp_mymod3,
- ["-module(myapp_mymod3).\n",
- "-export([myfunc3/0]).\n",
- "-include_lib(\"eunit/include/eunit.hrl\").\n",
- "myfunc3() -> ok.\n",
- "mygenerator_test_() -> [?_assertEqual(true, false)].\n"]).
-
--define(mysuite,
- ["-module(mysuite).\n",
- "-export([all_test_/0]).\n",
- "-include_lib(\"eunit/include/eunit.hrl\").\n",
- "all_test_() -> [myapp_mymod_defined_in_mysuite_tests].\n"]).
-
--define(myapp_mymod_defined_in_mysuite_tests,
- ["-module(myapp_mymod_defined_in_mysuite_tests).\n",
- "-compile([export_all]).\n",
- "-include_lib(\"eunit/include/eunit.hrl\").\n",
- "myfunc_test() -> ?assertMatch(ok, myapp_mymod:myfunc()).\n"]).
-
-make_tmp_dir() ->
- case file:make_dir(?TMP_DIR) of
- ok ->
- ok;
- {error, eexist} ->
- remove_tmp_dir(),
- make_tmp_dir();
- Error ->
- throw(Error)
- end.
-
-setup_environment() ->
- ok = make_tmp_dir(),
- prepare_rebar_script(),
- ok = file:set_cwd(?TMP_DIR).
-
-setup_basic_project() ->
- setup_environment(),
- rebar("create-app appid=myapp"),
- ok = file:make_dir("ebin"),
- ok = file:make_dir("test"),
- ok = file:write_file("test/myapp_mymod_tests.erl", ?myapp_mymod_tests),
- ok = file:write_file("src/myapp_mymod.erl", ?myapp_mymod).
-
-setup_project_with_multiple_modules() ->
- setup_basic_project(),
- ok = file:write_file("test/myapp_mymod2_tests.erl", ?myapp_mymod2_tests),
- ok = file:write_file("src/myapp_mymod2.erl", ?myapp_mymod2),
- ok = file:write_file("src/myapp_mymod3.erl", ?myapp_mymod3).
-
-setup_cover_project() ->
- setup_basic_project(),
- ok = file:write_file("rebar.config", "{cover_enabled, true}.\n").
-
-setup_cover_project_with_suite() ->
- setup_cover_project(),
- ok = file:write_file("test/mysuite.erl", ?mysuite),
- ok = file:write_file("test/myapp_mymod_defined_in_mysuite_tests.erl",
- ?myapp_mymod_defined_in_mysuite_tests).
-
-teardown(_) ->
- ok = file:set_cwd(".."),
- ok = remove_tmp_dir().
-
-remove_tmp_dir() ->
- remove_tmp_dir(arg_for_eunit).
-
-remove_tmp_dir(_) ->
- ok = rebar_file_utils:rm_rf(?TMP_DIR).
-
-%% ====================================================================
-%% Helper Functions
-%% ====================================================================
-
-prepare_rebar_script() ->
- Rebar = ?TMP_DIR ++ "rebar",
- {ok, _} = file:copy(?REBAR_SCRIPT, Rebar),
- case os:type() of
- {unix, _} ->
- [] = os:cmd("chmod u+x " ++ Rebar);
- {win32, _} ->
- {ok, _} = file:copy(?REBAR_SCRIPT ++ ".cmd",
- ?TMP_DIR ++ "rebar.cmd")
- end.
-
-rebar() ->
- rebar([]).
-
-rebar(Args) when is_list(Args) ->
- Out = os:cmd(filename:nativename("./rebar") ++ " " ++ Args),
- %% ?debugMsg("**** Begin"), ?debugMsg(Out), ?debugMsg("**** End"),
- Out.
-
-assert_dirs_in(Name, [Dir|T]) ->
- [{Name ++ " has directory: " ++ Dir, ?_assert(filelib:is_dir(Dir))} |
- assert_dirs_in(Name, T)];
-assert_dirs_in(_, []) -> [].
-
-assert_files_in(Name, [File|T]) ->
- [{Name ++ " has file: " ++ File, ?_assert(filelib:is_regular(File))} |
- assert_files_in(Name, T)];
-assert_files_in(_, []) -> [].
-
-assert_files_not_in(Name, [File|T]) ->
- [{Name ++ " does not have file: " ++ File,
- ?_assertNot(filelib:is_regular(File))} | assert_files_not_in(Name, T)];
-assert_files_not_in(_, []) -> [].
-
-assert_full_coverage(Mod) ->
- fun() ->
- {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],
- ?assert(length(Result) =:= 1)
- end.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f84eb4fc/src/rebar/test/rebar_file_utils_tests.erl
----------------------------------------------------------------------
diff --git a/src/rebar/test/rebar_file_utils_tests.erl b/src/rebar/test/rebar_file_utils_tests.erl
deleted file mode 100644
index 26a6f9f..0000000
--- a/src/rebar/test/rebar_file_utils_tests.erl
+++ /dev/null
@@ -1,278 +0,0 @@
-%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ts=4 sw=4 et
-%% -------------------------------------------------------------------
-%%
-%% rebar: Erlang Build Tools
-%%
-%% Copyright (c) 2009, 2010 Dave Smith (dizzyd@dizzyd.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 Juhani Rankimies <ju...@juranki.com>
-%% @doc Tests functionality of rebar_file_utils module.
-%% @copyright 2009, 2010 Dave Smith
-%% -------------------------------------------------------------------
--module(rebar_file_utils_tests).
-
--compile(export_all).
-
--include_lib("eunit/include/eunit.hrl").
-
--define(TMP_DIR, "tmp_file_utils").
--define(DIR_TREE, [{d,"source",[{f,"file1"},
- {f,"file2"}]},
- {d,"dest",[]}]).
--define(FILE_CONTENT, <<"1234567890">>).
-
-%% ====================================================================
-%% delete_each tests
-%% ====================================================================
-
-delete_bogus_test_() ->
- {"delete_each survives nonexisting files",
- [?_assertMatch(ok, rebar_file_utils:delete_each(["bogus"])),
- ?_assertMatch(ok, rebar_file_utils:delete_each(["bogus1","bogus2"]))]}.
-
-delete_each_test_() ->
- {"delete_each removes files",
- setup,
- fun() ->
- setup(),
- rebar_file_utils:delete_each(file_list())
- end,
- fun teardown/1,
- [assert_files_not_in("source", file_list())]}.
-
-%% ====================================================================
-%% rm_rf tests
-%% ====================================================================
-
-rm_rf_wildcard_test_() ->
- {"rm_rf removes files based on wildcard spec",
- setup,
- fun() ->
- setup(),
- rebar_file_utils:rm_rf(filename:join([?TMP_DIR,"source","file*"]))
- end,
- fun teardown/1,
- [assert_files_not_in("source", file_list())]}.
-
-rm_rf_dir_test_() ->
- {"rm_rf removes directory tree",
- setup,
- fun() ->
- setup(),
- rebar_file_utils:rm_rf(filename:join([?TMP_DIR,"source"]))
- end,
- fun teardown/1,
- [?_assertNot(filelib:is_dir(filename:join([?TMP_DIR,"source"])))]}.
-
-%% ====================================================================
-%% cp_r tests
-%% ====================================================================
-
-cp_r_file_to_file_test_() ->
- {"cp_r copies a file to file",
- setup,
- fun() ->
- setup(),
- rebar_file_utils:cp_r([filename:join([?TMP_DIR,"source","file1"])],
- filename:join([?TMP_DIR,"dest","new_file"]))
- end,
- fun teardown/1,
- [?_assert(filelib:is_regular(filename:join([?TMP_DIR,"dest","new_file"])))]}.
-
-cp_r_file_to_dir_test_() ->
- {"cp_r copies a file to directory",
- setup,
- fun() ->
- setup(),
- rebar_file_utils:cp_r([filename:join([?TMP_DIR,"source","file1"])],
- filename:join([?TMP_DIR,"dest"]))
- end,
- fun teardown/1,
- [?_assert(filelib:is_regular(filename:join([?TMP_DIR,"dest","file1"])))]}.
-
-cp_r_dir_to_dir_test_() ->
- {"cp_r copies a directory to directory",
- setup,
- fun() ->
- setup(),
- rebar_file_utils:cp_r([filename:join([?TMP_DIR,"source"])],
- filename:join([?TMP_DIR,"dest"]))
- end,
- fun teardown/1,
- [?_assert(filelib:is_dir(filename:join([?TMP_DIR,"dest","source"]))),
- assert_files_in("dest/source",
- [filename:join([?TMP_DIR,"dest","source",F]) ||
- F <- ["file1","file2"]])]}.
-
-cp_r_wildcard_file_to_dir_test_() ->
- {"cp_r copies wildcard files to directory",
- setup,
- fun() ->
- setup(),
- rebar_file_utils:cp_r([filename:join([?TMP_DIR,"source","*1"])],
- filename:join([?TMP_DIR,"dest"]))
- end,
- fun teardown/1,
- [?_assert(filelib:is_regular(filename:join([?TMP_DIR,"dest","file1"])))]}.
-
-cp_r_wildcard_dir_to_dir_test_() ->
- {"cp_r copies wildcard directory to directory",
- setup,
- fun() ->
- setup(),
- rebar_file_utils:cp_r([filename:join([?TMP_DIR,"sour*"])],
- filename:join([?TMP_DIR,"dest"]))
- end,
- fun teardown/1,
- [?_assert(filelib:is_dir(filename:join([?TMP_DIR,"dest","source"]))),
- assert_files_in("dest/source",
- [filename:join([?TMP_DIR,"dest","source",F]) ||
- F <- ["file1","file2"]])]}.
-
-cp_r_overwrite_file_test_() ->
- {"cp_r overwrites destination file",
- setup,
- fun() ->
- setup(),
- ok = file:write_file(filename:join([?TMP_DIR,"dest","file1"]),
- <<"test">>),
- rebar_file_utils:cp_r([filename:join([?TMP_DIR,"source","file1"])],
- filename:join([?TMP_DIR,"dest"]))
- end,
- fun teardown/1,
- [?_assertMatch({ok,?FILE_CONTENT},
- file:read_file(
- filename:join([?TMP_DIR,"dest","file1"])))]}.
-
-cp_r_overwrite_dir_test_() ->
- {"cp_r overwrites destination file (xcopy case on win32)",
- setup,
- fun() ->
- setup(),
- ok = file:make_dir(filename:join([?TMP_DIR,"dest","source"])),
- ok = file:write_file(
- filename:join([?TMP_DIR,"dest","source","file1"]),
- <<"test">>),
- rebar_file_utils:cp_r([filename:join([?TMP_DIR,"source"])],
- filename:join([?TMP_DIR,"dest"]))
- end,
- fun teardown/1,
- [?_assertMatch({ok,?FILE_CONTENT},
- file:read_file(
- filename:join([?TMP_DIR,"dest","source","file1"])))]}.
-
-cp_r_overwrite_file_fail_test_() ->
- {"cp_r fails to fs permission errors (file:copy/2 case on win32)",
- setup,
- fun() ->
- setup(),
- ok = file:write_file(
- filename:join([?TMP_DIR,"dest","file1"]),<<"test">>),
- ok = file:change_mode(
- filename:join([?TMP_DIR,"dest","file1"]),0)
- end,
- fun teardown/1,
- [?_assertError({badmatch,_},
- rebar_file_utils:cp_r(
- [filename:join([?TMP_DIR,"source","file1"])],
- filename:join([?TMP_DIR,"dest"])))]}.
-
-cp_r_overwrite_dir_fail_test_() ->
- {"cp_r fails to fs permission error (xcopy case on win32)",
- setup,
- fun() ->
- setup(),
- ok = file:make_dir(
- filename:join([?TMP_DIR,"dest","source"])),
- ok = file:write_file(
- filename:join([?TMP_DIR,"dest","source","file1"]),
- <<"test">>),
- ok = file:change_mode(
- filename:join([?TMP_DIR,"dest","source","file1"]),0)
- end,
- fun teardown/1,
- [?_assertError({badmatch,_},
- rebar_file_utils:cp_r(
- [filename:join([?TMP_DIR,"source"])],
- filename:join([?TMP_DIR,"dest"])))]}.
-
-mv_file_test_() ->
- {"move a file to folder",
- setup,
- fun() ->
- setup(),
- rebar_file_utils:mv(filename:join([?TMP_DIR,"source","file1"]),
- filename:join([?TMP_DIR,"dest"]))
- end,
- fun teardown/1,
- [?_assert(filelib:is_regular(filename:join([?TMP_DIR,"dest","file1"]))),
- ?_assertNot(filelib:is_regular(
- filename:join([?TMP_DIR,"source","file1"])))]}.
-
-%% ====================================================================
-%% Utilities
-%% ====================================================================
-
-file_list() ->
- [filename:join([?TMP_DIR,"source",F]) || F <- ["file1","file2"]].
-
-%% ====================================================================
-%% Setup and Teardown
-%% ====================================================================
-
-setup() ->
- file:make_dir(?TMP_DIR),
- make_dir_tree(?TMP_DIR,?DIR_TREE).
-
-make_dir_tree(Parent, [{d,Dir,Contents} | Rest]) ->
- NewDir = filename:join(Parent,Dir),
- ok = file:make_dir(NewDir),
- ok = make_dir_tree(NewDir,Contents),
- ok = make_dir_tree(Parent,Rest);
-make_dir_tree(Parent, [{f,File} | Rest]) ->
- ok = file:write_file(filename:join(Parent,File),?FILE_CONTENT),
- ok = make_dir_tree(Parent,Rest);
-make_dir_tree(_,[]) ->
- ok.
-
-teardown(_) ->
- case os:type() of
- {unix, _} ->
- os:cmd("rm -rf " ++ ?TMP_DIR ++ " 2>/dev/null");
- {win32, _} ->
- os:cmd("rmdir /S /Q " ++ filename:nativename(?TMP_DIR))
- end.
-
-%% ====================================================================
-%% Assert helpers
-%% ====================================================================
-
-assert_files_in(Name, [File|T]) ->
- [{Name ++ " has file: " ++ File, ?_assert(filelib:is_regular(File))} |
- assert_files_in(Name, T)];
-assert_files_in(_, []) -> [].
-
-assert_files_not_in(Name, [File|T]) ->
- [{Name ++ " does not have file: " ++ File,
- ?_assertNot(filelib:is_regular(File))} |
- assert_files_not_in(Name, T)];
-assert_files_not_in(_, []) -> [].
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f84eb4fc/src/rebar/test/rebar_xref_eunit.erl
----------------------------------------------------------------------
diff --git a/src/rebar/test/rebar_xref_eunit.erl b/src/rebar/test/rebar_xref_eunit.erl
deleted file mode 100644
index 45ec283..0000000
--- a/src/rebar/test/rebar_xref_eunit.erl
+++ /dev/null
@@ -1,203 +0,0 @@
--module(rebar_xref_eunit).
-
--compile(export_all).
-
--include_lib("eunit/include/eunit.hrl").
-
--define(REBAR_SCRIPT, "../rebar").
-
--define(TMP_DIR, "tmp_xref_eunit/").
-
-xref_test_() ->
- {"Test the various xref warnings",
- setup, fun() -> setup_project(false), rebar("compile"), rebar("skip_deps=true xref") end,
- fun teardown/1,
- fun(RebarOut) ->
- [
- {"Undefined function", ?_assert(string:str(RebarOut,
- "myapp_somemod:notavailable/1 is undefined function") =/= 0)},
- {"Undefined function call", ?_assert(string:str(RebarOut,
- "myapp_othermod:somefunc/0 calls undefined function myapp_somemod:notavailable/1") =/= 0)},
- {"Deprecated function", ?_assert(string:str(RebarOut,
- "myapp_mymod:fdeprecated/0 is deprecated function") =/= 0)},
- {"Deprecated function call", ?_assert(string:str(RebarOut,
- "myapp_othermod:somefunc/0 calls deprecated function myapp_mymod:fdeprecated/0") =/= 0)},
- {"Unused local", ?_assert(string:str(RebarOut,
- "myapp_mymod:localfunc2/0 is unused local function") =/= 0)},
- {"Unused export 1", ?_assert(string:str(RebarOut,
- "myapp_behaviour1:behaviour_info/1 is unused export") =/= 0)},
- {"Unused export 2", ?_assert(string:str(RebarOut,
- "myapp_behaviour2:behaviour_info/1 is unused export") =/= 0)},
- {"Unused export 3", ?_assert(string:str(RebarOut,
- "myapp_mymod:other2/1 is unused export") =/= 0)},
- {"Unused export 4", ?_assert(string:str(RebarOut,
- "myapp_othermod:somefunc/0 is unused export") =/= 0)},
- {"Suppressed behaviour export 1", ?_assert(string:str(RebarOut,
- "myapp_mymod:bh1_a/1 is unused export") =:= 0)},
- {"Suppressed behaviour export 2", ?_assert(string:str(RebarOut,
- "myapp_mymod:bh1_b/1 is unused export") =:= 0)},
- {"Suppressed behaviour export 3", ?_assert(string:str(RebarOut,
- "myapp_mymod:bh2_a/1 is unused export") =:= 0)},
- {"Suppressed behaviour export 4", ?_assert(string:str(RebarOut,
- "myapp_mymod:bh2_b/1 is unused export") =:= 0)}
- ]
- end}.
-
-xref_ignore_test_() ->
- {"Test the suppression of xref warnings",
- setup, fun() -> setup_project(ignore_xref), rebar("compile"), rebar("skip_deps=true xref") end,
- fun teardown/1,
- fun(RebarOut) ->
- [
- {"Undefined function can not be suppressed.", ?_assert(string:str(RebarOut,
- "myapp_somemod:notavailable/1 is undefined function") =/= 0)},
- {"Supppressed undefined function call", ?_assert(string:str(RebarOut,
- "myapp_othermod:somefunc/0 calls undefined function myapp_somemod:notavailable/1") =:= 0)},
- {"Supppressed deprecated function", ?_assert(string:str(RebarOut,
- "myapp_mymod:fdeprecated/0 is deprecated function") =:= 0)},
- {"Supppressed deprecated function call", ?_assert(string:str(RebarOut,
- "myapp_othermod:somefunc/0 calls deprecated function myapp_mymod:fdeprecated/0") =:= 0)},
- {"Supppressed unused local", ?_assert(string:str(RebarOut,
- "myapp_mymod:localfunc2/0 is unused local function") =:= 0)},
- {"Supppressed unused export 1", ?_assert(string:str(RebarOut,
- "myapp_behaviour1:behaviour_info/1 is unused export") =:= 0)},
- {"Supppressed unused export 2", ?_assert(string:str(RebarOut,
- "myapp_behaviour2:behaviour_info/1 is unused export") =:= 0)},
- {"Supppressed unused export 3", ?_assert(string:str(RebarOut,
- "myapp_mymod:other2/1 is unused export") =:= 0)},
- {"Supppressed unused export 4", ?_assert(string:str(RebarOut,
- "myapp_othermod:somefunc/0 is unused export") =:= 0)},
- {"Suppressed behaviour export 1", ?_assert(string:str(RebarOut,
- "myapp_mymod:bh1_a/1 is unused export") =:= 0)},
- {"Suppressed behaviour export 2", ?_assert(string:str(RebarOut,
- "myapp_mymod:bh1_b/1 is unused export") =:= 0)},
- {"Suppressed behaviour export 3", ?_assert(string:str(RebarOut,
- "myapp_mymod:bh2_a/1 is unused export") =:= 0)},
- {"Suppressed behaviour export 4", ?_assert(string:str(RebarOut,
- "myapp_mymod:bh2_b/1 is unused export") =:= 0)}
- ]
-
- end}.
-
-
-%% ====================================================================
-%% Setup and Teardown
-%% ====================================================================
-
--define(myapp_behaviour1,
- ["-module(myapp_behaviour1).\n",
- "-export([behaviour_info/1]).\n"]).
--define(myapp_behaviour1_body,
- ["behaviour_info(callbacks) -> [{bh1_a,1},{bh1_b,1}];\n",
- "behaviour_info(_Other) -> undefined.\n"]).
--define(myapp_behaviour1_ignorexref,
- ["-ignore_xref({behaviour_info,1}).\n"]).
-
--define(myapp_behaviour2,
- ["-module(myapp_behaviour2).\n",
- "-export([behaviour_info/1]).\n"]).
--define(myapp_behaviour2_body,
- ["behaviour_info(callbacks) -> [{bh2_a,1},{bh2_b,1}];\n",
- "behaviour_info(_Other) -> undefined.\n"]).
--define(myapp_behaviour2_ignorexref,
- ["-ignore_xref({behaviour_info,1}).\n"]).
-
--define(myapp_mymod,
- ["-module(myapp_mymod).\n",
- "-export([bh1_a/1,bh1_b/1,bh2_a/1,bh2_b/1,other1/1,other2/1,fdeprecated/0]).\n",
- "-behaviour(myapp_behaviour1).\n", % 2 behaviours
- "-behaviour(myapp_behaviour2).\n",
- "-deprecated({fdeprecated,0}).\n"]). % deprecated function
--define(myapp_mymod_body,
- ["bh1_a(A) -> localfunc1(bh1_a, A).\n", % behaviour functions
- "bh1_b(A) -> localfunc1(bh1_b, A).\n",
- "bh2_a(A) -> localfunc1(bh2_a, A).\n",
- "bh2_b(A) -> localfunc1(bh2_b, A).\n",
- "other1(A) -> localfunc1(other1, A).\n", % regular exported functions
- "other2(A) -> localfunc1(other2, A).\n",
- "localfunc1(A, B) -> {A, B}.\n", % used local
- "localfunc2() -> ok.\n", % unused local
- "fdeprecated() -> ok.\n" % deprecated function
- ]).
--define(myapp_mymod_ignorexref,
- ["-ignore_xref([{other2,1},{localfunc2,0},{fdeprecated,0}]).\n"]).
-
-
-
--define(myapp_othermod,
- ["-module(myapp_othermod).\n",
- "-export([somefunc/0]).\n"]).
--define(myapp_othermod_body,
- ["somefunc() ->\n",
- " myapp_mymod:other1(arg),\n",
- " myapp_somemod:notavailable(arg),\n",
- " myapp_mymod:fdeprecated().\n"
- ]).
--define(myapp_othermod_ignorexref,
- ["-ignore_xref([{myapp_somemod,notavailable,1},{somefunc,0}]).\n",
- "-ignore_xref({myapp_mymod,fdeprecated,0}).\n"]).
-
-
--define(myapp_rebarconfig,
- ["{erl_opts, [debug_info]}.\n",
- "{xref_checks, [deprecated_function_calls,deprecated_functions,\n",
- " undefined_function_calls,undefined_functions,\n",
- " exports_not_used,locals_not_used]}.\n"
- ]).
-
-setup_environment() ->
- ok = file:make_dir(?TMP_DIR),
- prepare_rebar_script(),
- ok = file:set_cwd(?TMP_DIR).
-
-prepare_project() ->
- setup_environment(),
- rebar("create-app appid=myapp"),
- ok = file:make_dir("ebin").
-
-setup_project(ignore_xref) ->
- prepare_project(),
- ok = file:write_file("src/myapp_behaviour1.erl", ?myapp_behaviour1 ++ ?myapp_behaviour1_ignorexref ++ ?myapp_behaviour1_body),
- ok = file:write_file("src/myapp_behaviour2.erl", ?myapp_behaviour2 ++ ?myapp_behaviour2_ignorexref++ ?myapp_behaviour2_body),
- ok = file:write_file("src/myapp_mymod.erl", ?myapp_mymod ++ ?myapp_mymod_ignorexref ++ ?myapp_mymod_body),
- ok = file:write_file("src/myapp_othermod.erl", ?myapp_othermod ++ ?myapp_othermod_ignorexref ++ ?myapp_othermod_body),
- ok = file:write_file("rebar.config", ?myapp_rebarconfig);
-
-setup_project(_) ->
- prepare_project(),
- ok = file:write_file("src/myapp_behaviour1.erl", ?myapp_behaviour1 ++ ?myapp_behaviour1_body),
- ok = file:write_file("src/myapp_behaviour2.erl", ?myapp_behaviour2 ++ ?myapp_behaviour2_body),
- ok = file:write_file("src/myapp_mymod.erl", ?myapp_mymod ++ ?myapp_mymod_body),
- ok = file:write_file("src/myapp_othermod.erl", ?myapp_othermod ++ ?myapp_othermod_body),
- ok = file:write_file("rebar.config", ?myapp_rebarconfig).
-
-
-teardown(_) ->
- ok = file:set_cwd(".."),
- ok = remove_tmp_dir().
-
-remove_tmp_dir() ->
- ok = rebar_file_utils:rm_rf(?TMP_DIR).
-
-%% ====================================================================
-%% Helper Functions
-%% ====================================================================
-
-prepare_rebar_script() ->
- Rebar = ?TMP_DIR ++ "rebar",
- {ok, _} = file:copy(?REBAR_SCRIPT, Rebar),
- case os:type() of
- {unix, _} ->
- [] = os:cmd("chmod u+x " ++ Rebar);
- {win32, _} ->
- {ok, _} = file:copy(?REBAR_SCRIPT ++ ".bat",
- ?TMP_DIR ++ "rebar.bat")
- end.
-
-rebar() ->
- rebar([]).
-
-rebar(Args) when is_list(Args) ->
- Out = os:cmd(filename:nativename("./rebar") ++ " " ++ Args),
- %% ?debugMsg("**** Begin"), ?debugMsg(Out), ?debugMsg("**** End"),
- Out.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f84eb4fc/src/rebar/test/upgrade_project/README.md
----------------------------------------------------------------------
diff --git a/src/rebar/test/upgrade_project/README.md b/src/rebar/test/upgrade_project/README.md
deleted file mode 100644
index 8df5383..0000000
--- a/src/rebar/test/upgrade_project/README.md
+++ /dev/null
@@ -1,40 +0,0 @@
-#### Building version 0.1
- rebar compile
- rebar generate
- mv rel/dummy rel/dummy_0.1
- rebar clean
- # start the release:
- cd rel/dummy_0.1
- bin/dummy console
-
- erl> dummy_server:get_state().
- erl> dummy_server:set_state(123).
- erl> dummy_server:get_state().
-
-#### Building version 0.2
-
- # Now, in another terminal we prepare an upgrade..
-
- # change release version numbers from 0.1 to 0.2 in
- $EDITOR apps/dummy/src/dummy.app.src
- $EDITOR rel/reltool.config
-
- rebar compile
- rebar generate
- # previous_release path is relative to your rel directory
- rebar generate-appups previous_release=dummy_0.1
- rebar generate-upgrade previous_release=dummy_0.1
- tar -zvtf rel/dummy_0.2.tar.gz
-
-
-#### Deploying with release_handler
- mv rel/dummy_0.2.tar.gz rel/dummy_0.1/releases/
-
- # Now use release_handler in the running erlang console for the deploy:
-
- erl> release_handler:unpack_release("dummy_0.2").
- erl> release_handler:install_release("0.2").
- erl> release_handler:make_permanent("0.2").
-
- erl> release_handler:which_releases().
- erl> dummy_server:get_state().
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f84eb4fc/src/rebar/test/upgrade_project/apps/dummy/src/dummy.app.src
----------------------------------------------------------------------
diff --git a/src/rebar/test/upgrade_project/apps/dummy/src/dummy.app.src b/src/rebar/test/upgrade_project/apps/dummy/src/dummy.app.src
deleted file mode 100644
index dd06752..0000000
--- a/src/rebar/test/upgrade_project/apps/dummy/src/dummy.app.src
+++ /dev/null
@@ -1,9 +0,0 @@
-{application, dummy, [
- {description, "a dummy app"},
- {vsn, "0.1"},
- {registered, [
- dummy_app
- ]},
- {mod, {dummy_app, []}},
- {applications, [kernel, stdlib, sasl]}
-]}.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f84eb4fc/src/rebar/test/upgrade_project/apps/dummy/src/dummy_app.erl
----------------------------------------------------------------------
diff --git a/src/rebar/test/upgrade_project/apps/dummy/src/dummy_app.erl b/src/rebar/test/upgrade_project/apps/dummy/src/dummy_app.erl
deleted file mode 100644
index 51363b3..0000000
--- a/src/rebar/test/upgrade_project/apps/dummy/src/dummy_app.erl
+++ /dev/null
@@ -1,9 +0,0 @@
--module(dummy_app).
--behaviour(application).
-
--export([start/2, stop/1]).
-
-start(_,_) ->
- dummy_sup:start_link().
-
-stop(_) -> ok.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f84eb4fc/src/rebar/test/upgrade_project/apps/dummy/src/dummy_server.erl
----------------------------------------------------------------------
diff --git a/src/rebar/test/upgrade_project/apps/dummy/src/dummy_server.erl b/src/rebar/test/upgrade_project/apps/dummy/src/dummy_server.erl
deleted file mode 100644
index 382251e..0000000
--- a/src/rebar/test/upgrade_project/apps/dummy/src/dummy_server.erl
+++ /dev/null
@@ -1,56 +0,0 @@
--module(dummy_server).
--behaviour(gen_server).
-
--export([start_link/0, set_state/1, get_state/0]).
-
--export([init/1,
- handle_call/3,
- handle_cast/2,
- handle_info/2,
- terminate/2,
- code_change/3]).
-
-%%
-
-start_link() ->
- gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
-
-set_state(What) ->
- gen_server:call(?MODULE, {set_state, What}).
-
-get_state() ->
- gen_server:call(?MODULE, get_state).
-
-
-%%
-
-init([]) ->
- say("init, setting state to 0", []),
- {ok, 0}.
-
-
-handle_call({set_state, NewState}, _From, _State) ->
- {reply, {ok, NewState}, NewState};
-
-handle_call(get_state, _From, State) ->
- {reply, State, State}.
-
-handle_cast('__not_implemented', State) ->
- {noreply, State}.
-
-handle_info(_Info, State) ->
- say("info ~p, ~p.", [_Info, State]),
- {noreply, State}.
-
-terminate(_Reason, _State) ->
- say("terminate ~p, ~p", [_Reason, _State]),
- ok.
-
-code_change(_OldVsn, State, _Extra) ->
- say("code_change ~p, ~p, ~p", [_OldVsn, State, _Extra]),
- {ok, State}.
-
-%% Internal
-
-say(Format, Data) ->
- io:format("~p:~p: ~s~n", [?MODULE, self(), io_lib:format(Format, Data)]).
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f84eb4fc/src/rebar/test/upgrade_project/apps/dummy/src/dummy_sup.erl
----------------------------------------------------------------------
diff --git a/src/rebar/test/upgrade_project/apps/dummy/src/dummy_sup.erl b/src/rebar/test/upgrade_project/apps/dummy/src/dummy_sup.erl
deleted file mode 100644
index b5617c7..0000000
--- a/src/rebar/test/upgrade_project/apps/dummy/src/dummy_sup.erl
+++ /dev/null
@@ -1,15 +0,0 @@
--module(dummy_sup).
--behaviour(supervisor).
-
--export([start_link/0]).
--export([init/1]).
-
-start_link() ->
- supervisor:start_link({local, ?MODULE}, ?MODULE, []).
-
-init([]) ->
- Dummy = {dummy_server,
- {dummy_server, start_link, []},
- permanent, 5000, worker, [dummy_server]},
-
- {ok, {{one_for_one, 10, 10}, [Dummy]}}.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f84eb4fc/src/rebar/test/upgrade_project/rebar.config
----------------------------------------------------------------------
diff --git a/src/rebar/test/upgrade_project/rebar.config b/src/rebar/test/upgrade_project/rebar.config
deleted file mode 100644
index 11b5b9a..0000000
--- a/src/rebar/test/upgrade_project/rebar.config
+++ /dev/null
@@ -1,4 +0,0 @@
-{sub_dirs, [
- "apps/dummy",
- "rel"
-]}.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f84eb4fc/src/rebar/test/upgrade_project/rel/files/dummy
----------------------------------------------------------------------
diff --git a/src/rebar/test/upgrade_project/rel/files/dummy b/src/rebar/test/upgrade_project/rel/files/dummy
deleted file mode 100755
index c2ef258..0000000
--- a/src/rebar/test/upgrade_project/rel/files/dummy
+++ /dev/null
@@ -1,347 +0,0 @@
-#!/bin/sh
-# -*- tab-width:4;indent-tabs-mode:nil -*-
-# ex: ts=4 sw=4 et
-
-# /bin/sh on Solaris is not a POSIX compatible shell, but /usr/bin/ksh is.
-if [ `uname -s` = 'SunOS' -a "${POSIX_SHELL}" != "true" ]; then
- POSIX_SHELL="true"
- export POSIX_SHELL
- # To support 'whoami' add /usr/ucb to path
- PATH=/usr/ucb:$PATH
- export PATH
- exec /usr/bin/ksh $0 "$@"
-fi
-
-# clear it so if we invoke other scripts, they run as ksh
-unset POSIX_SHELL
-
-RUNNER_SCRIPT_DIR=$(cd ${0%/*} && pwd -P)
-
-CALLER_DIR=$PWD
-
-RUNNER_BASE_DIR=${RUNNER_SCRIPT_DIR%/*}
-RUNNER_ETC_DIR=$RUNNER_BASE_DIR/etc
-# Note the trailing slash on $PIPE_DIR/
-PIPE_DIR=/tmp/$RUNNER_BASE_DIR/
-RUNNER_USER=
-WHOAMI=$(whoami)
-
-# Make sure this script is running as the appropriate user
-if ([ "$RUNNER_USER" ] && [ "x$WHOAMI" != "x$RUNNER_USER" ]); then
- type sudo > /dev/null 2>&1
- if [ $? -ne 0 ]; then
- echo "sudo doesn't appear to be installed and your EUID isn't $RUNNER_USER" 1>&2
- exit 1
- fi
- echo "Attempting to restart script through sudo -H -u $RUNNER_USER" >&2
- exec sudo -H -u $RUNNER_USER -i $RUNNER_SCRIPT_DIR/$RUNNER_SCRIPT $@
-fi
-
-# Identify the script name
-SCRIPT=`basename $0`
-
-# Parse out release and erts info
-START_ERL=`cat $RUNNER_BASE_DIR/releases/start_erl.data`
-ERTS_VSN=${START_ERL% *}
-APP_VSN=${START_ERL#* }
-
-# Use $CWD/vm.args if exists, otherwise releases/APP_VSN/vm.args, or
-# else etc/vm.args
-if [ -e "$CALLER_DIR/vm.args" ]; then
- VMARGS_PATH=$CALLER_DIR/vm.args
- USE_DIR=$CALLER_DIR
-else
- USE_DIR=$RUNNER_BASE_DIR
- if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args" ]; then
- VMARGS_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args"
- else
- VMARGS_PATH="$RUNNER_ETC_DIR/vm.args"
- fi
-fi
-
-RUNNER_LOG_DIR=$USE_DIR/log
-# Make sure log directory exists
-mkdir -p $RUNNER_LOG_DIR
-
-# Use releases/VSN/sys.config if it exists otherwise use etc/app.config
-if [ -e "$USE_DIR/sys.config" ]; then
- CONFIG_PATH="$USE_DIR/sys.config"
-else
- if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config" ]; then
- CONFIG_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config"
- else
- CONFIG_PATH="$RUNNER_ETC_DIR/app.config"
- fi
-fi
-
-# Extract the target node name from node.args
-NAME_ARG=`egrep '^\-s?name' $VMARGS_PATH`
-if [ -z "$NAME_ARG" ]; then
- echo "vm.args needs to have either -name or -sname parameter."
- exit 1
-fi
-
-# Extract the name type and name from the NAME_ARG for REMSH
-REMSH_TYPE=`echo $NAME_ARG | awk '{print $1}'`
-REMSH_NAME=`echo $NAME_ARG | awk '{print $2}'`
-
-# Note the `date +%s`, used to allow multiple remsh to the same node
-# transparently
-REMSH_NAME_ARG="$REMSH_TYPE remsh`date +%s`@`echo $REMSH_NAME | awk -F@ '{print $2}'`"
-REMSH_REMSH_ARG="-remsh $REMSH_NAME"
-
-# Extract the target cookie
-COOKIE_ARG=`grep '^\-setcookie' $VMARGS_PATH`
-if [ -z "$COOKIE_ARG" ]; then
- echo "vm.args needs to have a -setcookie parameter."
- exit 1
-fi
-
-# Make sure CWD is set to the right dir
-cd $USE_DIR
-
-# Make sure log directory exists
-mkdir -p $USE_DIR/log
-
-# Add ERTS bin dir to our path
-ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
-
-# Setup command to control the node
-NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
-
-# Setup remote shell command to control node
-REMSH="$ERTS_PATH/erl $REMSH_NAME_ARG $REMSH_REMSH_ARG $COOKIE_ARG"
-
-# Common functions
-
-# Ping node without allowing nodetool to take stdin
-ping_node() {
- $NODETOOL ping < /dev/null
-}
-
-# Set the PID global variable, return 1 on error
-get_pid() {
- PID=`$NODETOOL getpid < /dev/null`
- ES=$?
- if [ "$ES" -ne 0 ]; then
- echo "Node is not running!"
- return 1
- fi
-
- # don't allow empty or init pid's
- if [ -z $PID ] || [ "$PID" -le 1 ]; then
- return 1
- fi
-
- return 0
-}
-
-# Check the first argument for instructions
-case "$1" in
- start|start_boot)
- # Make sure there is not already a node running
- RES=`ping_node`
- if [ "$RES" = "pong" ]; then
- echo "Node is already running!"
- exit 1
- fi
- case "$1" in
- start)
- shift
- START_OPTION="console"
- HEART_OPTION="start"
- ;;
- start_boot)
- shift
- START_OPTION="console_boot"
- HEART_OPTION="start_boot"
- ;;
- esac
- RUN_PARAM=$(printf "\'%s\' " "$@")
- HEART_COMMAND="$RUNNER_BASE_DIR/bin/$SCRIPT $HEART_OPTION $RUN_PARAM"
- export HEART_COMMAND
- mkdir -p $PIPE_DIR
- $ERTS_PATH/run_erl -daemon $PIPE_DIR $RUNNER_LOG_DIR "exec $RUNNER_BASE_DIR/bin/$SCRIPT $START_OPTION $RUN_PARAM" 2>&1
- ;;
-
- stop)
- # Wait for the node to completely stop...
- case `uname -s` in
- Darwin)
- # Make sure we explicitly set this because iTerm.app doesn't for
- # some reason.
- COMMAND_MODE=unix2003
- esac
-
- # Get the PID from nodetool
- get_pid
- GPR=$?
- if [ "$GPR" -ne 0 ] || [ -z $PID ]; then
- exit $GPR
- fi
-
- # Tell nodetool to initiate a stop
- $NODETOOL stop
- ES=$?
- if [ "$ES" -ne 0 ]; then
- exit $ES
- fi
-
- # Wait for the node to completely stop...
- while `kill -s 0 $PID 2>/dev/null`
- do
- sleep 1
- done
- ;;
-
- restart)
- ## Restart the VM without exiting the process
- $NODETOOL restart
- ES=$?
- if [ "$ES" -ne 0 ]; then
- exit $ES
- fi
- ;;
-
- reboot)
- ## Restart the VM completely (uses heart to restart it)
- $NODETOOL reboot
- ES=$?
- if [ "$ES" -ne 0 ]; then
- exit $ES
- fi
- ;;
-
- ping)
- ## See if the VM is alive
- ping_node
- ES=$?
- if [ "$ES" -ne 0 ]; then
- exit $ES
- fi
- ;;
-
- attach)
- # Make sure a node is running
- ping_node
- ES=$?
- if [ "$ES" -ne 0 ]; then
- echo "Node is not running!"
- exit $ES
- fi
-
- shift
- exec $ERTS_PATH/to_erl $PIPE_DIR
- ;;
-
- remote_console)
- # Make sure a node is running
- ping_node
- ES=$?
- if [ "$ES" -ne 0 ]; then
- echo "Node is not running!"
- exit $ES
- fi
-
- shift
- exec $REMSH
- ;;
-
- upgrade)
- if [ -z "$2" ]; then
- echo "Missing upgrade package argument"
- echo "Usage: $SCRIPT upgrade {package base name}"
- echo "NOTE {package base name} MUST NOT include the .tar.gz suffix"
- exit 1
- fi
-
- # Make sure a node IS running
- ping_node
- ES=$?
- if [ "$ES" -ne 0 ]; then
- echo "Node is not running!"
- exit $ES
- fi
-
- node_name=`echo $NAME_ARG | awk '{print $2}'`
- erlang_cookie=`echo $COOKIE_ARG | awk '{print $2}'`
-
- $ERTS_PATH/escript $RUNNER_BASE_DIR/bin/install_upgrade.escript $node_name $erlang_cookie $2
- ;;
-
- console|console_clean|console_boot)
- # .boot file typically just $SCRIPT (ie, the app name)
- # however, for debugging, sometimes start_clean.boot is useful.
- # For e.g. 'setup', one may even want to name another boot script.
- case "$1" in
- console) BOOTFILE=$SCRIPT ;;
- console_clean) BOOTFILE=start_clean ;;
- console_boot)
- shift
- BOOTFILE="$1"
- shift
- ;;
- esac
- # Setup beam-required vars
- ROOTDIR=$RUNNER_BASE_DIR
- BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
- EMU=beam
- PROGNAME=`echo $0 | sed 's/.*\\///'`
- CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -mode embedded -config $CONFIG_PATH -args_file $VMARGS_PATH"
- export EMU
- export ROOTDIR
- export BINDIR
- export PROGNAME
-
- # Dump environment info for logging purposes
- echo "Exec: $CMD" -- ${1+"$@"}
- echo "Root: $ROOTDIR"
-
- # Log the startup
- logger -t "$SCRIPT[$$]" "Starting up"
-
- # Start the VM
- exec $CMD -- ${1+"$@"}
- ;;
-
- foreground)
- # start up the release in the foreground for use by runit
- # or other supervision services
-
- BOOTFILE=$SCRIPT
- FOREGROUNDOPTIONS="-noinput +Bd"
-
- # Setup beam-required vars
- ROOTDIR=$RUNNER_BASE_DIR
- BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
- EMU=beam
- PROGNAME=`echo $0 | sed 's/.*\///'`
- CMD="$BINDIR/erlexec $FOREGROUNDOPTIONS -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -config $CONFIG_PATH -args_file $VMARGS_PATH"
- export EMU
- export ROOTDIR
- export BINDIR
- export PROGNAME
-
- # Dump environment info for logging purposes
- echo "Exec: $CMD" -- ${1+"$@"}
- echo "Root: $ROOTDIR"
-
- # Start the VM
- exec $CMD -- ${1+"$@"}
- ;;
- getpid)
- # Get the PID from nodetool
- get_pid
- ES=$?
- if [ "$ES" -ne 0 ] || [ -z $PID ]; then
- exit $ES
- fi
- echo $PID
- ;;
- *)
- echo "Usage: $SCRIPT {start|start_boot <file>|foreground|stop|restart|reboot|ping|console|getpid|console_clean|console_boot <file>|attach|remote_console|upgrade}"
- exit 1
- ;;
-esac
-
-exit 0
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f84eb4fc/src/rebar/test/upgrade_project/rel/files/erl
----------------------------------------------------------------------
diff --git a/src/rebar/test/upgrade_project/rel/files/erl b/src/rebar/test/upgrade_project/rel/files/erl
deleted file mode 100755
index f4c63af..0000000
--- a/src/rebar/test/upgrade_project/rel/files/erl
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/sh
-
-# /bin/sh on Solaris is not a POSIX compatible shell, but /usr/bin/ksh is.
-if [ `uname -s` = 'SunOS' -a "${POSIX_SHELL}" != "true" ]; then
- POSIX_SHELL="true"
- export POSIX_SHELL
- exec /usr/bin/ksh $0 "$@"
-fi
-
-# clear it so if we invoke other scripts, they run as ksh as well
-unset POSIX_SHELL
-
-## This script replaces the default "erl" in erts-VSN/bin. This is
-## necessary as escript depends on erl and in turn, erl depends on
-## having access to a bootscript (start.boot). Note that this script
-## is ONLY invoked as a side-effect of running escript -- the embedded
-## node bypasses erl and uses erlexec directly (as it should).
-##
-## Note that this script makes the assumption that there is a
-## start_clean.boot file available in $ROOTDIR/release/VSN.
-
-# Determine the abspath of where this script is executing from.
-ERTS_BIN_DIR=$(cd ${0%/*} && pwd -P)
-
-# Now determine the root directory -- this script runs from erts-VSN/bin,
-# so we simply need to strip off two dirs from the end of the ERTS_BIN_DIR
-# path.
-ROOTDIR=${ERTS_BIN_DIR%/*/*}
-
-# Parse out release and erts info
-START_ERL=`cat $ROOTDIR/releases/start_erl.data`
-ERTS_VSN=${START_ERL% *}
-APP_VSN=${START_ERL#* }
-
-BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
-EMU=beam
-PROGNAME=`echo $0 | sed 's/.*\\///'`
-CMD="$BINDIR/erlexec"
-export EMU
-export ROOTDIR
-export BINDIR
-export PROGNAME
-
-exec $CMD -boot $ROOTDIR/releases/$APP_VSN/start_clean ${1+"$@"}