Skip to content

Commit

Permalink
Require [compat] entry for julia (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens authored Nov 15, 2023
1 parent b943093 commit 1b133dd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `test_ambiguities` now excludes the keyword sorter of all `exclude`d functions with keyword arguments as well. ([#203](https://github.com/JuliaTesting/Aqua.jl/pull/204))
- In `test_deps_compat`, the two subtests `check_extras` and `check_weakdeps` are now run by default. ([#202](https://github.com/JuliaTesting/Aqua.jl/pull/202)) [BREAKING]
- `test_deps_compat` now reqiures compat entries for all dependencies. Stdlibs no longer get ignored. This change is motivated by similar changes in the General registry. ([#215](https://github.com/JuliaTesting/Aqua.jl/pull/215)) [BREAKING]
- `test_deps_compat` now requires a compat entry for `julia` This can be disabling by setting `compat_julia = false`. ([#236](https://github.com/JuliaTesting/Aqua.jl/pull/236)) [BREAKING]
- `test_piracy` is renamed to `test_piracies`. ([#230](https://github.com/JuliaTesting/Aqua.jl/pull/230)) [BREAKING]
- `test_ambiguities` and `test_piracies` now return issues in a defined order. This order may change in a patch release of Aqua.jl. ([#233](https://github.com/JuliaTesting/Aqua.jl/pull/233))
- Improved the message for `test_project_extras` failures. ([#233](https://github.com/JuliaTesting/Aqua.jl/pull/233))
Expand Down
40 changes: 36 additions & 4 deletions src/deps_compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
Aqua.test_deps_compat(package)
Test that the `Project.toml` of `package` has a `compat` entry for
each package listed under `deps`.
each package listed under `deps` and for `julia`.
# Arguments
- `packages`: a top-level `Module`, a `Base.PkgId`, or a collection of
them.
# Keyword Arguments
## Test choosers
- `check_julia = true`: If true, additionally check for a compat entry for "julia".
- `check_extras = true`: If true, additionally check "extras". A NamedTuple
can be used to pass keyword arguments with test options (see below).
- `check_weakdeps = true`: If true, additionally check "weakdeps". A NamedTuple
Expand All @@ -23,18 +24,29 @@ to the corresponding `check_\$x` keyword argument.
`@test` for "deps".
- `ignore::Vector{Symbol}`: names of dependent packages to be ignored.
"""
function test_deps_compat(pkg::PkgId; check_extras = true, check_weakdeps = true, kwargs...)
function test_deps_compat(
pkg::PkgId;
check_julia = true,
check_extras = true,
check_weakdeps = true,
kwargs...,
)
if check_julia !== false
@testset "julia" begin
test_julia_compat(pkg; askwargs(check_julia)...)
end
end
@testset "$pkg deps" begin
test_deps_compat(pkg, "deps"; kwargs...)
end
if check_extras !== false
@testset "$pkg extras" begin
result = test_deps_compat(pkg, "extras"; askwargs(check_extras)...)
test_deps_compat(pkg, "extras"; askwargs(check_extras)...)
end
end
if check_weakdeps !== false
@testset "$pkg weakdeps" begin
result = test_deps_compat(pkg, "weakdeps"; askwargs(check_weakdeps)...)
test_deps_compat(pkg, "weakdeps"; askwargs(check_weakdeps)...)
end
end
end
Expand All @@ -59,6 +71,26 @@ function test_deps_compat(mod::Module; kwargs...)
test_deps_compat(aspkgid(mod); kwargs...)
end

function test_julia_compat(pkg::PkgId; broken::Bool = false, kwargs...)
if broken
@test_broken has_julia_compat(pkg; kwargs...)
else
@test has_julia_compat(pkg; kwargs...)
end
end

function has_julia_compat(pkg::PkgId)
result = root_project_or_failed_lazytest(pkg)
result isa LazyTestResult && error("Unable to locate Project.toml")
root_project_path = result
prj = TOML.parsefile(root_project_path)
return has_julia_compat(prj)
end

function has_julia_compat(prj::Dict{String,Any})
return "julia" in keys(get(prj, "compat", Dict{String,Any}()))
end

function find_missing_deps_compat(pkg::PkgId, deps_type::String = "deps"; kwargs...)
result = root_project_or_failed_lazytest(pkg)
result isa LazyTestResult && error("Unable to locate Project.toml")
Expand Down
25 changes: 24 additions & 1 deletion test/test_deps_compat.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
module TestDepsCompat

include("preamble.jl")
using Aqua: find_missing_deps_compat
using Aqua: find_missing_deps_compat, has_julia_compat

const DictSA = Dict{String,Any}

@testset "has_julia_compat" begin
@test has_julia_compat(DictSA("compat" => DictSA("julia" => "1")))
@test has_julia_compat(DictSA("compat" => DictSA("julia" => "1.0")))
@test has_julia_compat(DictSA("compat" => DictSA("julia" => "1.6")))
@test has_julia_compat(
DictSA(
"deps" => DictSA("PkgA" => "229717a1-0d13-4dfb-ba8f-049672e31205"),
"compat" => DictSA("julia" => "1", "PkgA" => "1.0"),
),
)

@test !has_julia_compat(DictSA())
@test !has_julia_compat(DictSA("compat" => DictSA()))
@test !has_julia_compat(DictSA("compat" => DictSA("PkgA" => "1.0")))
@test !has_julia_compat(
DictSA(
"deps" => DictSA("PkgA" => "229717a1-0d13-4dfb-ba8f-049672e31205"),
"compat" => DictSA("PkgA" => "1.0"),
),
)
end

@testset "find_missing_deps_compat" begin
@testset "pass" begin
result = find_missing_deps_compat(
DictSA("deps" => DictSA(), "compat" => DictSA("julia" => "1")),
"deps",
)
@test isempty(result)

result = find_missing_deps_compat(
DictSA(
"deps" => DictSA("PkgA" => "229717a1-0d13-4dfb-ba8f-049672e31205"),
Expand Down

0 comments on commit 1b133dd

Please sign in to comment.