Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests in Windows; adjust absolute paths #2286

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/rebar_file_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ robocopy_mv_and_rename(Source, Dest, SrcDir, SrcName, DestDir, DestName) ->
end.

robocopy_file(SrcPath, DestPath, FileName) ->
Cmd = ?FMT("robocopy /move /e \"~ts\" \"~ts\" \"~ts\"",
Cmd = ?FMT("robocopy /move /e \"~ts\" \"~ts\" \"~ts\" 1> nul",
[rebar_utils:escape_double_quotes(SrcPath),
rebar_utils:escape_double_quotes(DestPath),
rebar_utils:escape_double_quotes(FileName)]),
Expand All @@ -338,7 +338,7 @@ robocopy_file(SrcPath, DestPath, FileName) ->
end.

robocopy_dir(Source, Dest) ->
Cmd = ?FMT("robocopy /move /e \"~ts\" \"~ts\"",
Cmd = ?FMT("robocopy /move /e \"~ts\" \"~ts\" 1> nul",
[rebar_utils:escape_double_quotes(Source),
rebar_utils:escape_double_quotes(Dest)]),
Res = rebar_utils:sh(Cmd,
Expand Down Expand Up @@ -466,9 +466,10 @@ absolute_path(Path) ->
{ok, Dir} = file:get_cwd(),
filename:join([Dir, Path]);
volumerelative ->
Volume = hd(filename:split(Path)),
[Letter, $: | _] = filename:nativename(filename:absname(Path)),
Volume = [Letter, $:],
{ok, Dir} = file:get_cwd(Volume),
filename:join([Dir, Path])
Volume ++ filename:join([Dir, Path])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Erlang has no way to include the volume in the path? Or is this just so it works on both otp-23 and older otps?

Copy link
Collaborator Author

@ferd ferd May 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can get it in absname, but filename:join drops it... so I have to add it after the fact.

end.

%% @doc normalizing a path removes all of the `..' and the
Expand Down
16 changes: 10 additions & 6 deletions test/rebar_compile_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2534,13 +2534,17 @@ split_project_apps_hooks(Config) ->
ok = filelib:ensure_dir(filename:join([AppDir2, "src", "dummy"])),
ok = filelib:ensure_dir(filename:join([AppDir2, "include", "dummy"])),
ok = filelib:ensure_dir(filename:join([HookDir, "dummy"])),
Cmd = case os:type() of
{win32, _} -> "dir /B";
_ -> "ls"
end,
Cfg = fun(Name) ->
[{pre_hooks, [{compile, "ls "++HookDir++" > "++filename:join(HookDir, "pre-compile-"++Name)},
{erlc_compile, "ls "++HookDir++" > "++filename:join(HookDir, "pre-erlc-"++Name)},
{app_compile, "ls "++HookDir++" > "++filename:join(HookDir, "pre-app-"++Name)}]},
{post_hooks, [{compile, "ls "++HookDir++" > "++filename:join(HookDir, "post-compile-"++Name)},
{erlc_compile, "ls "++HookDir++" > "++filename:join(HookDir, "post-erlc-"++Name)},
{app_compile, "ls "++HookDir++" > "++filename:join(HookDir, "post-app-"++Name)}]}
[{pre_hooks, [{compile, Cmd++" \""++HookDir++"\" > \""++filename:join(HookDir, "pre-compile-"++Name)++"\""},
{erlc_compile, Cmd++" \""++HookDir++"\" > \""++filename:join(HookDir, "pre-erlc-"++Name)++"\""},
{app_compile, Cmd++" \""++HookDir++"\" > \""++filename:join(HookDir, "pre-app-"++Name)++"\""}]},
{post_hooks, [{compile, Cmd++" \""++HookDir++"\" > \""++filename:join(HookDir, "post-compile-"++Name)++"\""},
{erlc_compile, Cmd++" \""++HookDir++"\" > \""++filename:join(HookDir, "post-erlc-"++Name)++"\""},
{app_compile, Cmd++" \""++HookDir++"\" > \""++filename:join(HookDir, "post-app-"++Name)++"\""}]}
]
end,
ok = file:write_file(filename:join(AppDir1, "rebar.config"),
Expand Down
16 changes: 10 additions & 6 deletions test/rebar_file_utils_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ canonical_path(_Config) ->

absolute_path(_Config) ->
%% We find the root so that the name works both on unix-likes and
%% with Windows.
%% with Windows. Starting on OTP-22, filename:join/1 drops the drive letter,
%% and split/1 and absname both normalize c:\\ to c:/ -- going onwards, we
%% start normalizing the same way as well to prevent issues.
Root = case os:type() of
{win32, _} -> filename:nativename(filename:absname("/")); % C:\, with proper drive
{win32, _} -> filename:absname(filename:nativename("/")); % C:\, with proper drive
_ -> "/"
end,
?assertEqual(filename:absname(Root), rebar_file_utils:absolute_path("/")),
Expand All @@ -165,18 +167,20 @@ absolute_path(_Config) ->

normalized_path(_Config) ->
%% We find the root so that the name works both on unix-likes and
%% with Windows.
%% with Windows. Starting on OTP-22, filename:join/1 drops the drive letter,
%% and split/1 and absname both normalize c:\\ to c:/ -- going onwards, we
%% start normalizing the same way as well to prevent issues.
Root = case os:type() of
{win32, _} -> filename:nativename(filename:absname("/")); % C:\, with proper drive
{win32, _} -> filename:absname(filename:nativename("/")); % c:/, with proper drive
_ -> "/"
end,
?assertEqual(filename:nativename(Root), rebar_file_utils:normalized_path("/")),
?assertEqual(Root, rebar_file_utils:normalized_path("/")),
?assertEqual("../..", rebar_file_utils:normalized_path("/../../..")),
?assertEqual(Root ++ "foo", rebar_file_utils:normalized_path("/foo/bar/..")),
?assertEqual(Root ++ "foo", rebar_file_utils:normalized_path("/foo/../foo")),
?assertEqual(Root ++ "foo", rebar_file_utils:normalized_path("/foo/.")),
?assertEqual(Root ++ "foo", rebar_file_utils:normalized_path("/foo/./.")),
?assertEqual(filename:nativename(Root ++ "foo/bar"),
?assertEqual(Root ++ "foo/bar",
rebar_file_utils:normalized_path("/foo/./bar")).

resolve_link(_Config) ->
Expand Down
6 changes: 5 additions & 1 deletion test/rebar_hooks_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ bare_compile_hooks_default_ns(Config) ->

HookFile = filename:join([?config(priv_dir, Config), "bare-post.hook"]),

Cmd = case os:type() of
{win32, _} -> "dir";
_ -> "ls"
end,
ConfOpts = [{provider_hooks, [{post, [{compile, clean}]}]},
{post_hooks, [{compile, "ls > " ++ HookFile}]}],
{post_hooks, [{compile, Cmd ++ " > " ++ HookFile}]}],
RConfFile = rebar_test_utils:create_config(AppDir, ConfOpts),
{ok, RConf} = file:consult(RConfFile),
rebar_test_utils:run_and_check(
Expand Down