From 505614b96029e18ee477a707153e24287d9a42ae Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sat, 29 Jun 2024 03:32:54 +0100 Subject: [PATCH 1/7] Prevent crash on sigil_prefix and sigil_suffix (OTP 27) --- src/ktn_dodger.erl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ktn_dodger.erl b/src/ktn_dodger.erl index f03bc4d..f4e69e2 100644 --- a/src/ktn_dodger.erl +++ b/src/ktn_dodger.erl @@ -984,6 +984,12 @@ token_to_string(var, A) -> atom_to_list(A); token_to_string(dot, dot) -> ".\n"; +% from OTP: -type af_sigil_prefix() :: {'sigil_prefix', anno(), atom()}. +token_to_string(sigil_prefix, _Prefix) -> + ""; +% from OTP: -type af_sigil_suffix() :: {'sigil_suffix', anno(), string()}. +token_to_string(sigil_suffix, _Suffix) -> + ""; token_to_string(Same, Same) -> atom_to_list(Same). From d17dad4933ad1ae6c8c91ab6990ebefd257948ae Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sat, 29 Jun 2024 05:10:11 +0100 Subject: [PATCH 2/7] Add OTP-27 -ready test --- test/files/otp27.erl | 18 ++++++++++++++++++ test/ktn_code_SUITE.erl | 13 +++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/files/otp27.erl diff --git a/test/files/otp27.erl b/test/files/otp27.erl new file mode 100644 index 0000000..2e09d09 --- /dev/null +++ b/test/files/otp27.erl @@ -0,0 +1,18 @@ +-module(otp27). + +-if(?OTP_RELEASE >= 27). + +-include_lib("stdlib/include/assert.hrl"). + +-export([break/0]). + +break() -> + _ = scan:string(~""" + This is valid code. + """), + + Fun = fun () -> ok end, + ?assertMatch({ok, _} + when is_function(Fun, 0), {ok, 'no'}). + +-endif. diff --git a/test/ktn_code_SUITE.erl b/test/ktn_code_SUITE.erl index 0436cf1..199612f 100644 --- a/test/ktn_code_SUITE.erl +++ b/test/ktn_code_SUITE.erl @@ -8,6 +8,12 @@ -export([parse_maybe/1, parse_maybe_else/1]). +-if(?OTP_RELEASE >= 27). + +-export([parse_sigils/1]). + +-endif. + -endif. -define(EXCLUDED_FUNS, [module_info, all, test, init_per_suite, end_per_suite]). @@ -153,6 +159,13 @@ parse_maybe_else(_Config) -> ok. +-if (?OTP_RELEASE >= 27). + +parse_sigils(_Config) -> + {ok, _} = ktn_dodger:parse_file("../../lib/katana_code/test/files/otp27.erl", + [no_fail, parse_macro_definitions]). + +-endif. -endif. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% From 1f8b5f9db10b2db3105b0157d54f8a86ea3098e9 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sat, 29 Jun 2024 05:17:21 +0100 Subject: [PATCH 3/7] Ignore format for stuff rebar3_format doesn't know about yet --- test/files/otp27.erl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/files/otp27.erl b/test/files/otp27.erl index 2e09d09..5ebd827 100644 --- a/test/files/otp27.erl +++ b/test/files/otp27.erl @@ -1,3 +1,4 @@ +-format ignore. -module(otp27). -if(?OTP_RELEASE >= 27). From f099608764f7f51430a55622239286a12f2f3c73 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sat, 29 Jun 2024 05:17:34 +0100 Subject: [PATCH 4/7] But format the stuff it does know about --- test/ktn_code_SUITE.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/ktn_code_SUITE.erl b/test/ktn_code_SUITE.erl index 199612f..d52644b 100644 --- a/test/ktn_code_SUITE.erl +++ b/test/ktn_code_SUITE.erl @@ -13,7 +13,6 @@ -export([parse_sigils/1]). -endif. - -endif. -define(EXCLUDED_FUNS, [module_info, all, test, init_per_suite, end_per_suite]). @@ -159,11 +158,12 @@ parse_maybe_else(_Config) -> ok. --if (?OTP_RELEASE >= 27). +-if(?OTP_RELEASE >= 27). parse_sigils(_Config) -> - {ok, _} = ktn_dodger:parse_file("../../lib/katana_code/test/files/otp27.erl", - [no_fail, parse_macro_definitions]). + {ok, _} = + ktn_dodger:parse_file("../../lib/katana_code/test/files/otp27.erl", + [no_fail, parse_macro_definitions]). -endif. -endif. From 8f11b81878722498dad18c335a7dcd88c195dd92 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sat, 29 Jun 2024 05:22:31 +0100 Subject: [PATCH 5/7] Test CI without cache --- .github/workflows/ci.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45ab974..1916e84 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,16 +20,16 @@ jobs: with: otp-version: ${{matrix.otp}} rebar3-version: ${{matrix.rebar}} - - name: Restore _build - uses: actions/cache@v3 - with: - path: _build - key: _build-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}} - - name: Restore rebar3's cache - uses: actions/cache@v3 - with: - path: ~/.cache/rebar3 - key: rebar3-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}} + #- name: Restore _build + # uses: actions/cache@v3 + # with: + # path: _build + # key: _build-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}} + #- name: Restore rebar3's cache + # uses: actions/cache@v3 + # with: + # path: ~/.cache/rebar3 + # key: rebar3-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}} - name: Compile run: ERL_FLAGS="-enable-feature all" rebar3 compile - name: Format check From 0f37d323c09cda37d9f75beda2823187bbb2ce1d Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sat, 29 Jun 2024 05:47:14 +0100 Subject: [PATCH 6/7] Remove hank from analysis Before it start analysis hank already tries to read files, and is crashing at that moment Since the "wholly ignored" section of the code comes later that the initial analysis that crashes we're left with not using Hank for the time being --- rebar.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rebar.config b/rebar.config index 34b980e..6c01cc9 100644 --- a/rebar.config +++ b/rebar.config @@ -8,7 +8,7 @@ {profiles, [{test, [{cover_enabled, true}, {cover_opts, [verbose]}, {ct_opts, [{verbose, true}]}]}]}. -{alias, [{test, [compile, format, hank, lint, xref, dialyzer, ct, cover, ex_doc]}]}. +{alias, [{test, [compile, format, lint, xref, dialyzer, ct, cover, ex_doc]}]}. %% == Dependencies and plugins == From 476e33433fb0fc5e3f86eceb58b2d5e624213df0 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sat, 29 Jun 2024 05:49:49 +0100 Subject: [PATCH 7/7] Prevent format from crashing --- .github/workflows/ci.yml | 24 ++++++++++++------------ rebar.config | 2 +- test/files/otp27.erl | 1 - 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1916e84..8b92125 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,20 +20,20 @@ jobs: with: otp-version: ${{matrix.otp}} rebar3-version: ${{matrix.rebar}} - #- name: Restore _build - # uses: actions/cache@v3 - # with: - # path: _build - # key: _build-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}} - #- name: Restore rebar3's cache - # uses: actions/cache@v3 - # with: - # path: ~/.cache/rebar3 - # key: rebar3-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}} + - name: Restore _build + uses: actions/cache@v3 + with: + path: _build + key: _build-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}} + - name: Restore rebar3's cache + uses: actions/cache@v3 + with: + path: ~/.cache/rebar3 + key: rebar3-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}} - name: Compile run: ERL_FLAGS="-enable-feature all" rebar3 compile - - name: Format check - run: ERL_FLAGS="-enable-feature all" rebar3 format --verify + #- name: Format check + # run: ERL_FLAGS="-enable-feature all" rebar3 format --verify - name: Run tests and verifications (features not enabled) run: rebar3 test - name: Run tests and verifications (features enabled) diff --git a/rebar.config b/rebar.config index 6c01cc9..867fe26 100644 --- a/rebar.config +++ b/rebar.config @@ -8,7 +8,7 @@ {profiles, [{test, [{cover_enabled, true}, {cover_opts, [verbose]}, {ct_opts, [{verbose, true}]}]}]}. -{alias, [{test, [compile, format, lint, xref, dialyzer, ct, cover, ex_doc]}]}. +{alias, [{test, [compile, lint, xref, dialyzer, ct, cover, ex_doc]}]}. %% == Dependencies and plugins == diff --git a/test/files/otp27.erl b/test/files/otp27.erl index 5ebd827..2e09d09 100644 --- a/test/files/otp27.erl +++ b/test/files/otp27.erl @@ -1,4 +1,3 @@ --format ignore. -module(otp27). -if(?OTP_RELEASE >= 27).