Skip to content

Commit

Permalink
Add windows to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmuskala committed Aug 28, 2024
1 parent 767e5df commit cccc259
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/*_SUITE_data/*.formatted 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
2 changes: 1 addition & 1 deletion src/erlfmt_scan.erl
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ last_node_string(#state{original = [First | _] = Tokens}) ->
-spec last_node_string_trimmed(state()) -> {unicode:chardata(), anno()}.
last_node_string_trimmed(#state{original = [First | _] = Tokens}) ->
String0 = stringify_tokens(Tokens),
String = string:trim(String0, both, "\n"),
String = string:trim(String0, both, "\r\n"),
Location = erl_scan:location(First),
{String, token_anno([{text, String}, {location, Location}])}.

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

0 comments on commit cccc259

Please sign in to comment.