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

Possible bug: Length of coverage does not always match number of source lines in file #234

Closed
DilumAluthge opened this issue Sep 15, 2019 · 0 comments · Fixed by JuliaLang/julia#34281

Comments

@DilumAluthge
Copy link
Member

DilumAluthge commented Sep 15, 2019

Here is a minimal (albeit contrived) example.

In example_1.jl, the length of coverage[1].coverage is equal to the length of split(coverage[1].source, '\n').

However, in example_2.jl, the length of coverage[2].coverage is equal to the length of split(coverage[2].source, '\n')

Contents of example_1.jl:

function foo(x)
    x + x
end

foo(1)

Contents of example_2.jl:

using Test

@testset begin
    @test 1 == 1
    @test 2 == 2
end

Julia session:

shell> ls
example_1.jl	example_2.jl

shell> cat example_1.jl
function foo(x)
    x + x
end

foo(1)

shell> cat example_2.jl
using Test

@testset begin
    @test 1 == 1
    @test 2 == 2
end

julia> split(read("example_1.jl", String), '\n')
6-element Array{SubString{String},1}:
 "function foo(x)"
 "    x + x"
 "end"
 ""
 "foo(1)"
 ""

julia> split(read("example_2.jl", String), '\n')
7-element Array{SubString{String},1}:
 "using Test"
 ""
 "@testset begin"
 "    @test 1 == 1"
 "    @test 2 == 2"
 "end"
 ""

shell> julia --code-coverage example_1.jl

shell> julia --code-coverage example_2.jl
Test Summary: | Pass  Total
test set      |    2      2

julia> using Coverage

julia> coverage = process_folder(pwd());
[ Info: Coverage.process_folder: Searching /Users/dilum/Downloads/example for .jl files...
[ Info: Coverage.process_file: Detecting coverage for /Users/dilum/Downloads/example/example_1.jl
[ Info: Coverage.process_cov: processing /Users/dilum/Downloads/example/example_1.jl.82432.cov
[ Info: Coverage.process_file: Detecting coverage for /Users/dilum/Downloads/example/example_2.jl
┌ Info: Coverage.process_cov: Coverage file(s) for /Users/dilum/Downloads/example/example_2.jl do not exist.
└ Assuming file has no coverage.

julia> split(coverage[1].source, '\n')
6-element Array{SubString{String},1}:
 "function foo(x)"
 "    x + x"
 "end"
 ""
 "foo(1)"
 ""

julia> coverage[1].coverage
6-element Array{Union{Nothing, Int64},1}:
  nothing
 2
  nothing
  nothing
  nothing
  nothing

julia> split(coverage[2].source, '\n')
7-element Array{SubString{String},1}:
 "using Test"
 ""
 "@testset begin"
 "    @test 1 == 1"
 "    @test 2 == 2"
 "end"
 ""

julia> coverage[2].coverage
6-element Array{Union{Nothing, Int64},1}:
 nothing
 nothing
 nothing
 nothing
 nothing
 nothing
@DilumAluthge DilumAluthge changed the title Length of coverage does not always match number of lines in file Length of coverage does not always match number of source lines in file Sep 15, 2019
@DilumAluthge DilumAluthge changed the title Length of coverage does not always match number of source lines in file Possible bug: Length of coverage does not always match number of source lines in file Sep 15, 2019
@vtjnash vtjnash added enhancement and removed bug labels Nov 15, 2019
vtjnash added a commit to JuliaLang/julia that referenced this issue Jan 6, 2020
Previously, we might append an extra empty line to the file.
Also add error checking for I/O faults:

> terminate called after throwing an instance of std::__ios_failure
>   what():  basic_ios::clear: iostream error

Fixes JuliaCI/Coverage.jl#234
vtjnash added a commit to JuliaLang/julia that referenced this issue Jan 9, 2020
Previously, we might append an extra empty line to the file.
Also add error checking for I/O faults:

> terminate called after throwing an instance of std::__ios_failure
>   what():  basic_ios::clear: iostream error

Fixes JuliaCI/Coverage.jl#234
KristofferC pushed a commit to JuliaLang/julia that referenced this issue Apr 11, 2020
Previously, we might append an extra empty line to the file.
Also add error checking for I/O faults:

> terminate called after throwing an instance of std::__ios_failure
>   what():  basic_ios::clear: iostream error

Fixes JuliaCI/Coverage.jl#234
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 a pull request may close this issue.

2 participants