Implement equality for Template and Plugins
This commit is contained in:
parent
a1dc3ef95c
commit
914480157b
@ -1,6 +1,10 @@
|
|||||||
const TEMPLATES_DIR = normpath(joinpath(@__DIR__, "..", "templates"))
|
const TEMPLATES_DIR = normpath(joinpath(@__DIR__, "..", "templates"))
|
||||||
const DEFAULT_PRIORITY = 1000
|
const DEFAULT_PRIORITY = 1000
|
||||||
|
|
||||||
|
function Base.:(==)(a::T, b::T) where T <: Plugin
|
||||||
|
return all(n -> getfield(a, n) == getfield(b, n), fieldnames(T))
|
||||||
|
end
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Secret(name::AbstractString)
|
Secret(name::AbstractString)
|
||||||
|
|
||||||
|
@ -130,6 +130,15 @@ function (t::Template)(pkg::AbstractString)
|
|||||||
@info "New package is at $pkg_dir"
|
@info "New package is at $pkg_dir"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Base.:(==)(a::Template, b::Template)
|
||||||
|
return a.authors == b.authors &&
|
||||||
|
a.dir == b.dir &&
|
||||||
|
a.host == b.host &&
|
||||||
|
a.julia == b.julia &&
|
||||||
|
a.user == b.user &&
|
||||||
|
all(map(==, a.plugins, b.plugins))
|
||||||
|
end
|
||||||
|
|
||||||
# Does the template have a plugin that satisfies some predicate?
|
# Does the template have a plugin that satisfies some predicate?
|
||||||
hasplugin(t::Template, f::Function) = any(f, t.plugins)
|
hasplugin(t::Template, f::Function) = any(f, t.plugins)
|
||||||
hasplugin(t::Template, ::Type{T}) where T <: Plugin = hasplugin(t, p -> p isa T)
|
hasplugin(t::Template, ::Type{T}) where T <: Plugin = hasplugin(t, p -> p isa T)
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
# Don't move this line from the top, please. {{X}} {{Y}} {{Z}}
|
# Don't move this line from the top, please. {{X}} {{Y}} {{Z}}
|
||||||
|
|
||||||
struct BasicTest <: PT.BasicPlugin end
|
struct BasicTest <: PT.BasicPlugin
|
||||||
|
a::String
|
||||||
|
b::Bool
|
||||||
|
end
|
||||||
|
|
||||||
PT.gitignore(::BasicTest) = ["a", "aa", "aaa"]
|
PT.gitignore(::BasicTest) = ["a", "aa", "aaa"]
|
||||||
PT.source(::BasicTest) = @__FILE__
|
PT.source(::BasicTest) = @__FILE__
|
||||||
@ -11,7 +14,7 @@ PT.user_view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 1, "Z" =>
|
|||||||
|
|
||||||
@testset "Plugins" begin
|
@testset "Plugins" begin
|
||||||
@testset "BasicPlugin" begin
|
@testset "BasicPlugin" begin
|
||||||
p = BasicTest()
|
p = BasicTest("foo", true)
|
||||||
t = tpl(; plugins=[p])
|
t = tpl(; plugins=[p])
|
||||||
|
|
||||||
# The X from user_view should override the X from view.
|
# The X from user_view should override the X from view.
|
||||||
@ -34,4 +37,12 @@ PT.user_view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 1, "Z" =>
|
|||||||
@test_logs tpl(; julia=v"1.2", plugins=[p])
|
@test_logs tpl(; julia=v"1.2", plugins=[p])
|
||||||
@test_logs tpl(; julia=v"1.3", plugins=[p])
|
@test_logs tpl(; julia=v"1.3", plugins=[p])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@testset "Equality" begin
|
||||||
|
a = BasicTest("foo", true)
|
||||||
|
b = BasicTest("foo", true)
|
||||||
|
@test a == b
|
||||||
|
c = BasicTest("foo", false)
|
||||||
|
@test a != c
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -44,7 +44,7 @@ const LICENSES_DIR = joinpath(TEMPLATES_DIR, "licenses")
|
|||||||
file: "$(joinpath(TEMPLATES_DIR, "github", "workflows", "TagBot.yml"))"
|
file: "$(joinpath(TEMPLATES_DIR, "github", "workflows", "TagBot.yml"))"
|
||||||
destination: "TagBot.yml"
|
destination: "TagBot.yml"
|
||||||
cron: "0 * * * *"
|
cron: "0 * * * *"
|
||||||
token: \${{ secrets.GITHUB_TOKEN }}
|
token: Secret("GITHUB_TOKEN")
|
||||||
ssh: nothing
|
ssh: nothing
|
||||||
ssh_password: nothing
|
ssh_password: nothing
|
||||||
changelog: nothing
|
changelog: nothing
|
||||||
@ -63,9 +63,8 @@ const LICENSES_DIR = joinpath(TEMPLATES_DIR, "licenses")
|
|||||||
end
|
end
|
||||||
|
|
||||||
@testset "show as serialization" begin
|
@testset "show as serialization" begin
|
||||||
# Equality is not implemented for Template, so check the string form.
|
|
||||||
t1 = tpl()
|
t1 = tpl()
|
||||||
t2 = eval(Meta.parse(sprint(show, t1)))
|
t2 = eval(Meta.parse(sprint(show, t1)))
|
||||||
@test sprint(show, t1) == sprint(show, t2)
|
@test t1 == t2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -50,6 +50,14 @@
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@testset "Equality" begin
|
||||||
|
a = tpl()
|
||||||
|
b = tpl()
|
||||||
|
@test a == b
|
||||||
|
c = tpl(julia=v"0.3")
|
||||||
|
@test a != c
|
||||||
|
end
|
||||||
|
|
||||||
@testset "hasplugin" begin
|
@testset "hasplugin" begin
|
||||||
t = tpl(; plugins=[TravisCI(), Documenter{TravisCI}()])
|
t = tpl(; plugins=[TravisCI(), Documenter{TravisCI}()])
|
||||||
@test PT.hasplugin(t, typeof(first(PT.default_plugins())))
|
@test PT.hasplugin(t, typeof(first(PT.default_plugins())))
|
||||||
|
Loading…
Reference in New Issue
Block a user