Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unicode support for atoms in asserts is inconsistent #9173

Open
brigadier opened this issue Dec 10, 2024 · 1 comment
Open

unicode support for atoms in asserts is inconsistent #9173

brigadier opened this issue Dec 10, 2024 · 1 comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@brigadier
Copy link
Contributor

brigadier commented Dec 10, 2024

Describe the bug
unicode support for atoms in asserts is inconsistent. With erl +pc unicode some macroses print atoms in errors correctly, some not. I think it is the issue with the ?? expansion in macroses in general.

To Reproduce
in the erl +pc unicode shell:

-module(test).
-include_lib("stdlib/include/assert.hrl").

-export([test1/0, test2/0, test3/0, test4/0]).

test1() -> 
    ?assertMatch(<<"атом"/utf8>>, atom).

test2() ->     
    ?assertMatch('атом', atom).

test3() ->     
    ?assertEqual('атом', atom).
    
test4() ->
    ?assertMatch({'атом', <<"атом"/utf8>>}, {atom, <<"atom">>}).

Result:


1> test:test1().
** exception error: {assertMatch,[{module,test},
                                  {line,10},
                                  {expression,"atom"},
                                  {pattern,"<< \"атом\" / utf8 >>"},
                                  {value,atom}]}
     in function  test:test1/0 (test.erl, line 10)
2> test:test2().
** exception error: {assertMatch,[{module,test},
                                  {line,13},
                                  {expression,"atom"},
                                  {pattern,"'\\x{430}\\x{442}\\x{43E}\\x{43C}'"},
                                  {value,atom}]}
     in function  test:test2/0 (test.erl, line 13)
3> test:test3().
** exception error: {assertEqual,[{module,test},
                                  {line,16},
                                  {expression,"atom"},
                                  {expected,'атом'},
                                  {value,atom}]}
     in function  test:test3/0 (test.erl, line 16)
4>test:test4().
** exception error: {assertMatch,[{module,test},
                                  {line,19},
                                  {expression,"{ atom , << \"atom\" >> }"},
                                  {pattern,"{ '\\x{430}\\x{442}\\x{43E}\\x{43C}' , << \"атом\" / utf8 >> }"},
                                  {value,{atom,<<"atom">>}}]}
     in function  test:test4/0 (test.erl, line 19)

Expected behavior


2> test:test2().
** exception error: {assertMatch,[{module,test},
                                  {line,13},
                                  {expression,"atom"},
                                  {pattern,"'атом'"},
                                  {value,atom}]}
     in function  test:test2/0 (test.erl, line 13)

Affected versions
at least OTP 27

@brigadier brigadier added the bug Issue is reported as a bug label Dec 10, 2024
@garazdawi
Copy link
Contributor

It is macro argument stringification that is causing this.

-module(t).

-export([go/0]).
-define(a(A), ??A).

go() -> {?a(atom),?a('атом')}.
1> c(t).
{ok,t}
2> t:go().
{"atom","'\\x{430}\\x{442}\\x{43E}\\x{43C}'"}

I think this is in order to generate the same result for latin1 and utf8 files. I'll leave figuring out of it is a wanted behaviour or not to others :)

@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

3 participants