Skip to content

Commit

Permalink
Rename test_stale_deps to test_unused_deps
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Mar 15, 2024
1 parent b51f800 commit 6b4794e
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Aqua.jl provides functions to run a few automatable checks for Julia packages:
* There are no method ambiguities.
* There are no undefined `export`s.
* There are no unbound type parameters.
* There are no stale dependencies listed in `Project.toml`.
* There are no unused dependencies listed in `Project.toml`.
* Check that test target of the root project `Project.toml` and test project (`test/Project.toml`) are consistent.
* Check that all external packages listed in `deps` have corresponding `compat` entries.
* There are no "obvious" type piracies.
Expand Down
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ makedocs(;
"unbound_args.md",
"exports.md",
"project_extras.md",
"stale_deps.md",
"unused_deps.md",
"deps_compat.md",
"piracies.md",
"persistent_tasks.md",
Expand Down
4 changes: 2 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Aqua.jl provides functions to run a few automatable checks for Julia packages:
* There are no method ambiguities.
* There are no undefined `export`s.
* There are no unbound type parameters.
* There are no stale dependencies listed in `Project.toml`.
* There are no unused dependencies listed in `Project.toml`.
* Check that test target of the root project `Project.toml` and test project (`test/Project.toml`) are consistent.
* Check that all external packages listed in `deps` have corresponding `compat` entries.
* There are no "obvious" type piracies.
Expand Down Expand Up @@ -75,7 +75,7 @@ using Aqua
Aqua.test_all(
YourPackage;
ambiguities=(exclude=[SomePackage.some_function], broken=true),
stale_deps=(ignore=[:SomePackage],),
unused_deps=(ignore=[:SomePackage],),
deps_compat=(ignore=[:SomeOtherPackage],),
piracies=false,
)
Expand Down
7 changes: 0 additions & 7 deletions docs/src/stale_deps.md

This file was deleted.

7 changes: 7 additions & 0 deletions docs/src/unused_deps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Unused dependencies

## [Test function](@id test_unused_deps)

```@docs
Aqua.test_unused_deps
```
14 changes: 7 additions & 7 deletions src/Aqua.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include("ambiguities.jl")
include("unbound_args.jl")
include("exports.jl")
include("project_extras.jl")
include("stale_deps.jl")
include("unused_deps.jl")
include("deps_compat.jl")
include("piracies.jl")
include("persistent_tasks.jl")
Expand All @@ -33,7 +33,7 @@ Run the following tests:
* [`test_unbound_args(testtarget)`](@ref test_unbound_args)
* [`test_undefined_exports(testtarget)`](@ref test_undefined_exports)
* [`test_project_extras(testtarget)`](@ref test_project_extras)
* [`test_stale_deps(testtarget)`](@ref test_stale_deps)
* [`test_unused_deps(testtarget)`](@ref test_unused_deps)
* [`test_deps_compat(testtarget)`](@ref test_deps_compat)
* [`test_piracies(testtarget)`](@ref test_piracies)
* [`test_persistent_tasks(testtarget)`](@ref test_persistent_tasks)
Expand All @@ -48,7 +48,7 @@ passed to `\$x` to specify the keyword arguments for `test_\$x`.
- `unbound_args = true`
- `undefined_exports = true`
- `project_extras = true`
- `stale_deps = true`
- `unused_deps = true`
- `deps_compat = true`
- `piracies = true`
- `persistent_tasks = true`
Expand All @@ -59,7 +59,7 @@ function test_all(
unbound_args = true,
undefined_exports = true,
project_extras = true,
stale_deps = true,
unused_deps = true,
deps_compat = true,
piracies = true,
persistent_tasks = true,
Expand All @@ -85,9 +85,9 @@ function test_all(
test_project_extras(testtarget)
end
end
@testset "Stale dependencies" begin
if stale_deps !== false
test_stale_deps(testtarget; askwargs(stale_deps)...)
@testset "Unused dependencies" begin

Check warning on line 88 in src/Aqua.jl

View check run for this annotation

Codecov / codecov/patch

src/Aqua.jl#L88

Added line #L88 was not covered by tests
if unused_deps !== false
test_unused_deps(testtarget; askwargs(unused_deps)...)
end
end
@testset "Compat bounds" begin
Expand Down
36 changes: 18 additions & 18 deletions src/stale_deps.jl → src/unused_deps.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Aqua.test_stale_deps(package; [ignore])
Aqua.test_unused_deps(package; [ignore])
Test that `package` loads all dependencies listed in `Project.toml`.
Note that this does not imply that `package` loads the dependencies
Expand All @@ -14,7 +14,7 @@ directly, this can be achieved via transitivity as well.
!!! warning "Known bug"
Currently, `Aqua.test_stale_deps` does not detect stale
Currently, `Aqua.test_unused_deps` does not detect unused
dependencies when they are in the sysimage. This is considered a
bug and may be fixed in the future. Such a release is considered
non-breaking.
Expand All @@ -26,23 +26,23 @@ directly, this can be achieved via transitivity as well.
# Keyword Arguments
- `ignore::Vector{Symbol}`: names of dependent packages to be ignored.
"""
function test_stale_deps(pkg::PkgId; kwargs...)
stale_deps = find_stale_deps(pkg; kwargs...)
@test isempty(stale_deps)
function test_unused_deps(pkg::PkgId; kwargs...)
unused_deps = find_unused_deps(pkg; kwargs...)
@test isempty(unused_deps)
end

function test_stale_deps(mod::Module; kwargs...)
test_stale_deps(aspkgid(mod); kwargs...)
function test_unused_deps(mod::Module; kwargs...)
test_unused_deps(aspkgid(mod); kwargs...)
end

# Remove in next breaking release
function test_stale_deps(packages::Vector{<:Union{Module,PkgId}}; kwargs...)
function test_unused_deps(packages::Vector{<:Union{Module,PkgId}}; kwargs...)

Check warning on line 39 in src/unused_deps.jl

View check run for this annotation

Codecov / codecov/patch

src/unused_deps.jl#L39

Added line #L39 was not covered by tests
@testset "$pkg" for pkg in packages
test_stale_deps(pkg; kwargs...)
test_unused_deps(pkg; kwargs...)

Check warning on line 41 in src/unused_deps.jl

View check run for this annotation

Codecov / codecov/patch

src/unused_deps.jl#L41

Added line #L41 was not covered by tests
end
end

function find_stale_deps(pkg::PkgId; ignore::AbstractVector{Symbol} = Symbol[])
function find_unused_deps(pkg::PkgId; ignore::AbstractVector{Symbol} = Symbol[])
root_project_path, found = root_project_toml(pkg)
found || error("Unable to locate Project.toml")

Expand All @@ -66,16 +66,16 @@ function find_stale_deps(pkg::PkgId; ignore::AbstractVector{Symbol} = Symbol[])
output = output[pos.stop+1:end]
loaded_uuids = map(UUID, eachline(IOBuffer(output)))

return find_stale_deps_2(;
return find_unused_deps_2(;
deps = deps,
weakdeps = weakdeps,
loaded_uuids = loaded_uuids,
ignore = ignore,
)
end

# Side-effect -free part of stale dependency analysis.
function find_stale_deps_2(;
# Side-effect -free part of unused dependency analysis.
function find_unused_deps_2(;
deps::AbstractVector{PkgId},
weakdeps::AbstractVector{PkgId},
loaded_uuids::AbstractVector{UUID},
Expand All @@ -84,10 +84,10 @@ function find_stale_deps_2(;
deps_uuids = [p.uuid for p in deps]
pkgid_from_uuid = Dict(p.uuid => p for p in deps)

stale_uuids = setdiff(deps_uuids, loaded_uuids)
stale_pkgs = [pkgid_from_uuid[uuid] for uuid in stale_uuids]
stale_pkgs = setdiff(stale_pkgs, weakdeps)
stale_pkgs = [p for p in stale_pkgs if !(Symbol(p.name) in ignore)]
unused_uuids = setdiff(deps_uuids, loaded_uuids)
unused_pkgs = [pkgid_from_uuid[uuid] for uuid in unused_uuids]
unused_pkgs = setdiff(unused_pkgs, weakdeps)
unused_pkgs = [p for p in unused_pkgs if !(Symbol(p.name) in ignore)]

return stale_pkgs
return unused_pkgs
end
4 changes: 2 additions & 2 deletions test/test_smoke.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Aqua
# test defaults
Aqua.test_all(
Aqua;
stale_deps = (; ignore = [:Compat]), # conditionally loaded
unused_deps = (; ignore = [:Compat]), # conditionally loaded
)

# test everything else
Expand All @@ -15,7 +15,7 @@ Aqua.test_all(
unbound_args = false,
undefined_exports = false,
project_extras = false,
stale_deps = false,
unused_deps = false,
deps_compat = false,
piracies = false,
persistent_tasks = false,
Expand Down
26 changes: 13 additions & 13 deletions test/test_stale_deps.jl → test/test_unused_deps.jl
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
module TestStaleDeps
module TestUnusedDeps

include("preamble.jl")
using Base: PkgId, UUID
using Aqua: find_stale_deps_2
using Aqua: find_unused_deps_2

@testset "find_stale_deps_2" begin
@testset "find_unused_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
result = find_stale_deps_2(;
result = find_unused_deps_2(;
deps = PkgId[],
weakdeps = PkgId[],
loaded_uuids = UUID[],
ignore = Symbol[],
)
@test isempty(result)

result = find_stale_deps_2(;
result = find_unused_deps_2(;
deps = PkgId[dep1],
weakdeps = PkgId[],
loaded_uuids = UUID[dep1.uuid, dep2.uuid, dep3.uuid],
ignore = Symbol[],
)
@test isempty(result)

result = find_stale_deps_2(;
result = find_unused_deps_2(;
deps = PkgId[dep1],
weakdeps = PkgId[],
loaded_uuids = UUID[dep2.uuid, dep3.uuid],
ignore = Symbol[:Dep1],
)
@test isempty(result)

result = find_stale_deps_2(;
result = find_unused_deps_2(;
deps = PkgId[dep1],
weakdeps = PkgId[dep2],
loaded_uuids = UUID[dep1.uuid],
ignore = Symbol[],
)
@test isempty(result)

result = find_stale_deps_2(;
result = find_unused_deps_2(;
deps = PkgId[dep1, dep2],
weakdeps = PkgId[dep2],
loaded_uuids = UUID[dep1.uuid],
ignore = Symbol[],
)
@test isempty(result)

result = find_stale_deps_2(;
result = find_unused_deps_2(;
deps = PkgId[dep1, dep2],
weakdeps = PkgId[dep2],
loaded_uuids = UUID[],
Expand All @@ -61,7 +61,7 @@ using Aqua: find_stale_deps_2
@test isempty(result)
end
@testset "failure" begin
result = find_stale_deps_2(;
result = find_unused_deps_2(;
deps = PkgId[dep1],
weakdeps = PkgId[],
loaded_uuids = UUID[],
Expand All @@ -70,7 +70,7 @@ using Aqua: find_stale_deps_2
@test length(result) == 1
@test dep1 in result

result = find_stale_deps_2(;
result = find_unused_deps_2(;
deps = PkgId[dep1],
weakdeps = PkgId[],
loaded_uuids = UUID[dep2.uuid, dep3.uuid],
Expand All @@ -79,7 +79,7 @@ using Aqua: find_stale_deps_2
@test length(result) == 1
@test dep1 in result

result = find_stale_deps_2(;
result = find_unused_deps_2(;
deps = PkgId[dep1, dep2],
weakdeps = PkgId[],
loaded_uuids = UUID[dep3.uuid],
Expand All @@ -93,7 +93,7 @@ end
with_sample_pkgs() do
@testset "Package without `deps`" begin
pkg = AquaTesting.SAMPLE_PKG_BY_NAME["PkgWithoutDeps"]
results = Aqua.find_stale_deps(pkg)
results = Aqua.find_unused_deps(pkg)
@test isempty(results)
end
end
Expand Down

0 comments on commit 6b4794e

Please sign in to comment.