Skip to content

Commit 2a2fca9

Browse files
committed
Add windows to CI
1 parent 767e5df commit 2a2fca9

5 files changed

Lines changed: 29 additions & 24 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/*_SUITE_data/* text eol=lf

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030
- os: ubuntu-22.04
3131
otp-version: 26
3232
rebar3-version: 3.22
33+
- os: windows-2022
34+
otp-version: 26
35+
rebar3-version: 3.22
3336
runs-on: ${{ matrix.os }}
3437
steps:
3538
- name: Checkout

test/assert_diagnostic.erl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,18 @@ assert_snapshot_match(Expected, Output) ->
8181
ct:fail("unexpected: ~p~n", [Other])
8282
end.
8383

84-
assert_binary_match(Expected, Formatted) ->
85-
case Formatted of
86-
Expected ->
87-
ok;
88-
Other ->
89-
% Split by lines (preserving empty lines).
90-
Expected2 = string:split(Expected, "\n", all),
91-
Other2 = string:split(Other, "\n", all),
92-
% We already know they are not equal,
93-
% this macro gives a better diagnostic.
94-
?assertListEqual(Expected2, Other2)
95-
end.
84+
assert_binary_match(Expected0, Formatted0) ->
85+
Expected = unicode:characters_to_binary(string:replace(Expected0, "\r\n", "\n", all)),
86+
Formatted = unicode:characters_to_binary(Formatted0),
87+
?assertEqual(Expected, Formatted).
88+
% case string:equal(Expected, Formatted) of
89+
% true ->
90+
% ok;
91+
% false ->
92+
% % Split by lines (preserving empty lines).
93+
% Expected2 = string:split(Expected, "\n", all),
94+
% Other = string:split(Formatted, "\n", all),
95+
% % We already know they are not equal,
96+
% % this macro gives a better diagnostic.
97+
% ?assertListEqual(Expected2, Other)
98+
% end.

test/erlfmt_SUITE.erl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,9 +1112,8 @@ snapshot_formatted(Module, Config) ->
11121112
snapshot_match(FormattedModule, Module, Config, Options) ->
11131113
% Format `Module` and check it matches `FormattedModule`.
11141114
DataDir = ?config(data_dir, Config),
1115-
{ok, FormattedBin} = file:read_file(filename:join([DataDir, FormattedModule])),
1115+
{ok, Formatted} = file:read_file(filename:join([DataDir, FormattedModule])),
11161116
{ok, OriginalBin} = file:read_file(filename:join([DataDir, Module])),
1117-
Formatted = unicode:characters_to_list(FormattedBin),
11181117
Original = unicode:characters_to_list(OriginalBin),
11191118
Output = erlfmt:format_string(Original, Options),
11201119
assert_diagnostic:assert_snapshot_match(Formatted, Output).
@@ -1127,7 +1126,7 @@ format_string_unicode(_) ->
11271126
Options = [],
11281127
Output = erlfmt:format_string(Original, Options),
11291128
% Already formatted: we just check encoding is still ok.
1130-
assert_diagnostic:assert_snapshot_match(Original, Output).
1129+
assert_diagnostic:assert_snapshot_match(unicode:characters_to_binary(Original), Output).
11311130

11321131
error_ignore_begin_ignore(_) ->
11331132
assert_error(

test/erlfmt_cli_SUITE.erl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ smoke_test_stdio_unicode(Config) ->
133133
stdio_test("unicode.erl", "--require-pragma", Config).
134134

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

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

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

157157
smoke_test_stdio_delete_pragma_with_copyright(Config) when is_list(Config) ->
158158
Formatted = os:cmd(
159-
"echo '%% @format\n%% copyright\n\n-module(nopragma).' | " ++ escript() ++
159+
"echo \"%% @format\n%% copyright\n\n-module(nopragma).\" | " ++ escript() ++
160160
" - --delete-pragma"
161161
),
162162
Expected =
@@ -167,7 +167,7 @@ smoke_test_stdio_delete_pragma_with_copyright(Config) when is_list(Config) ->
167167

168168
smoke_test_stdio_reinsert_pragma(Config) when is_list(Config) ->
169169
Formatted = os:cmd(
170-
"echo '%% @format\n%%% copyright\n\n-module(nopragma).' | " ++ escript() ++
170+
"echo \"%% @format\n%%% copyright\n\n-module(nopragma).\" | " ++ escript() ++
171171
" - --insert-pragma"
172172
),
173173
Expected =
@@ -180,7 +180,7 @@ smoke_test_stdio_reinsert_pragma(Config) when is_list(Config) ->
180180
%% respect the number of percentages when replacing the pragma
181181
smoke_test_stdio_reinsert_pragma_second(Config) when is_list(Config) ->
182182
Formatted = os:cmd(
183-
"echo '%% copyright\n%% @format\n\n-module(nopragma).' | " ++ escript() ++
183+
"echo \"%% copyright\n%% @format\n\n-module(nopragma).\" | " ++ escript() ++
184184
" - --insert-pragma"
185185
),
186186
Expected =
@@ -192,7 +192,7 @@ smoke_test_stdio_reinsert_pragma_second(Config) when is_list(Config) ->
192192

193193
smoke_test_stdio_reinsert_pragma_config(Config) when is_list(Config) ->
194194
Formatted = os:cmd(
195-
"echo '%% @format\n\n%%% actual comment\n{}.\n' | " ++ escript() ++
195+
"echo \"%% @format\n\n%%% actual comment\n{}.\n\" | " ++ escript() ++
196196
" - --insert-pragma"
197197
),
198198
Expected =
@@ -238,7 +238,7 @@ noformat_pragma_file(Config) when is_list(Config) ->
238238

239239
noformat_pragma(Config) when is_list(Config) ->
240240
Formatted = os:cmd(
241-
"echo '%% @noformat\n\n%%% actual comment\n{ }.' | " ++ escript() ++ " -"
241+
"echo \"%% @noformat\n\n%%% actual comment\n{ }.\" | " ++ escript() ++ " -"
242242
),
243243
Expected =
244244
"%% @noformat\n"
@@ -280,7 +280,6 @@ stdio_test(FileName, Options, Config) ->
280280
DataDir = ?config(data_dir, Config),
281281
Path = filename:join(DataDir, FileName),
282282
Formatted = os:cmd("cat " ++ Path ++ " | " ++ escript() ++ " - " ++ Options),
283-
% ?assertEqual(toto, Path),
284283
{ok, Expected} = file:read_file(Path),
285284
assert_diagnostic:assert_binary_match(Expected, unicode:characters_to_binary(Formatted)).
286285

0 commit comments

Comments
 (0)