diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/rebar_eunit_tests.erl | 474 | ||||
-rw-r--r-- | test/rebar_file_utils_tests.erl | 278 | ||||
-rw-r--r-- | test/rebar_otp_release_tests.erl | 47 | ||||
-rw-r--r-- | test/rebar_require_vsn_tests.erl | 23 | ||||
-rw-r--r-- | test/rebar_xref_eunit.erl | 203 | ||||
-rw-r--r-- | test/upgrade_project/README.md | 40 | ||||
-rw-r--r-- | test/upgrade_project/apps/dummy/src/dummy.app.src | 9 | ||||
-rw-r--r-- | test/upgrade_project/apps/dummy/src/dummy_app.erl | 9 | ||||
-rw-r--r-- | test/upgrade_project/apps/dummy/src/dummy_server.erl | 56 | ||||
-rw-r--r-- | test/upgrade_project/apps/dummy/src/dummy_sup.erl | 15 | ||||
-rw-r--r-- | test/upgrade_project/rebar.config | 4 | ||||
-rwxr-xr-x | test/upgrade_project/rel/files/dummy | 347 | ||||
-rwxr-xr-x | test/upgrade_project/rel/files/erl | 44 | ||||
-rw-r--r-- | test/upgrade_project/rel/files/nodetool | 182 | ||||
-rw-r--r-- | test/upgrade_project/rel/files/sys.config | 11 | ||||
-rw-r--r-- | test/upgrade_project/rel/files/vm.args | 19 | ||||
-rw-r--r-- | test/upgrade_project/rel/reltool.config | 27 |
17 files changed, 0 insertions, 1788 deletions
diff --git a/test/rebar_eunit_tests.erl b/test/rebar_eunit_tests.erl deleted file mode 100644 index bb64507..0000000 --- a/test/rebar_eunit_tests.erl +++ /dev/null @@ -1,474 +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 <cebernard@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}, - {"Ensure EUnit runs a specific test by qualified function name", - setup, - fun() -> - setup_project_with_multiple_modules(), - rebar("-v eunit tests=myapp_mymod:myprivate_test") - end, - fun teardown/1, - fun(RebarOut) -> - [{"Selected test is run", - [?_assert(string:str(RebarOut, - "myapp_mymod:myprivate_test/0") - =/= 0)]}, - - {"Only selected test is run", - [?_assert(string:str(RebarOut, - "Test passed.") =/= 0)]}] - end}, - {"Ensure EUnit runs a specific test by qualified function " - ++ "name and tests from other module", - setup, - fun() -> - setup_project_with_multiple_modules(), - rebar("-v eunit suites=myapp_mymod3 " - ++ "tests=myapp_mymod:myprivate_test") - end, - fun teardown/1, - fun(RebarOut) -> - [{"Selected test is run", - [?_assert(string:str(RebarOut, - "myapp_mymod:myprivate_test/0") =/= 0)]}, - - {"Tests from module are run", - [?_assert(string:str(RebarOut, - "myapp_mymod3:") =/= 0)]}, - - {"Only selected tests are run", - [?_assert(string:str(RebarOut, - "Failed: 1. Skipped: 0. Passed: 1") - =/= 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. diff --git a/test/rebar_file_utils_tests.erl b/test/rebar_file_utils_tests.erl deleted file mode 100644 index a191765..0000000 --- a/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 <juhani@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, - [?_assertThrow(rebar_abort, - 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, - [?_assertThrow(rebar_abort, - 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(_, []) -> []. diff --git a/test/rebar_otp_release_tests.erl b/test/rebar_otp_release_tests.erl deleted file mode 100644 index 3045136..0000000 --- a/test/rebar_otp_release_tests.erl +++ /dev/null @@ -1,47 +0,0 @@ -%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*- -%% ex: ts=4 sw=4 et -%% ------------------------------------------------------------------- -%% -%% rebar: Erlang Build Tools -%% -%% Copyright (c) 2014 Tuncer Ayaz -%% -%% 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_otp_release_tests). - --include_lib("eunit/include/eunit.hrl"). - -check_otp_release_test() -> - case rebar_utils:otp_release() of - %% <= R16 - [$R,N|_] when is_integer(N) -> - ?assert(true); - %% >= 17.x - [N|_]=Rel when is_integer(N) -> - %% Check that it has at least Major.Minor. - ?assert(length(string:tokens(Rel, ".")) > 1), - - %% If otp_patch_apply was used and the release version has - %% a "**" suffix, we drop that part in otp_release/0. - ?assertEqual(0, string:str(Rel, "*")), - - %% Check that "\n" is dropped in otp_release/0. - ?assertEqual(0, string:str(Rel, "\n")) - end. diff --git a/test/rebar_require_vsn_tests.erl b/test/rebar_require_vsn_tests.erl deleted file mode 100644 index 2d3a1ec..0000000 --- a/test/rebar_require_vsn_tests.erl +++ /dev/null @@ -1,23 +0,0 @@ --module(rebar_require_vsn_tests). - --compile(export_all). - --include_lib("eunit/include/eunit.hrl"). - -version_tuple_test_() -> - [%% typical cases - ?_assert(rebar_require_vsn:version_tuple("R15B", "eunit") =:= {15, 0}), - ?_assert(rebar_require_vsn:version_tuple("R15B01", "eunit") =:= {15, 1}), - ?_assert(rebar_require_vsn:version_tuple("R15B02", "eunit") =:= {15, 2}), - ?_assert(rebar_require_vsn:version_tuple("R15B03-1", "eunit") =:= {15, 3}), - ?_assert(rebar_require_vsn:version_tuple("R15B03", "eunit") =:= {15, 3}), - ?_assert(rebar_require_vsn:version_tuple("R16B", "eunit") =:= {16, 0}), - ?_assert(rebar_require_vsn:version_tuple("R16B01", "eunit") =:= {16, 1}), - ?_assert(rebar_require_vsn:version_tuple("R16B02", "eunit") =:= {16, 2}), - ?_assert(rebar_require_vsn:version_tuple("R16B03", "eunit") =:= {16, 3}), - ?_assert(rebar_require_vsn:version_tuple("R16B03-1", "eunit") =:= {16, 3}), - ?_assert(rebar_require_vsn:version_tuple("17", "eunit") =:= {17, 0}), - %% error cases - ?_assertException(throw, rebar_abort, rebar_require_vsn:version_tuple("", "eunit")), - ?_assertException(throw, rebar_abort, rebar_require_vsn:version_tuple("abc", "eunit")) - ]. diff --git a/test/rebar_xref_eunit.erl b/test/rebar_xref_eunit.erl deleted file mode 100644 index 45ec283..0000000 --- a/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. diff --git a/test/upgrade_project/README.md b/test/upgrade_project/README.md deleted file mode 100644 index 8df5383..0000000 --- a/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(). diff --git a/test/upgrade_project/apps/dummy/src/dummy.app.src b/test/upgrade_project/apps/dummy/src/dummy.app.src deleted file mode 100644 index dd06752..0000000 --- a/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]} -]}. diff --git a/test/upgrade_project/apps/dummy/src/dummy_app.erl b/test/upgrade_project/apps/dummy/src/dummy_app.erl deleted file mode 100644 index 51363b3..0000000 --- a/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. diff --git a/test/upgrade_project/apps/dummy/src/dummy_server.erl b/test/upgrade_project/apps/dummy/src/dummy_server.erl deleted file mode 100644 index 382251e..0000000 --- a/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)]). diff --git a/test/upgrade_project/apps/dummy/src/dummy_sup.erl b/test/upgrade_project/apps/dummy/src/dummy_sup.erl deleted file mode 100644 index b5617c7..0000000 --- a/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]}}. diff --git a/test/upgrade_project/rebar.config b/test/upgrade_project/rebar.config deleted file mode 100644 index 11b5b9a..0000000 --- a/test/upgrade_project/rebar.config +++ /dev/null @@ -1,4 +0,0 @@ -{sub_dirs, [ - "apps/dummy", - "rel" -]}. diff --git a/test/upgrade_project/rel/files/dummy b/test/upgrade_project/rel/files/dummy deleted file mode 100755 index c2ef258..0000000 --- a/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 diff --git a/test/upgrade_project/rel/files/erl b/test/upgrade_project/rel/files/erl deleted file mode 100755 index f4c63af..0000000 --- a/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+"$@"} diff --git a/test/upgrade_project/rel/files/nodetool b/test/upgrade_project/rel/files/nodetool deleted file mode 100644 index ce06c6a..0000000 --- a/test/upgrade_project/rel/files/nodetool +++ /dev/null @@ -1,182 +0,0 @@ -#!/usr/bin/env escript -%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- -%% ex: ft=erlang ts=4 sw=4 et -%% ------------------------------------------------------------------- -%% -%% nodetool: Helper Script for interacting with live nodes -%% -%% ------------------------------------------------------------------- -main(Args) -> - ok = start_epmd(), - %% Extract the args - {RestArgs, TargetNode} = process_args(Args, [], undefined), - - %% any commands that don't need a running node - case RestArgs of - ["chkconfig", File] -> - case file:consult(File) of - {ok, _} -> - io:format("ok\n"), - halt(0); - {error, {Line, Mod, Term}} -> - io:format(standard_error, ["Error on line ", - file:format_error({Line, Mod, Term}), "\n"], []), - halt(1); - {error, R} -> - io:format(standard_error, ["Error reading config file: ", - file:format_error(R), "\n"], []), - halt(1) - end; - _ -> - ok - end, - - %% See if the node is currently running -- if it's not, we'll bail - case {net_kernel:hidden_connect_node(TargetNode), - net_adm:ping(TargetNode)} of - {true, pong} -> - ok; - {false,pong} -> - io:format("Failed to connect to node ~p .\n", [TargetNode]), - halt(1); - {_, pang} -> - io:format("Node ~p not responding to pings.\n", [TargetNode]), - halt(1) - end, - - case RestArgs of - ["getpid"] -> - io:format("~p\n", - [list_to_integer(rpc:call(TargetNode, os, getpid, []))]); - ["ping"] -> - %% If we got this far, the node already responsed to a - %% ping, so just dump a "pong" - io:format("pong\n"); - ["stop"] -> - io:format("~p\n", [rpc:call(TargetNode, init, stop, [], 60000)]); - ["restart"] -> - io:format("~p\n", [rpc:call(TargetNode, init, restart, [], 60000)]); - ["reboot"] -> - io:format("~p\n", [rpc:call(TargetNode, init, reboot, [], 60000)]); - ["rpc", Module, Function | RpcArgs] -> - case rpc:call(TargetNode, - list_to_atom(Module), - list_to_atom(Function), - [RpcArgs], 60000) of - ok -> - ok; - {badrpc, Reason} -> - io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]), - halt(1); - _ -> - halt(1) - end; - ["rpc_infinity", Module, Function | RpcArgs] -> - case rpc:call(TargetNode, - list_to_atom(Module), - list_to_atom(Function), - [RpcArgs], infinity) of - ok -> - ok; - {badrpc, Reason} -> - io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]), - halt(1); - _ -> - halt(1) - end; - ["rpcterms", Module, Function, ArgsAsString] -> - case rpc:call(TargetNode, - list_to_atom(Module), - list_to_atom(Function), - consult(ArgsAsString), 60000) of - {badrpc, Reason} -> - io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]), - halt(1); - Other -> - io:format("~p\n", [Other]) - end; - Other -> - io:format("Other: ~p\n", [Other]), - io:format("Usage: nodetool {chkconfig|getpid|ping|stop|restart|reboot|rpc|rpc_infinity|rpcterms}\n") - end, - net_kernel:stop(). - -process_args([], Acc, TargetNode) -> - {lists:reverse(Acc), TargetNode}; -process_args(["-setcookie", Cookie | Rest], Acc, TargetNode) -> - erlang:set_cookie(node(), list_to_atom(Cookie)), - process_args(Rest, Acc, TargetNode); -process_args(["-name", TargetName | Rest], Acc, _) -> - ThisNode = append_node_suffix(TargetName, "_maint_"), - {ok, _} = net_kernel:start([ThisNode, longnames]), - process_args(Rest, Acc, nodename(TargetName)); -process_args(["-sname", TargetName | Rest], Acc, _) -> - ThisNode = append_node_suffix(TargetName, "_maint_"), - {ok, _} = net_kernel:start([ThisNode, shortnames]), - process_args(Rest, Acc, nodename(TargetName)); -process_args([Arg | Rest], Acc, Opts) -> - process_args(Rest, [Arg | Acc], Opts). - - -start_epmd() -> - [] = os:cmd(epmd_path() ++ " -daemon"), - ok. - -epmd_path() -> - ErtsBinDir = filename:dirname(escript:script_name()), - Name = "epmd", - case os:find_executable(Name, ErtsBinDir) of - false -> - case os:find_executable(Name) of - false -> - io:format("Could not find epmd.~n"), - halt(1); - GlobalEpmd -> - GlobalEpmd - end; - Epmd -> - Epmd - end. - - -nodename(Name) -> - case string:tokens(Name, "@") of - [_Node, _Host] -> - list_to_atom(Name); - [Node] -> - [_, Host] = string:tokens(atom_to_list(node()), "@"), - list_to_atom(lists:concat([Node, "@", Host])) - end. - -append_node_suffix(Name, Suffix) -> - case string:tokens(Name, "@") of - [Node, Host] -> - list_to_atom(lists:concat([Node, Suffix, os:getpid(), "@", Host])); - [Node] -> - list_to_atom(lists:concat([Node, Suffix, os:getpid()])) - end. - - -%% -%% Given a string or binary, parse it into a list of terms, ala file:consult/0 -%% -consult(Str) when is_list(Str) -> - consult([], Str, []); -consult(Bin) when is_binary(Bin)-> - consult([], binary_to_list(Bin), []). - -consult(Cont, Str, Acc) -> - case erl_scan:tokens(Cont, Str, 0) of - {done, Result, Remaining} -> - case Result of - {ok, Tokens, _} -> - {ok, Term} = erl_parse:parse_term(Tokens), - consult([], Remaining, [Term | Acc]); - {eof, _Other} -> - lists:reverse(Acc); - {error, Info, _} -> - {error, Info} - end; - {more, Cont1} -> - consult(Cont1, eof, Acc) - end. diff --git a/test/upgrade_project/rel/files/sys.config b/test/upgrade_project/rel/files/sys.config deleted file mode 100644 index 3b7f6bd..0000000 --- a/test/upgrade_project/rel/files/sys.config +++ /dev/null @@ -1,11 +0,0 @@ -[ - %% SASL config - {sasl, [ - {sasl_error_logger, {file, "log/sasl-error.log"}}, - {errlog_type, error}, - {error_logger_mf_dir, "log/sasl"}, % Log directory - {error_logger_mf_maxbytes, 10485760}, % 10 MB max file size - {error_logger_mf_maxfiles, 5} % 5 files max - ]} -]. - diff --git a/test/upgrade_project/rel/files/vm.args b/test/upgrade_project/rel/files/vm.args deleted file mode 100644 index a9aeb64..0000000 --- a/test/upgrade_project/rel/files/vm.args +++ /dev/null @@ -1,19 +0,0 @@ -## Name of the node --name dummy@127.0.0.1 - -## Cookie for distributed erlang --setcookie dummy - -## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive -## (Disabled by default..use with caution!) -##-heart - -## Enable kernel poll and a few async threads -##+K true -##+A 5 - -## Increase number of concurrent ports/sockets -##-env ERL_MAX_PORTS 4096 - -## Tweak GC to run more often -##-env ERL_FULLSWEEP_AFTER 10 diff --git a/test/upgrade_project/rel/reltool.config b/test/upgrade_project/rel/reltool.config deleted file mode 100644 index b691c77..0000000 --- a/test/upgrade_project/rel/reltool.config +++ /dev/null @@ -1,27 +0,0 @@ -{sys, [ - {lib_dirs, ["../apps"]}, - {rel, "dummy", "0.1", [ - kernel, - stdlib, - sasl, - dummy - ]}, - {rel, "start_clean", "", [kernel, stdlib]}, - {boot_rel, "dummy"}, - {profile, embedded}, - {excl_sys_filters, ["^bin/.*", "^erts.*/bin/(dialyzer|typer)"]}, - {excl_archive_filters, [".*"]}, - - {app, hipe, [{incl_cond, exclude}]}, - - {app, dummy, [{incl_cond, include}]} -]}. - -{overlay, [ - {mkdir, "log/sasl"}, - {copy, "files/erl", "{{erts_vsn}}/bin/erl"}, - {copy, "files/nodetool", "{{erts_vsn}}/bin/nodetool"}, - {copy, "files/dummy", "bin/dummy"}, - {copy, "files/sys.config", "releases/\{\{rel_vsn\}\}/sys.config"}, - {copy, "files/vm.args", "releases/\{\{rel_vsn\}\}/vm.args"} - ]}. |