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

Introduce Windows CI, but fixed #268

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions .github/workflows/erlang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,24 @@ jobs:
run: rebar3 dialyzer || true # to generate the PLT :(
- name: Run tests
run: rebar3 test

test_windows:

runs-on: windows-latest

strategy:
matrix:
otp: [21.3]

steps:
- uses: actions/checkout@v2
- uses: gleam-lang/[email protected]
with:
otp-version: ${{matrix.otp}}
id: install_erlang
- name: Fetch rebar3
run: wget https://github.com/erlang/rebar3/releases/download/3.15.2/rebar3 -OutFile rebar3
shell: powershell
- name: Run tests
run: |
& "${{steps.install_erlang.outputs.erlpath}}\bin\escript.exe" rebar3 do ct,cover
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
22 changes: 11 additions & 11 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 All @@ -58,7 +56,9 @@ init_test_app() ->
rebar_state:set(State1, format, [Files, IgnoredFiles]).

git_diff() ->
case os:cmd("git --no-pager diff --no-index -- after formatted") of
case
os:cmd("git -c core.autocrlf=true -c core.safecrlf=false --no-pager diff --no-index --ignore-cr-at-eol -- after formatted")
of
"" ->
ok;
Diff ->
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).
Copy link
Collaborator

Choose a reason for hiding this comment

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

In NextRoll, we usually call modules like this one test_utils (plural).
Sorry about this… but… do you mind changing its name?


-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").