Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge remote branch 'origin/peppe/common_test/otp-9964_9975_9595' int…

…o maint

* origin/peppe/common_test/otp-9964_9975_9595:
  Have ct_run clean up the code path after each test run
  Fix problems with ct_run's code path manipulation

OTP-9964
OTP-9975
OTP-9595
  • Loading branch information...
commit 805f55b9f08d29bfca4fdf0fe1509702a8451b5b 2 parents 027456f + 4db5923
Peter Andersson pekadan authored

Showing 1 changed file with 53 additions and 25 deletions. Show diff stats Hide diff stats

  1. +53 25 lib/common_test/src/ct_run.erl
78 lib/common_test/src/ct_run.erl
@@ -1746,25 +1746,31 @@ set_group_leader_same_as_shell() ->
1746 1746 false
1747 1747 end.
1748 1748
1749   -check_and_add([{TestDir0,M,_} | Tests], Added) ->
  1749 +check_and_add([{TestDir0,M,_} | Tests], Added, PA) ->
1750 1750 case locate_test_dir(TestDir0, M) of
1751 1751 {ok,TestDir} ->
1752 1752 case lists:member(TestDir, Added) of
1753 1753 true ->
1754   - check_and_add(Tests, Added);
  1754 + check_and_add(Tests, Added, PA);
1755 1755 false ->
1756   - true = code:add_patha(TestDir),
1757   - check_and_add(Tests, [TestDir|Added])
  1756 + case lists:member(rm_trailing_slash(TestDir),
  1757 + code:get_path()) of
  1758 + false ->
  1759 + true = code:add_patha(TestDir),
  1760 + check_and_add(Tests, [TestDir|Added], [TestDir|PA]);
  1761 + true ->
  1762 + check_and_add(Tests, [TestDir|Added], PA)
  1763 + end
1758 1764 end;
1759 1765 {error,_} ->
1760 1766 {error,{invalid_directory,TestDir0}}
1761 1767 end;
1762   -check_and_add([], _) ->
1763   - ok.
  1768 +check_and_add([], _, PA) ->
  1769 + {ok,PA}.
1764 1770
1765 1771 do_run_test(Tests, Skip, Opts) ->
1766   - case check_and_add(Tests, []) of
1767   - ok ->
  1772 + case check_and_add(Tests, [], []) of
  1773 + {ok,AddedToPath} ->
1768 1774 ct_util:set_testdata({stats,{0,0,{0,0}}}),
1769 1775 ct_util:set_testdata({cover,undefined}),
1770 1776 test_server_ctrl:start_link(local),
@@ -1858,7 +1864,9 @@ do_run_test(Tests, Skip, Opts) ->
1858 1864 end,
1859 1865 lists:foreach(fun(Suite) ->
1860 1866 maybe_cleanup_interpret(Suite, Opts#opts.step)
1861   - end, CleanUp);
  1867 + end, CleanUp),
  1868 + [code:del_path(Dir) || Dir <- AddedToPath],
  1869 + ok;
1862 1870 Error ->
1863 1871 Error
1864 1872 end.
@@ -2347,31 +2355,38 @@ event_handler_init_args2opts([]) ->
2347 2355 %% relative dirs "post run_test erl_args" is not kept!
2348 2356 rel_to_abs(CtArgs) ->
2349 2357 {PA,PZ} = get_pa_pz(CtArgs, [], []),
2350   - io:format(user, "~n", []),
2351 2358 [begin
2352   - code:del_path(filename:basename(D)),
2353   - Abs = filename:absname(D),
2354   - code:add_pathz(Abs),
2355   - if D /= Abs ->
  2359 + Dir = rm_trailing_slash(D),
  2360 + Abs = make_abs(Dir),
  2361 + if Dir /= Abs ->
  2362 + code:del_path(Dir),
  2363 + code:del_path(Abs),
2356 2364 io:format(user, "Converting ~p to ~p and re-inserting "
2357 2365 "with add_pathz/1~n",
2358   - [D, Abs]);
  2366 + [Dir, Abs]);
2359 2367 true ->
2360   - ok
2361   - end
  2368 + code:del_path(Dir)
  2369 + end,
  2370 + code:add_pathz(Abs)
2362 2371 end || D <- PZ],
2363 2372 [begin
2364   - code:del_path(filename:basename(D)),
2365   - Abs = filename:absname(D),
2366   - code:add_patha(Abs),
2367   - if D /= Abs ->
  2373 + Dir = rm_trailing_slash(D),
  2374 + Abs = make_abs(Dir),
  2375 + if Dir /= Abs ->
  2376 + code:del_path(Dir),
  2377 + code:del_path(Abs),
2368 2378 io:format(user, "Converting ~p to ~p and re-inserting "
2369 2379 "with add_patha/1~n",
2370   - [D, Abs]);
2371   - true ->ok
2372   - end
  2380 + [Dir, Abs]);
  2381 + true ->
  2382 + code:del_path(Dir)
  2383 + end,
  2384 + code:add_patha(Abs)
2373 2385 end || D <- PA],
2374   - io:format(user, "~n", []).
  2386 + io:format(user, "~n", []).
  2387 +
  2388 +rm_trailing_slash(Dir) ->
  2389 + filename:join(filename:split(Dir)).
2375 2390
2376 2391 get_pa_pz([{pa,Dirs} | Args], PA, PZ) ->
2377 2392 get_pa_pz(Args, PA ++ Dirs, PZ);
@@ -2382,6 +2397,19 @@ get_pa_pz([_ | Args], PA, PZ) ->
2382 2397 get_pa_pz([], PA, PZ) ->
2383 2398 {PA,PZ}.
2384 2399
  2400 +make_abs(RelDir) ->
  2401 + Tokens = filename:split(filename:absname(RelDir)),
  2402 + filename:join(lists:reverse(make_abs1(Tokens, []))).
  2403 +
  2404 +make_abs1([".."|Dirs], [_Dir|Path]) ->
  2405 + make_abs1(Dirs, Path);
  2406 +make_abs1(["."|Dirs], Path) ->
  2407 + make_abs1(Dirs, Path);
  2408 +make_abs1([Dir|Dirs], Path) ->
  2409 + make_abs1(Dirs, [Dir|Path]);
  2410 +make_abs1([], Path) ->
  2411 + Path.
  2412 +
2385 2413 %% This function translates ct:run_test/1 start options
2386 2414 %% to ct_run start arguments (on the init arguments format) -
2387 2415 %% this is useful mainly for testing the ct_run start functions.

0 comments on commit 805f55b

Please sign in to comment.
Something went wrong with that request. Please try again.