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

Handle empty packages (fixes sum bug) #10

Merged
merged 2 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.9'
- '~1.9.0-0'
- 'nightly'
os:
- ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion src/PkgCacheInspector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct PkgCacheSizes
gvarlist::Int
fptrlist::Int
end
PkgCacheSizes() = PkgCacheSizes(0, 0, 0, 0, 0, 0, 0) # for testing

const cache_displaynames = [
"system",
Expand Down Expand Up @@ -63,11 +64,12 @@ struct PkgCacheInfo
filesize::Int
cachesizes::PkgCacheSizes
end
PkgCacheInfo(cachefile::AbstractString, modules) = PkgCacheInfo(cachefile, modules, [], [], [], [], [], [], 0, PkgCacheSizes())

function Base.show(io::IO, info::PkgCacheInfo)
nspecs = count_module_specializations(info.new_specializations)
nspecs = sort(collect(nspecs); by=last, rev=true)
nspecs_tot = sum(last, nspecs)
nspecs_tot = sum(last, nspecs; init=0)

println(io, "Contents of ", info.cachefile, ':')
println(io, " modules: ", info.modules)
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ using Pkg

Pkg.precompile()

module EmptyPkg end

@testset "PkgCacheInspector.jl" begin
info = info_cachefile("Colors")
@test isa(info, PkgCacheInfo)
Expand All @@ -15,4 +17,10 @@ Pkg.precompile()
mis = methodinstances(info)
@test eltype(mis) === Core.MethodInstance
@test length(mis) > 100

# Empty pkgimages do not cause issues
info = PkgCacheInfo("EmptyPkg.so", [EmptyPkg])
str = sprint(show, info)
@test occursin(r"modules: .*EmptyPkg\]", str)
@test occursin(r"file size: +0 \(0 bytes\)", str)
end