Skip to content

Commit

Permalink
Add more tests (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
DilumAluthge authored Jun 8, 2021
1 parent 682b616 commit 63f71be
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 17 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/CI.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
matrix:
version:
- '1.0'
- '1.6'
- '1'
- 'nightly'
os:
Expand All @@ -42,12 +43,22 @@ jobs:
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
# (NOT pull request) OR ( (pull request) AND (NOT from a fork) )
# In this case, secrets are available, so we can use the `CODECOV_TOKEN`.
if: github.event_name != 'pull_request' || github.repository == github.event.pull_request.head.repo.full_name
with:
file: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
- uses: codecov/codecov-action@v1
# (pull request) AND (from a fork)
# In this case, secrets are NOT available, so we have to rely on Codecov's "tokenless uploads for GitHub Actions" feature.
if: github.event_name == 'pull_request' && github.repository != github.event.pull_request.head.repo.full_name
with:
file: lcov.info
- uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: lcov.info
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-${{ matrix.test_number }}
parallel: true
finish:
Expand All @@ -57,5 +68,5 @@ jobs:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CoverageTools"
uuid = "c36e975a-824b-4404-a568-ef97ca766997"
authors = ["Iain Dunning <[email protected]>"]
version = "1.2.4"
version = "1.2.5"

[compat]
julia = "0.7, 1"
Expand Down
11 changes: 3 additions & 8 deletions src/CoverageTools.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
#######################################################################
# CoverageTools.jl
# Input: Code coverage and memory allocations
# Output: Useful things
# https://github.com/JuliaCI/CoverageTools.jl
#######################################################################
module CoverageTools

export process_folder, process_file
Expand Down Expand Up @@ -318,7 +312,7 @@ module CoverageTools
for file in files
fullfile = joinpath(folder, file)
if isfile(fullfile) && iscovfile(fullfile, filename)
@info "Removing $fullfile"
@info("Removing $(fullfile)")
rm(fullfile)
end
end
Expand All @@ -327,4 +321,5 @@ module CoverageTools
include("lcov.jl")
include("memalloc.jl")
include("parser.jl")
end

end # module
54 changes: 48 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
using CoverageTools
using Test

if VERSION < v"1.1-"
if Base.VERSION < v"1.1"
isnothing(x) = false
isnothing(x::Nothing) = true
end

if Base.VERSION < v"1.4"
function only(x::Array)
i = iterate(x)
if i === nothing
throw(ArgumentError("Collection is empty, must contain exactly 1 element"))
end
(ret, state) = i::NTuple{2,Any}
if iterate(x, state) !== nothing
throw(ArgumentError("Collection has multiple elements, must contain exactly 1 element"))
end
return ret
end
end

withenv("DISABLE_AMEND_COVERAGE_FROM_SRC" => nothing) do

@testset "iscovfile" begin
Expand Down Expand Up @@ -199,11 +213,39 @@ end # testset
end
@test_throws Base.Meta.ParseError(msg) process_file(bustedfile, srcdir)
end # testset

@testset "types" begin
a = CoverageTools.MallocInfo(1, "", 1)
b = CoverageTools.MallocInfo(2, "", 1)
@test CoverageTools.sortbybytes(a, b)

@testset "malloc.jl" begin
@testset "types" begin
a = CoverageTools.MallocInfo(1, "", 1)
b = CoverageTools.MallocInfo(2, "", 1)
@test CoverageTools.sortbybytes(a, b)
end
end # testset

@testset "parser.jl" begin
@testset "function_body_lines!" begin
@testset "ast.head == :module" begin
code = """
module Foo
eval() = "foo"
eval(x) = "bar"
f() = "baz"
end # module
"""
ast = Meta.parse(code)
# remove the top-level line number nodes
filter!(x -> !(x isa LineNumberNode), ast.args[end].args)
flines = []
coverage = CoverageTools.CovCount[]
lineoffset = 1
infunction = false
@test length(flines) == 0
CoverageTools.function_body_lines!(flines, ast, coverage, lineoffset, infunction)
@test length(flines) == 1
@test only(flines) == 4
end

end
end

end # withenv

2 comments on commit 63f71be

@DilumAluthge
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/38443

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.2.5 -m "<description of version>" 63f71bec00dfda1b9ba5b9328fbee07b9f411bc3
git push origin v1.2.5

Please sign in to comment.