From 6246653eb5424207f7e351b669ba128da5c2a0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Muska=C5=82a?= Date: Wed, 28 Aug 2024 13:26:11 +0100 Subject: [PATCH] Add windows to CI --- .github/workflows/ci.yml | 3 +++ test/assert_diagnostic.erl | 28 ++++++++++++++++------------ test/erlfmt_SUITE.erl | 5 ++--- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00fb424..3ff5a3b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/test/assert_diagnostic.erl b/test/assert_diagnostic.erl index 40ee344..ca15457 100644 --- a/test/assert_diagnostic.erl +++ b/test/assert_diagnostic.erl @@ -81,15 +81,19 @@ 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(Expected, Formatted0) -> + %% windows compatibility + Formatted1 = string:replace(Formatted0, <<"\\r\\n">>, <<"\\n">>, all), + Formatted = unicode:characters_to_binary(Formatted1), + ?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. diff --git a/test/erlfmt_SUITE.erl b/test/erlfmt_SUITE.erl index d751c92..15ec823 100644 --- a/test/erlfmt_SUITE.erl +++ b/test/erlfmt_SUITE.erl @@ -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). @@ -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(