Skip to content

Commit

Permalink
Wrap stale_deps.jl into module
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Jul 3, 2023
1 parent 5be2a3b commit 43d840d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
20 changes: 15 additions & 5 deletions src/stale_deps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,24 @@ Test that `package` loads all dependencies listed in `Project.toml`.
- `ignore::Vector{Symbol}`: names of dependent packages to be ignored.
"""
function test_stale_deps(packages; kwargs...)
@testset "$(result.label)" for result in analyze_stale_deps(packages, kwargs...)
@testset "$(result.label)" for result in
StaleDeps.analyze_stale_deps(packages, kwargs...)
@debug result.label result
@test result true
end
end

module StaleDeps

using Base: PkgId, UUID
using Pkg: TOML

using Aqua: LazyTestResult, aspkgids, reprpkgid, root_project_or_failed_lazytest

analyze_stale_deps(packages, kwargs...) =
[_analyze_stale_deps_1(pkg; kwargs...) for pkg in aspkgids(packages)]
[analyze_stale_deps_1(pkg; kwargs...) for pkg in aspkgids(packages)]

function _analyze_stale_deps_1(pkg::PkgId; ignore::AbstractVector{Symbol} = Symbol[])
function analyze_stale_deps_1(pkg::PkgId; ignore::AbstractVector{Symbol} = Symbol[])
label = "$pkg"

result = root_project_or_failed_lazytest(pkg)
Expand Down Expand Up @@ -62,7 +70,7 @@ function _analyze_stale_deps_1(pkg::PkgId; ignore::AbstractVector{Symbol} = Symb
output = output[pos.stop+1:end]
loaded_uuids = map(UUID, eachline(IOBuffer(output)))

return _analyze_stale_deps_2(;
return analyze_stale_deps_2(;
pkg = pkg,
deps = deps,
weakdeps = weakdeps,
Expand All @@ -72,7 +80,7 @@ function _analyze_stale_deps_1(pkg::PkgId; ignore::AbstractVector{Symbol} = Symb
end

# Side-effect -free part of stale dependency analysis.
function _analyze_stale_deps_2(;
function analyze_stale_deps_2(;
pkg::PkgId,
deps::AbstractVector{PkgId},
weakdeps::AbstractVector{PkgId},
Expand Down Expand Up @@ -109,3 +117,5 @@ function _analyze_stale_deps_2(;
]
return LazyTestResult(label, join(msglines, "\n"), false)
end

end # module
28 changes: 15 additions & 13 deletions test/test_stale_deps.jl
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
module TestStaleDeps

include("preamble.jl")
using Aqua: PkgId, UUID, _analyze_stale_deps_2, ispass,
using Base: PkgId, UUID
using Aqua: ispass,
using Aqua.StaleDeps: analyze_stale_deps, analyze_stale_deps_2

@testset "_analyze_stale_deps_2" begin
@testset "analyze_stale_deps_2" begin
pkg = PkgId(UUID(42), "TargetPkg")

dep1 = PkgId(UUID(1), "Dep1")
dep2 = PkgId(UUID(2), "Dep2")
dep3 = PkgId(UUID(3), "Dep3")

@testset "pass" begin
@test _analyze_stale_deps_2(;
@test analyze_stale_deps_2(;
pkg = pkg,
deps = PkgId[],
weakdeps = PkgId[],
loaded_uuids = UUID[],
ignore = Symbol[],
) true
@test _analyze_stale_deps_2(;
@test analyze_stale_deps_2(;
pkg = pkg,
deps = PkgId[dep1],
weakdeps = PkgId[],
loaded_uuids = UUID[dep1.uuid, dep2.uuid, dep3.uuid],
ignore = Symbol[],
) true
@test _analyze_stale_deps_2(;
@test analyze_stale_deps_2(;
pkg = pkg,
deps = PkgId[dep1],
weakdeps = PkgId[],
loaded_uuids = UUID[dep2.uuid, dep3.uuid],
ignore = Symbol[:Dep1],
) true
@test _analyze_stale_deps_2(;
@test analyze_stale_deps_2(;
pkg = pkg,
deps = PkgId[dep1],
weakdeps = PkgId[dep2],
loaded_uuids = UUID[dep1.uuid],
ignore = Symbol[],
) true
@test _analyze_stale_deps_2(;
@test analyze_stale_deps_2(;
pkg = pkg,
deps = PkgId[dep1, dep2],
weakdeps = PkgId[dep2],
loaded_uuids = UUID[dep1.uuid],
ignore = Symbol[],
) true
@test _analyze_stale_deps_2(;
@test analyze_stale_deps_2(;
pkg = pkg,
deps = PkgId[dep1, dep2],
weakdeps = PkgId[dep2],
Expand All @@ -55,21 +57,21 @@ using Aqua: PkgId, UUID, _analyze_stale_deps_2, ispass, ⊜
) true
end
@testset "failure" begin
@test _analyze_stale_deps_2(;
@test analyze_stale_deps_2(;
pkg = pkg,
deps = PkgId[dep1],
weakdeps = PkgId[],
loaded_uuids = UUID[],
ignore = Symbol[],
) false
@test _analyze_stale_deps_2(;
@test analyze_stale_deps_2(;
pkg = pkg,
deps = PkgId[dep1],
weakdeps = PkgId[],
loaded_uuids = UUID[dep2.uuid, dep3.uuid],
ignore = Symbol[],
) false
@test _analyze_stale_deps_2(;
@test analyze_stale_deps_2(;
pkg = pkg,
deps = PkgId[dep1, dep2],
weakdeps = PkgId[],
Expand All @@ -82,7 +84,7 @@ end
with_sample_pkgs() do
@testset "Package without `deps`" begin
pkg = AquaTesting.SAMPLE_PKG_BY_NAME["PkgWithoutTestProject"]
results = Aqua.analyze_stale_deps(pkg)
results = analyze_stale_deps(pkg)
@test length(results) == 1
r, = results
@test ispass(r)
Expand All @@ -92,7 +94,7 @@ with_sample_pkgs() do
end
@testset "PkgWithoutProject" begin
pkg = AquaTesting.SAMPLE_PKG_BY_NAME["PkgWithoutProject"]
results = Aqua.analyze_stale_deps(pkg)
results = analyze_stale_deps(pkg)
@test length(results) == 1
r, = results
@test !ispass(r)
Expand Down

0 comments on commit 43d840d

Please sign in to comment.