summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEvan Vigil-McClanahan <evan@getchef.com>2014-08-15 17:21:00 -0700
committerEvan Vigil-McClanahan <evan@getchef.com>2014-08-18 13:56:19 -0700
commitba466e2d38cc41850aa1f19bdf17d1ee293285af (patch)
tree814b466f7788ac18f936152f453a63eb04f994a1 /test
parente9f62c45807ce2db39e0606c4d97cd071416bd64 (diff)
downloadrebar-ba466e2d38cc41850aa1f19bdf17d1ee293285af.tar.gz
Manually clean up paths
Using code:set_path/1 with very large paths is very slow on larger projects. On my mid-sized project, it seems to take around .4s per call. Emulating the call with direct path removal (using code:del_path/1) seems to be quite a lot faster.
Diffstat (limited to 'test')
-rw-r--r--test/rebar_eunit_tests.erl56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/rebar_eunit_tests.erl b/test/rebar_eunit_tests.erl
index bb64507..33f168c 100644
--- a/test/rebar_eunit_tests.erl
+++ b/test/rebar_eunit_tests.erl
@@ -325,6 +325,62 @@ basic_setup_test_() ->
["test/myapp_mymod_tests.erl",
"src/myapp_mymod.erl"])}.
+code_path_test_() ->
+ [{"Ensuring that fast code path cleanup is correct for adds",
+ setup, fun make_tmp_dir/0,
+ fun(_) -> remove_tmp_dir() end,
+ fun() ->
+ OPath = code:get_path(),
+ PathZ = ?TMP_DIR ++ "some_path",
+ PathA = ?TMP_DIR ++ "some_other_path",
+ ok = file:make_dir(PathZ),
+ ok = file:make_dir(PathA),
+ true = code:add_pathz(PathZ),
+ true = code:add_patha(PathA),
+ %% make sure that they've been added
+ ?assertEqual([PathA] ++ OPath ++ [PathZ],
+ code:get_path()),
+ true = rebar_utils:cleanup_code_path(OPath),
+ ?assertEqual(OPath, code:get_path())
+ end},
+ {"Ensuring that fast code path cleanup is correct for removes",
+ setup, fun make_tmp_dir/0,
+ fun(_) -> remove_tmp_dir() end,
+ fun() ->
+ OPath = code:get_path(),
+ Path1 = lists:nth(10, OPath),
+ Path2 = lists:nth(11, OPath),
+ true = code:del_path(Path1),
+ true = code:del_path(Path2),
+ %% make sure that they've been added
+ ?assertEqual(OPath -- [Path1, Path2],
+ code:get_path()),
+ true = rebar_utils:cleanup_code_path(OPath),
+ ?assertEqual(OPath, code:get_path())
+ end},
+ {"Ensuring that fast code path cleanup is equivalent for adds",
+ setup, fun make_tmp_dir/0,
+ fun(_) -> remove_tmp_dir() end,
+ fun() ->
+ OPath = code:get_path(),
+ PathZ = ?TMP_DIR ++ "some_path",
+ PathA = ?TMP_DIR ++ "some_other_path",
+ ok = file:make_dir(PathZ),
+ ok = file:make_dir(PathA),
+ true = code:add_pathz(PathZ),
+ true = code:add_patha(PathA),
+ %% make sure that they've been added
+ ?assertEqual([PathA] ++ OPath ++ [PathZ],
+ code:get_path()),
+ true = rebar_utils:cleanup_code_path(OPath),
+ CleanedPath = code:get_path(),
+ true = code:add_pathz(PathZ),
+ true = code:add_patha(PathA),
+ true = code:set_path(OPath),
+ ?assertEqual(CleanedPath, code:get_path())
+ end}].
+
+
%% ====================================================================
%% Setup and Teardown
%% ====================================================================