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

Split different tests into submodules #154

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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 src/Aqua.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using .Versions: VersionSpec, semver_spec
include("utils.jl")
include("ambiguities.jl")
include("unbound_args.jl")
include("exports.jl")
include("undefined_exports.jl")
include("project_extras.jl")
include("stale_deps.jl")
include("deps_compat.jl")
Expand Down
67 changes: 24 additions & 43 deletions src/ambiguities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,27 @@ false-positive.
- Other keyword arguments such as `imported` and `ambiguous_bottom`
are passed to `Test.detect_ambiguities` as-is.
"""
test_ambiguities(packages; kwargs...) = _test_ambiguities(aspkgids(packages); kwargs...)
function test_ambiguities(packages; broken::Bool = false, kwargs...)
num_ambiguities, strout, strerr = Ambiguities.find_ambiguities(packages; kwargs...)

const ExcludeSpec = Pair{Base.PkgId,String}

aspkgids(pkg::Union{Module,PkgId}) = aspkgids([pkg])
aspkgids(packages) = mapfoldl(aspkgid, push!, packages, init = PkgId[])
println(stderr, strerr)
println(stdout, strout)

aspkgid(pkg::PkgId) = pkg
function aspkgid(m::Module)
if !ispackage(m)
error("Non-package (non-toplevel) module is not supported. Got: $m")
if broken
@test_broken num_ambiguities == 0
else
@test num_ambiguities == 0
end
return PkgId(m)
end
function aspkgid(name::Symbol)
# Maybe `Base.depwarn()`
return Base.identify_package(String(name))::PkgId
end

ispackage(m::Module) =
if m in (Base, Core)
true
else
parentmodule(m) == m
end
module Ambiguities

using Base: PkgId
using Test: detect_ambiguities

using ..Aqua: aspkgids, checked_repr, reprpkgid

const ExcludeSpec = Pair{Base.PkgId,String}

strnameof(x) = string(x)
strnameof(x::Type) = string(nameof(x))
Expand Down Expand Up @@ -81,23 +77,15 @@ function reprexclude(exspecs::Vector{ExcludeSpec})
itemreprs = map(exspecs) do (pkgid, name)
string("(", reprpkgid(pkgid), " => ", repr(name), ")")
end
return string("Aqua.ExcludeSpec[", join(itemreprs, ", "), "]")
return string("Aqua.Ambiguities.ExcludeSpec[", join(itemreprs, ", "), "]")
end

function _test_ambiguities(packages::Vector{PkgId}; broken::Bool = false, kwargs...)
num_ambiguities, strout, strerr = _find_ambiguities(packages; kwargs...)

println(stderr, strerr)
println(stdout, strout)

if broken
@test_broken num_ambiguities == 0
else
@test num_ambiguities == 0
end
function find_ambiguities(packages; kwargs...)
package_ids = aspkgids(packages)::Vector{PkgId}
return find_ambiguities(package_ids; kwargs...)
end

function _find_ambiguities(
function find_ambiguities(
packages::Vector{PkgId};
color::Union{Bool,Nothing} = nothing,
exclude::AbstractVector = [],
Expand All @@ -113,7 +101,7 @@ function _find_ambiguities(
code = """
$(Base.load_path_setup_code())
using Aqua
Aqua.test_ambiguities_impl(
Aqua.Ambiguities.test_ambiguities_impl(
$packages_repr,
$options_repr,
$exclude_repr,
Expand Down Expand Up @@ -153,15 +141,6 @@ function reprpkgids(packages::Vector{PkgId})
return packages_repr
end

function reprpkgid(pkg::PkgId)
name = pkg.name
if pkg.uuid === nothing
return "Base.PkgId($(repr(name)))"
end
uuid = pkg.uuid.value
return "Base.PkgId(Base.UUID($(repr(uuid))), $(repr(name)))"
end

struct _NoValue end

function getobj(m::Method)
Expand Down Expand Up @@ -252,3 +231,5 @@ function ambiguity_hint(m1::Method, m2::Method)
end
end
end

end # module
19 changes: 17 additions & 2 deletions src/deps_compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,27 @@ Test that `Project.toml` of `package` list all `compat` for `deps`.
- `ignore::Vector{Symbol}`: names of dependent packages to be ignored.
"""
function test_deps_compat(packages; kwargs...)
@testset "$(result.label)" for result in analyze_deps_compat(packages; kwargs...)
@testset "$(result.label)" for result in
DepsCompat.analyze_deps_compat(packages; kwargs...)
@debug result.label result
@test result ⊜ true
end
end

module DepsCompat

using Base: PkgId, UUID
using Pkg: TOML

using ..Aqua: LazyTestResult, aspkgids, isnothing, root_project_or_failed_lazytest, stdlibs

function analyze_deps_compat(packages; kwargs...)
result = [_analyze_deps_compat_1(pkg; kwargs...) for pkg in aspkgids(packages)]
package_ids = aspkgids(packages)::Vector{PkgId}
return analyze_deps_compat(package_ids; kwargs...)
end

function analyze_deps_compat(packages::Vector{PkgId}; kwargs...)
result = [_analyze_deps_compat_1(pkg; kwargs...) for pkg in packages]
return result
end

Expand Down Expand Up @@ -82,3 +95,5 @@ function _analyze_deps_compat_2(
true,
)
end

end # module
43 changes: 0 additions & 43 deletions src/exports.jl

This file was deleted.

69 changes: 35 additions & 34 deletions src/piracy.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
"""
test_piracy(m::Module)

Test that `m` does not commit type piracy.
See [Julia documentation](https://docs.julialang.org/en/v1/manual/style-guide/#Avoid-type-piracy)
for more information about type piracy.

# Keyword Arguments
- `broken::Bool = false`: If true, it uses `@test_broken` instead of
`@test`.
- `treat_as_own = Union{Function, Type}[]`: The types in this container
are considered to be "owned" by the module `m`. This is useful for
testing packages that deliberately commit some type piracy, e.g. modules
adding higher-level functionality to a lightweight C-wrapper, or packages
that are extending `StatsAPI.jl`.
"""
function test_piracy(m::Module; broken::Bool = false, kwargs...)
v = Piracy.hunt(m; kwargs...)
if !isempty(v)
printstyled(
stderr,
"Possible type-piracy detected:\n";
bold = true,
color = Base.error_color(),
)
show(stderr, MIME"text/plain"(), v)
println(stderr)
end
if broken
@test_broken isempty(v)
else
@test isempty(v)
end
end

module Piracy

using Test: @test, @test_broken
Expand Down Expand Up @@ -172,37 +207,3 @@ function hunt(pkg::Base.PkgId; from::Module, kwargs...)
end

end # module

"""
test_piracy(m::Module)

Test that `m` does not commit type piracy.
See [Julia documentation](https://docs.julialang.org/en/v1/manual/style-guide/#Avoid-type-piracy) for more information about type piracy.

# Keyword Arguments
- `broken::Bool = false`: If true, it uses `@test_broken` instead of
`@test`.
- `treat_as_own = Union{Function, Type}[]`: The types in this container
are considered to be "owned" by the module `m`. This is useful for
testing packages that deliberately commit some type piracy, e.g. modules
adding higher-level functionality to a lightweight C-wrapper, or packages
that are extending `StatsAPI.jl`.
"""
function test_piracy(m::Module; broken::Bool = false, kwargs...)
v = Piracy.hunt(m; kwargs...)
if !isempty(v)
printstyled(
stderr,
"Possible type-piracy detected:\n";
bold = true,
color = Base.error_color(),
)
show(stderr, MIME"text/plain"(), v)
println(stderr)
end
if broken
@test_broken isempty(v)
else
@test isempty(v)
end
end
31 changes: 22 additions & 9 deletions src/project_extras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,36 @@ Julia < 1.2 while recording test-only dependency compatibility in
`test/Project.toml`.
"""
function test_project_extras(packages)
@testset "$(result.label)" for result in analyze_project_extras(packages)
@testset "$(result.label)" for result in map(
ProjectExtras.analyze_project_extras,
aspkgids(packages),
)
@debug result.label result
@test result ⊜ true
end
end

function project_toml_path(dir)
candidates = joinpath.(dir, ["Project.toml", "JuliaProject.toml"])
i = findfirst(isfile, candidates)
i === nothing && return candidates[1], false
return candidates[i], true
end
module ProjectExtras

using Base: PkgId
using Pkg: TOML

analyze_project_extras(packages) = map(_analyze_project_extras, aspkgids(packages))
using ..Aqua:
LazyTestResult,
VersionSpec,
aspkgid,
project_toml_path,
root_project_or_failed_lazytest,
semver_spec

is_julia12_or_later(compat::AbstractString) = is_julia12_or_later(semver_spec(compat))
is_julia12_or_later(compat::VersionSpec) = isempty(compat ∩ semver_spec("1.0 - 1.1"))

function _analyze_project_extras(pkg::PkgId)
function analyze_project_extras(pkg)
return analyze_project_extras(aspkgid(pkg))
end

function analyze_project_extras(pkg::PkgId)
label = string(pkg)

result = root_project_or_failed_lazytest(pkg)
Expand Down Expand Up @@ -101,3 +112,5 @@ function _analyze_project_extras(pkg::PkgId)
return LazyTestResult(label, msg, false)
end
end

end # module
Loading