Skip to content

Commit

Permalink
Merge pull request #83 from paulo-ferraz-oliveira/fix/for-otp27
Browse files Browse the repository at this point in the history
Prevent crash on `sigil_prefix` and `sigil_suffix` (OTP 27)
  • Loading branch information
elbrujohalcon authored Jul 1, 2024
2 parents 5cf3074 + 476e334 commit f897f5c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
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)
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -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, lint, xref, dialyzer, ct, cover, ex_doc]}]}.

%% == Dependencies and plugins ==

Expand Down
6 changes: 6 additions & 0 deletions src/ktn_dodger.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
18 changes: 18 additions & 0 deletions test/files/otp27.erl
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions test/ktn_code_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

-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]).
Expand Down Expand Up @@ -153,6 +158,14 @@ 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.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down

0 comments on commit f897f5c

Please sign in to comment.