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

use 'unite' for eunit error formatting #421

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

binarytemple
Copy link

@binarytemple binarytemple commented Jul 17, 2017

'unite' provides way nicer error output from 'eunit' tests - one thing I found particularly useful when hacking on hackney was the fact that it provides diff'd output on 'assertEqual' assertions whereas the default output formatter truncates the output.

A follow up P/R will patch the unit tests to use assertions rather than equality checks, e.g:

[{V, ?assertEqual(R,hackney_url:parse_url(V)) } || {V, R} <- Tests] ++

I have an active P/R with eproxus to correct a unhandled case statement - this dependency is to my patched version.

Examples:

1) "module 'hackney_integration_tests'"                              
    get_request/0 (/common/hackney/_build/test/lib/hackney/test/hackney_integration_tests.erl:49)                                            
    Instantiation failed:          
    exception error: no match of right hand side value {error,econnrefused}                                                                        in function  hackney_integration_tests:get_request/0 (/common/hackney/_build/test/lib/hackney/test/hackney_integration_tests.erl, line 49)
      in call from hackney_integration_tests:all_tests/0 (/common/hackney/_build/test/lib/hackney/test/hackney_integration_tests.erl, line 7)      in call from hackney_integration_tests:'-http_requests_test_/0-fun-2-'/1 (/common/hackney/_build/test/lib/hackney/test/hackney_integration_tests.erl, line 38)

151 tests passed  1 fixture cancelled  (0.93 s)                       
===> Error running tests

('assertMatch')

 1) parse_and_unparse_url_test_/0 (/common/hackney/_build/test/lib/hackney/test/hackney_url_tests.erl:140)
    Generator failed!
    exception error: {assertEqual,
                         [{module,hackney_url_tests},
                          {line,140},
                          {expression,"hackney_url : parse_url ( V )"},
                          {expected,
                              {hackney_url,hackney_tcp,foo,<<"www.example.com">>,
                                  <<"/path?key=value#Section%205">>,<<"/path">>,
                                  <<"key=value">>,<<"Section%205">>,
                                  "www.example.com",80,<<>>,<<>>}},
                          {value,
                              {hackney_url,hackney_tcp,http,
                                  <<"www.example.com">>,
                                  <<"/path?key=value#Section%205">>,<<"/path">>,
                                  <<"key=value">>,<<"Section%205">>,
                                  "www.example.com",80,<<>>,<<>>}}]}
      in function  hackney_url_tests:'-parse_and_unparse_url_test_/0-fun-0-'/2 (/common/hackney/_build/test/lib/hackney/test/hackney_url_tests.erl, line 140)
      in call from hackney_url_tests:'-parse_and_unparse_url_test_/0-lc$^1/1-1-'/2 (/common/hackney/_build/test/lib/hackney/test/hackney_url_tests.erl, line 140)

87 tests passed  3 fixtures cancelled  (0.72

'unite' provides way nicer error output from 'eunit' tests - one thing I found particularly useful when hacking on hackney was the fact that it provides diff'd output on 'assertEqual' assertions whereas the default output formatter truncates the output. 

A follow up P/R will patch the unit tests to use assertions rather than equality checks, e.g:

```
 [{V, fun() -> ?assertMatch(R,hackney_url:parse_url(V)) end} || {V, R} <- Tests] ++
```


I have an active [P/R](eproxus/unite#10) with eproxus to correct a unhandled case statement - this dependency is to my patched version.

Examples: 

```
1) "module 'hackney_integration_tests'"                              
    get_request/0 (/common/hackney/_build/test/lib/hackney/test/hackney_integration_tests.erl:49)                                            
    Instantiation failed:          
    exception error: no match of right hand side value {error,econnrefused}                                                                        in function  hackney_integration_tests:get_request/0 (/common/hackney/_build/test/lib/hackney/test/hackney_integration_tests.erl, line 49)
      in call from hackney_integration_tests:all_tests/0 (/common/hackney/_build/test/lib/hackney/test/hackney_integration_tests.erl, line 7)      in call from hackney_integration_tests:'-http_requests_test_/0-fun-2-'/1 (/common/hackney/_build/test/lib/hackney/test/hackney_integration_tests.erl, line 38)

151 tests passed  1 fixture cancelled  (0.93 s)                       
===> Error running tests
```
        
('assertMatch') 

```
 1) "http://www.example.com/path?key=value#Section%205"
    parse_and_unparse_url_test_/0 (/common/hackney/_build/test/lib/hackney/test/hackney_url_tests.erl:140)
    Assert match failed!
    Expression:
        hackney_url:parse_url(V)
    Pattern:
        R
    Actual:
        {hackney_url,hackney_tcp,http,<<"www.example.com">>,
                     <<"/path?key=value#Section%205">>,<<"/path">>,
                     <<"key=value">>,<<"Section%205">>,"www.example.com",80,
                     <<>>,<<>>}
```
@binarytemple
Copy link
Author

I've updated the example in the P/R - please ignore the example given in the original commit message ....

@benoitc
Copy link
Owner

benoitc commented Jul 30, 2017

Thanks for the patch. Is unite available on hex? I would prefer to pass a source package name instead

@binarytemple
Copy link
Author

I don't believe so, and there are P/R outstanding for a year on the project (hence my fork). I'm going to reach out to the author (@eproxus).

@eproxus
Copy link

eproxus commented Aug 7, 2017

Hi everyone, I'm back from vacation now. 😄 I'd be happy to put Unite on hex and upgrade it to Rebar3. For some reason I was not watching my own project, so no notifications... 🤦‍♂️

@binarytemple
Copy link
Author

binarytemple commented Aug 7, 2017 via email

@eproxus
Copy link

eproxus commented Sep 13, 2017

Unite is now on Hex.pm: https://hex.pm/packages/unite

There's one caveat and that is that the compatibility fixes for pre-18 versions of Erlang are not in yet. I'll work on those next.

@benoitc
Copy link
Owner

benoitc commented Oct 8, 2017

@eproxus did you manage to have pre-18 support?

@eproxus
Copy link

eproxus commented Oct 9, 2017

@benoitc Not yet. I'll try to finish it this week.

@eproxus
Copy link

eproxus commented Oct 20, 2017

@benoitc Unite 0.3.0 is now published with hex with backwards compatibility

@binarytemple
Copy link
Author

binarytemple commented Oct 20, 2017 via email

@paulo-ferraz-oliveira
Copy link
Contributor

Is this pull request still valid? I find the current eunit output quite readable, and I can't see unite being used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants