Skip to content

Commit

Permalink
Fixed Common Test on Windows, hopefully.
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectronicRU committed Jun 10, 2021
1 parent 2031b75 commit 8b48e63
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 36 deletions.
10 changes: 3 additions & 7 deletions test/erlfmt_formatter_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,9 @@ init() ->
init(Opts) ->
ok =
file:set_cwd(
filename:join(
code:priv_dir(rebar3_format), "../test_app")),
{ok, State1} =
rebar3_format:init(
rebar_state:new()),
{ok, State2} = rebar_prv_app_discovery:do(State1),
test_util:get_app_dir()),
{ok, State1} = test_util:init(),
Files = {files, ["src/minimal.erl"]},
Formatter = {formatter, erlfmt_formatter},
Out = {options, Opts},
rebar_state:set(State2, format, [Files, Formatter, Out]).
rebar_state:set(State1, format, [Files, Formatter, Out]).
24 changes: 12 additions & 12 deletions test/otp_formatter_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ all() ->
[test_app, error, modified_ast].

test_app(_Config) ->
ok = file:set_cwd("../../../../test_app"),
{ok, State1} = init(),
ok =
file:set_cwd(
test_util:get_app_dir()),
{ok, State1} = test_util:init(),
Files =
{files, ["src/*.app.src", "src/*.sh", "src/*.erl", "src/*/*.erl", "include/*.hrl"]},
Formatter = {formatter, otp_formatter},
Expand Down Expand Up @@ -42,17 +44,21 @@ test_app(_Config) ->
{ok, _} = rebar3_format_prv:do(State2).

error(_Config) ->
ok = file:set_cwd("../../../../test_app"),
{ok, State1} = init(),
ok =
file:set_cwd(
test_util:get_app_dir()),
{ok, State1} = test_util:init(),
Formatter = {formatter, otp_formatter},
State2 = rebar_state:set(State1, format, [Formatter]),
%% OTP formatter can't parse some of our files in test_app/src because of macros
{error, _} = verify(State2).

%% otp_formatter messes up with some files. We have a mechanism to catch that.
modified_ast(_Config) ->
ok = file:set_cwd("../../../../test_app"),
{ok, State1} = init(),
ok =
file:set_cwd(
test_util:get_app_dir()),
{ok, State1} = test_util:init(),
Files = {files, ["src/dodge_macros.erl"]},
Formatter = {formatter, otp_formatter},
State2 = rebar_state:set(State1, format, [Files, Formatter]),
Expand All @@ -66,9 +72,3 @@ verify(State) ->
format(State) ->
rebar3_format_prv:do(
rebar_state:command_parsed_args(State, {[{output, "formatted_as_otp"}], something})).

init() ->
{ok, State} =
rebar_prv_app_discovery:do(
rebar_state:new()),
rebar3_format:init(State).
15 changes: 8 additions & 7 deletions test/sr_formatter_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ output_dir(_Config) ->

% When there is an expected output, steamroller should run on the input file
steamroller:validator(fun(File, _) ->
<<"/tmp/src/brackets.erl">> = File,
case filename:split(File) of
[<<"tmp">>, <<"src">>, <<"brackets.erl">>] ->
ok;
[_, <<"tmp">>, <<"src">>, <<"brackets.erl">>] ->
ok
end,
file:write_file(File, <<>>),
ok
end),
Expand All @@ -75,12 +80,8 @@ init() ->
init(Options) ->
ok =
file:set_cwd(
filename:join(
code:priv_dir(rebar3_format), "../test_app")),
{ok, State0} =
rebar_prv_app_discovery:do(
rebar_state:new()),
{ok, State1} = rebar3_format:init(State0),
test_util:get_app_dir()),
{ok, State1} = test_util:init(),
Files = {files, ["src/brackets.erl"]},
Formatter = {formatter, sr_formatter},
Opts = {options, Options},
Expand Down
18 changes: 8 additions & 10 deletions test/test_app_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ all() ->
[test_app, no_good_files].

test_app(_Config) ->
ok = file:set_cwd("../../../../test_app"),
ok =
file:set_cwd(
test_util:get_app_dir()),
State2 = init_test_app(),
{error, _} = verify(State2),
{ok, _} = format(State2),
Expand All @@ -20,8 +22,10 @@ test_app(_Config) ->
ok = git_diff().

no_good_files(_Config) ->
ok = file:set_cwd("../../../../test_app"),
{ok, State1} = init(),
ok =
file:set_cwd(
test_util:get_app_dir()),
{ok, State1} = test_util:init(),
Files = {files, ["a.broken.file", "a.non.existent.file"]},
State2 = rebar_state:set(State1, format, [Files]),
%% Our parsers don't crash on unparseable or non-existent files
Expand All @@ -35,14 +39,8 @@ format(State) ->
rebar3_format_prv:do(
rebar_state:command_parsed_args(State, {[{output, "formatted"}], something})).

init() ->
{ok, State} =
rebar_prv_app_discovery:do(
rebar_state:new()),
rebar3_format:init(State).

init_test_app() ->
{ok, State1} = init(),
{ok, State1} = test_util:init(),
Files =
{files,
["*.config", "src/*.app.src", "src/*.sh", "src/*.erl", "src/*/*.erl", "include/*.hrl"]},
Expand Down
13 changes: 13 additions & 0 deletions test/test_util.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-module(test_util).

-export([init/0, get_app_dir/0]).

init() ->
{ok, State0} =
rebar_prv_app_discovery:do(
rebar_state:new()),
rebar3_format:init(State0).

get_app_dir() ->
filename:join(
filename:dirname(?FILE), "../test_app").

0 comments on commit 8b48e63

Please sign in to comment.