diff --git a/src/public_interface.jl b/src/public_interface.jl index fe0d033..1f73f51 100644 --- a/src/public_interface.jl +++ b/src/public_interface.jl @@ -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 @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index d857c48..24aae67 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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, @@ -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) @@ -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",