Skip to content

Commit

Permalink
Increase test coverage (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
DilumAluthge committed Jan 8, 2020
1 parent 34b3496 commit 5407431
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/public_interface.jl
Expand Up @@ -14,7 +14,7 @@ function start(path::AbstractString)
if isfile(path)
return _start_tracking_file(path)
else
throw(ArgumentError("Path must be a file"))
throw(ArgumentError("Path must be an existing file"))
end
end

Expand All @@ -37,12 +37,11 @@ function stop(; dump_coverage::Bool = false,
end

function clean(path::AbstractString = pwd())
_realpath::String = convert(String, realpath(path))::String
if isfile(_realpath)
return _clean_file(_realpath)
elseif isdir(_realpath)
return _clean_directory(_realpath)
if isfile(path)
return _clean_file(convert(String, realpath(path)))
elseif isdir(path)
return _clean_directory(convert(String, realpath(path)))
else
throw(ArgumentError("Path must be a file or directory"))
throw(ArgumentError("Path must be an existing file or directory"))
end
end
11 changes: 10 additions & 1 deletion test/runtests.jl
Expand Up @@ -11,9 +11,14 @@ using Test
@test MicroCoverage.always_assert(true, "") == nothing
@test_throws MicroCoverage.AlwaysAssertionError MicroCoverage.always_assert(false, "")
end
@testset "instrument.jl" begin
MicroCoverage.instrument("", Expr(:block), Val(:block)) == Expr(:block)
end
@testset "public_interface.jl" begin
MicroCoverage.with_temp_dir() do tmp_depot
MicroCoverage.with_temp_dir() do tmp_src_directory
nonexistent_filename = joinpath(tmp_src_directory,
"nonexistent.jl")
foo_jl_filename = joinpath(tmp_src_directory,
"foo.jl")
test_foo_jl_filename = joinpath(tmp_src_directory,
Expand All @@ -34,7 +39,9 @@ using Test
println(io, "")
println(io, "@test foo(1) == \"hello\"")
end
MicroCoverage.start(foo_jl_filename)
@test_throws ArgumentError MicroCoverage.start(nonexistent_filename)
@test_throws ArgumentError MicroCoverage.clean(nonexistent_filename)
MicroCoverage.start(strip(foo_jl_filename))
include(foo_jl_filename)
MicroCoverage.preview_coverage(; dump_coverage_io = devnull)
include(test_foo_jl_filename)
Expand All @@ -47,7 +54,9 @@ using Test
@test isfile(foo_jl_microcov_filename)
@test ispath(foo_jl_microcov_filename)
foo_jl_microcov_filecontents = read(foo_jl_microcov_filename, String)
touch(foo_jl_microcov_filename)
MicroCoverage.clean(foo_jl_filename)
touch(foo_jl_microcov_filename)
MicroCoverage.clean(tmp_src_directory)
@test foo_jl_microcov_filecontents == string("[1,1,1] function foo(x)\n",
"[1,0,1,0,1] if x == 1 || x == 100\n",
Expand Down

0 comments on commit 5407431

Please sign in to comment.