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

How to get code coverage for @traitfn-wrapped functions? #28

Closed
sbromberger opened this issue Mar 14, 2017 · 6 comments
Closed

How to get code coverage for @traitfn-wrapped functions? #28

sbromberger opened this issue Mar 14, 2017 · 6 comments
Labels

Comments

@sbromberger
Copy link

sbromberger commented Mar 14, 2017

I'm using @traitfn like this:

"""docstring"""
foo(x...) = error("Not implemented")            #1
@traitfn foo{X<:XType; IsMyTrait{X}}(x::X) = ...      #2
@traitfn foo{X<:XType; !IsMyTrait{X}}(x::X) = ...     #3

I can get code coverage for #1, but even when I do real tests on foo (#2 and #3), codecov complains that the method isn't tested.

Is there a recommended way to do this? (Also: is there a better way to associate a docstring other than creating a dummy non-traited function?)

@mauro3
Copy link
Owner

mauro3 commented Mar 14, 2017

This would need something like https://github.com/bramtayl/NumberedLines.jl. I hope to do this at some point but it's not high on my priority list.

However, @bramtayl seems keen to see his package used: https://github.com/bramtayl/NumberedLines.jl/issues/1 . So maybe he'd work with you on a PR...

@bramtayl
Copy link
Contributor

Hmm. I'm not sure I'm seeing what the issue is? It looks to me like the line number info is in the function body (fbody), which gets passed through untouched?

@mauro3
Copy link
Owner

mauro3 commented Mar 15, 2017

Sorry, I got confused with my packages: this package has line number information (thanks to @timholy, see here) but Parameters.jl is lacking it. So, I'm not sure why coverage is not reported correctly but it seems a Julia-0.5 issue, as below tests show. @sbromberger can you check whether it works on 0.6?

Running:

# julia --code-coverage coverage-test.jl
using SimpleTraits, Base.Test
@traitdef Tr{X}
@traitimpl Tr{Int}

foo() = 1
@traitfn foo(x::::Tr) = 2
@traitfn foo(x::::(!Tr)) = 3

@test foo()==1
@test foo(1)==2
@test foo(1.0)==3

Julia 0.5 produces no .cov file at all. Conversely, running with 0.6 a .cov file is produced:

        - # julia --code-coverage coverage-test.jl
        - using SimpleTraits, Base.Test
        - @traitdef Tr{X}
        - @traitimpl Tr{Int}
        -
        1 foo() = 1
        2 @traitfn foo(x::::Tr) = 2
        2 @traitfn foo(x::::(!Tr)) = 3
        -
        - @test foo()==1
        - @test foo(1)==2
        - @test foo(1.0)==3

Not 100% right as it over-reports at least the second line. In fact, running a slightly different script shows the problem a bit better:

        - # julia --code-coverage coverage-test.jl
        - using SimpleTraits, Base.Test
        - @traitdef Tr{X}
        - @traitimpl Tr{Int}
        -
        1 foo() = 1
        2 @traitfn foo(x::::Tr) = 2
        - @traitfn function foo(x::::(!Tr))
        4     println("here") # over-reporting
        2     println("here") # over-reporting
        2     println("here") # correct
        2     if x>0
        1         return 3
        -     else
        1         return -3
        -     end
        - end
        -
        -
        - @test foo()==1
        - @test foo(1)==2
        - @test foo(1.0)==3
        - @test foo(-1.0)==-3

@mauro3
Copy link
Owner

mauro3 commented Mar 17, 2017

@sbromberger did you check whether Julia-0.6 gives better coverage results?

@sbromberger
Copy link
Author

@mauro3 I won't be able to do that for a while since we haven't migrated this branch to have compatibility with 0.6.

@mauro3
Copy link
Owner

mauro3 commented Mar 17, 2017

Ok. I don't think there is anything for me to do here (and I certainly wouldn't know what). So, I'll close this. But if you figure something out, a PR is welcome.

@mauro3 mauro3 closed this as completed Mar 17, 2017
@mauro3 mauro3 added the wontfix label Mar 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants