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

Add windows to CI #361

Open
wants to merge 1 commit 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
Add windows to CI
  • Loading branch information
michalmuskala committed Aug 28, 2024
commit 2a4bfdc2054a28f29f960b3a238cd1f959e5671b
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/*_SUITE_data/* text eol=lf
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
- os: ubuntu-22.04
otp-version: 26
rebar3-version: 3.22
- os: windows-2022
otp-version: 26
rebar3-version: 3.22
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand Down
27 changes: 15 additions & 12 deletions test/assert_diagnostic.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,18 @@ assert_snapshot_match(Expected, Output) ->
ct:fail("unexpected: ~p~n", [Other])
end.

assert_binary_match(Expected, Formatted) ->
case Formatted of
Expected ->
ok;
Other ->
% Split by lines (preserving empty lines).
Expected2 = string:split(Expected, "\n", all),
Other2 = string:split(Other, "\n", all),
% We already know they are not equal,
% this macro gives a better diagnostic.
?assertListEqual(Expected2, Other2)
end.
assert_binary_match(Expected0, Formatted0) ->
Expected = unicode:characters_to_binary(string:replace(Expected0, "\r\n", "\n", all)),
Formatted = unicode:characters_to_binary(Formatted0),
?assertEqual(Expected, Formatted).
% case string:equal(Expected, Formatted) of
% true ->
% ok;
% false ->
% % Split by lines (preserving empty lines).
% Expected2 = string:split(Expected, "\n", all),
% Other = string:split(Formatted, "\n", all),
% % We already know they are not equal,
% % this macro gives a better diagnostic.
% ?assertListEqual(Expected2, Other)
% end.
5 changes: 2 additions & 3 deletions test/erlfmt_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1112,9 +1112,8 @@ snapshot_formatted(Module, Config) ->
snapshot_match(FormattedModule, Module, Config, Options) ->
% Format `Module` and check it matches `FormattedModule`.
DataDir = ?config(data_dir, Config),
{ok, FormattedBin} = file:read_file(filename:join([DataDir, FormattedModule])),
{ok, Formatted} = file:read_file(filename:join([DataDir, FormattedModule])),
{ok, OriginalBin} = file:read_file(filename:join([DataDir, Module])),
Formatted = unicode:characters_to_list(FormattedBin),
Original = unicode:characters_to_list(OriginalBin),
Output = erlfmt:format_string(Original, Options),
assert_diagnostic:assert_snapshot_match(Formatted, Output).
Expand All @@ -1127,7 +1126,7 @@ format_string_unicode(_) ->
Options = [],
Output = erlfmt:format_string(Original, Options),
% Already formatted: we just check encoding is still ok.
assert_diagnostic:assert_snapshot_match(Original, Output).
assert_diagnostic:assert_snapshot_match(unicode:characters_to_binary(Original), Output).

error_ignore_begin_ignore(_) ->
assert_error(
Expand Down
19 changes: 9 additions & 10 deletions test/erlfmt_cli_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ smoke_test_stdio_unicode(Config) ->
stdio_test("unicode.erl", "--require-pragma", Config).

smoke_test_stdio_insert_pragma_without(Config) when is_list(Config) ->
Formatted = os:cmd("echo '-module(nopragma).' | " ++ escript() ++ " - --insert-pragma"),
Formatted = os:cmd("echo \"-module(nopragma).\" | " ++ escript() ++ " - --insert-pragma"),
Expected =
"%%% % @format\n"
"\n"
Expand All @@ -142,21 +142,21 @@ smoke_test_stdio_insert_pragma_without(Config) when is_list(Config) ->

smoke_test_stdio_delete_pragma(Config) when is_list(Config) ->
Formatted = os:cmd(
"echo '%% @format\n\n-module(nopragma).' | " ++ escript() ++ " - --delete-pragma"
"echo \"%% @format\n\n-module(nopragma).\" | " ++ escript() ++ " - --delete-pragma"
),
Expected =
"-module(nopragma).\n",
?assertEqual(Expected, Formatted).

smoke_test_stdio_delete_pragma_without(Config) when is_list(Config) ->
Formatted = os:cmd("echo '-module(nopragma).' | " ++ escript() ++ " - --delete-pragma"),
Formatted = os:cmd("echo \"-module(nopragma).\" | " ++ escript() ++ " - --delete-pragma"),
Expected =
"-module(nopragma).\n",
?assertEqual(Expected, Formatted).

smoke_test_stdio_delete_pragma_with_copyright(Config) when is_list(Config) ->
Formatted = os:cmd(
"echo '%% @format\n%% copyright\n\n-module(nopragma).' | " ++ escript() ++
"echo \"%% @format\n%% copyright\n\n-module(nopragma).\" | " ++ escript() ++
" - --delete-pragma"
),
Expected =
Expand All @@ -167,7 +167,7 @@ smoke_test_stdio_delete_pragma_with_copyright(Config) when is_list(Config) ->

smoke_test_stdio_reinsert_pragma(Config) when is_list(Config) ->
Formatted = os:cmd(
"echo '%% @format\n%%% copyright\n\n-module(nopragma).' | " ++ escript() ++
"echo \"%% @format\n%%% copyright\n\n-module(nopragma).\" | " ++ escript() ++
" - --insert-pragma"
),
Expected =
Expand All @@ -180,7 +180,7 @@ smoke_test_stdio_reinsert_pragma(Config) when is_list(Config) ->
%% respect the number of percentages when replacing the pragma
smoke_test_stdio_reinsert_pragma_second(Config) when is_list(Config) ->
Formatted = os:cmd(
"echo '%% copyright\n%% @format\n\n-module(nopragma).' | " ++ escript() ++
"echo \"%% copyright\n%% @format\n\n-module(nopragma).\" | " ++ escript() ++
" - --insert-pragma"
),
Expected =
Expand All @@ -192,7 +192,7 @@ smoke_test_stdio_reinsert_pragma_second(Config) when is_list(Config) ->

smoke_test_stdio_reinsert_pragma_config(Config) when is_list(Config) ->
Formatted = os:cmd(
"echo '%% @format\n\n%%% actual comment\n{}.\n' | " ++ escript() ++
"echo \"%% @format\n\n%%% actual comment\n{}.\n\" | " ++ escript() ++
" - --insert-pragma"
),
Expected =
Expand Down Expand Up @@ -238,7 +238,7 @@ noformat_pragma_file(Config) when is_list(Config) ->

noformat_pragma(Config) when is_list(Config) ->
Formatted = os:cmd(
"echo '%% @noformat\n\n%%% actual comment\n{ }.' | " ++ escript() ++ " -"
"echo \"%% @noformat\n\n%%% actual comment\n{ }.\" | " ++ escript() ++ " -"
),
Expected =
"%% @noformat\n"
Expand Down Expand Up @@ -280,10 +280,9 @@ stdio_test(FileName, Options, Config) ->
DataDir = ?config(data_dir, Config),
Path = filename:join(DataDir, FileName),
Formatted = os:cmd("cat " ++ Path ++ " | " ++ escript() ++ " - " ++ Options),
% ?assertEqual(toto, Path),
{ok, Expected} = file:read_file(Path),
assert_diagnostic:assert_binary_match(Expected, unicode:characters_to_binary(Formatted)).

escript() ->
%% this relies on the _build structure rebar3 uses
filename:join(code:lib_dir(erlfmt), "../../bin/erlfmt").
"escript " ++ filename:join(code:lib_dir(erlfmt), "../../bin/erlfmt").
Loading