PkgTemplates.jl/test/plugin.jl
Chris de Graaf 02d416bedf
Rename BasicPlugin -> FilePlugin (#159)
The new name does a much better job of describing what they're
actually for, IMO.
2020-04-21 13:56:02 -05:00

49 lines
1.7 KiB
Julia

# Don't move this line from the top, please. {{X}} {{Y}} {{Z}}
struct BasicTest <: PT.FilePugin
a::String
b::Bool
end
PT.gitignore(::BasicTest) = ["a", "aa", "aaa"]
PT.source(::BasicTest) = @__FILE__
PT.destination(::BasicTest) = "foo.txt"
PT.badges(::BasicTest) = PT.Badge("{{X}}", "{{Y}}", "{{Z}}")
PT.view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 0, "Y" => 2)
PT.user_view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 1, "Z" => 3)
@testset "Plugins" begin
@testset "FilePugin" begin
p = BasicTest("foo", true)
t = tpl(; plugins=[p])
# The X from user_view should override the X from view.
s = PT.render_plugin(p, t, "")
@test occursin("1 2 3", first(split(s, "\n")))
with_pkg(t) do pkg
pkg_dir = joinpath(t.dir, pkg)
badge = string(PT.Badge("1", "2", "3"))
@test occursin("a\naa\naaa", read(joinpath(pkg_dir, ".gitignore"), String))
@test occursin(badge, read(joinpath(pkg_dir, "README.md"), String))
@test read(joinpath(pkg_dir, "foo.txt"), String) == s
end
end
@testset "Tests Project.toml warning on Julia < 1.2" begin
p = Tests(; project=true)
@test_logs (:warn, r"The project option is set") tpl(; julia=v"1", plugins=[p])
@test_logs (:warn, r"The project option is set") tpl(; julia=v"1.1", plugins=[p])
@test_logs tpl(; julia=v"1.2", plugins=[p])
@test_logs tpl(; julia=v"1.3", plugins=[p])
end
@testset "Equality" begin
a = BasicTest("foo", true)
b = BasicTest("foo", true)
@test a == b
c = BasicTest("foo", false)
@test a != c
end
end