Simplify internal API

This commit is contained in:
Chris de Graaf 2018-09-28 15:30:10 -05:00
parent ab2829a6be
commit 9c6a160bc2
12 changed files with 106 additions and 147 deletions

View File

@ -43,7 +43,7 @@ function generate(pkg_name::AbstractString, t::Template)
gen_readme(pkg_dir, t), gen_readme(pkg_dir, t),
gen_gitignore(pkg_dir, t), gen_gitignore(pkg_dir, t),
gen_license(pkg_dir, t), gen_license(pkg_dir, t),
vcat(map(p -> gen_plugin(p, t, t.dir, pkg_name), values(t.plugins))...), vcat(map(p -> gen_plugin(p, t, pkg_name), values(t.plugins))...),
) )
LibGit2.add!(repo, files...) LibGit2.add!(repo, files...)

View File

@ -56,7 +56,7 @@ Generic plugins are plugins that add any number of patterns to the generated pac
end end
end end
interactive(plugin_type::Type{MyPlugin}) = interactive(plugin_type; file="my-plugin.toml") interactive(::Type{MyPlugin}) = interactive(MyPlugin; file="my-plugin.toml")
``` ```
The above plugin ignores files ending with `.mgp`, copies `defaults/my-plugin.toml` by The above plugin ignores files ending with `.mgp`, copies `defaults/my-plugin.toml` by
@ -101,12 +101,7 @@ pattern. They can implement [`gen_plugin`](@ref), [`badges`](@ref), and
MyPlugin() = new([], rand() > 0.8) MyPlugin() = new([], rand() > 0.8)
function gen_plugin( function gen_plugin(p::MyPlugin, t::Template, pkg_name::AbstractString)
plugin::MyPlugin,
template::Template,
dir::AbstractString,
pkg_name::AbstractString,
)
if plugin.lucky if plugin.lucky
text = substitute( text = substitute(
"You got lucky with {{PKGNAME}}, {{USER}}!", "You got lucky with {{PKGNAME}}, {{USER}}!",
@ -137,7 +132,7 @@ pattern. They can implement [`gen_plugin`](@ref), [`badges`](@ref), and
end end
end end
interactive(plugin_type::Type{MyPlugin}) = MyPlugin() interactive(t:Type{MyPlugin}) = MyPlugin()
``` ```
This plugin doesn't do much, but it demonstrates how [`gen_plugin`](@ref), [`badges`](@ref) This plugin doesn't do much, but it demonstrates how [`gen_plugin`](@ref), [`badges`](@ref)
@ -175,96 +170,73 @@ Return `badge`'s data formatted as a Markdown string.
format(b::Badge) = "[![$(b.hover)]($(b.image))]($(b.link))" format(b::Badge) = "[![$(b.hover)]($(b.image))]($(b.link))"
""" """
gen_plugin( gen_plugin(p::Plugin, t::Template, pkg_name::AbstractString) -> Vector{String}
plugin::Plugin,
template::Template,
dir::AbstractString,
pkg_name::AbstractString
) -> Vector{String}
Generate any files associated with a plugin. Generate any files associated with a plugin.
# Arguments # Arguments
* `plugin::Plugin`: Plugin whose files are being generated. * `p::Plugin`: Plugin whose files are being generated.
* `template::Template`: Template configuration. * `t::Template`: Template configuration.
* `dir::AbstractString`: The directory in which the files will be generated. Note that
this will be joined to `pkg_name`.
* `pkg_name::AbstractString`: Name of the package. * `pkg_name::AbstractString`: Name of the package.
Returns an array of generated file/directory names. Returns an array of generated file/directory names.
""" """
function gen_plugin( gen_plugin(::Plugin, ::Template, ::AbstractString) = String[]
plugin::Plugin,
template::Template,
dir::AbstractString,
pkg_name::AbstractString,
)
return String[]
end
function gen_plugin( function gen_plugin(p::GenericPlugin, t::Template, pkg_name::AbstractString)
plugin::GenericPlugin, if p.src === nothing
template::Template,
dir::AbstractString,
pkg_name::AbstractString,
)
if plugin.src === nothing
return String[] return String[]
end end
text = substitute( text = substitute(
read(plugin.src, String), read(p.src, String),
template; t;
view=merge(Dict("PKGNAME" => pkg_name), plugin.view), view=merge(Dict("PKGNAME" => pkg_name), p.view),
) )
gen_file(joinpath(dir, pkg_name, plugin.dest), text) gen_file(joinpath(t.dir, pkg_name, p.dest), text)
return [plugin.dest] return [p.dest]
end end
""" """
badges(plugin::Plugin, user::AbstractString, pkg_name::AbstractString) -> Vector{String} badges(p::Plugin, user::AbstractString, pkg_name::AbstractString) -> Vector{String}
Generate Markdown badges for the plugin. Generate Markdown badges for the plugin.
# Arguments # Arguments
* `plugin::Plugin`: Plugin whose badges we are generating. * `p::Plugin`: Plugin whose badges we are generating.
* `user::AbstractString`: Username of the package creator. * `user::AbstractString`: Username of the package creator.
* `pkg_name::AbstractString`: Name of the package. * `pkg_name::AbstractString`: Name of the package.
Returns an array of Markdown badges. Returns an array of Markdown badges.
""" """
badges(plugin::Plugin, user::AbstractString, pkg_name::AbstractString) = String[] badges(::Plugin, ::AbstractString, ::AbstractString) = String[]
function badges(plugin::GenericPlugin, user::AbstractString, pkg_name::AbstractString) function badges(p::GenericPlugin, user::AbstractString, pkg_name::AbstractString)
# Give higher priority to replacements defined in the plugin's view. # Give higher priority to replacements defined in the plugin's view.
view = merge(Dict("USER" => user, "PKGNAME" => pkg_name), plugin.view) view = merge(Dict("USER" => user, "PKGNAME" => pkg_name), p.view)
return map(b -> substitute(format(b), view), plugin.badges) return map(b -> substitute(format(b), view), p.badges)
end end
""" """
interactive( interactive(t::Type{<:Plugin}; file::Union{AbstractString, Nothing}="") -> Plugin
plugin_type::Type{<:Plugin};
file::Union{AbstractString, Nothing}="",
) -> Plugin
Interactively create a plugin of type `plugin_type`, where `file` is the plugin type's Interactively create a plugin of type `t`, where `file` is the plugin type's default
default config template with a non-standard name (for `MyPlugin`, this is anything but config template with a non-standard name (for `MyPlugin`, this is anything but
"myplugin.yml"). "myplugin.yml").
""" """
function interactive( function interactive(t::Type{<:GenericPlugin}; file::Union{AbstractString, Nothing}="")
plugin_type::Type{<:GenericPlugin}; name = string(nameof(t))
file::Union{AbstractString, Nothing}="",
)
plugin_name = string(nameof(plugin_type))
# By default, we expect the default plugin file template for a plugin called # By default, we expect the default plugin file template for a plugin called
# "MyPlugin" to be called "myplugin.yml". # "MyPlugin" to be called "myplugin.yml".
fn = file != nothing && isempty(file) ? "$(lowercase(plugin_name)).yml" : file fn = file != nothing && isempty(file) ? "$(lowercase(name)).yml" : file
default_config_file = fn == nothing ? fn : joinpath(DEFAULTS_DIR, fn) default_config_file = fn == nothing ? fn : joinpath(DEFAULTS_DIR, fn)
print("$plugin_name: Enter the config template filename (\"None\" for no file) ")
print("$name: Enter the config template filename (\"None\" for no file) ")
if default_config_file == nothing if default_config_file == nothing
print("[None]: ") print("[None]: ")
else else
print("[$(replace(default_config_file, homedir() => "~"))]: ") print("[$(replace(default_config_file, homedir() => "~"))]: ")
end end
config_file = readline() config_file = readline()
config_file = if uppercase(config_file) == "NONE" config_file = if uppercase(config_file) == "NONE"
nothing nothing
@ -273,5 +245,6 @@ function interactive(
else else
config_file config_file
end end
return plugin_type(; config_file=config_file)
return t(; config_file=config_file)
end end

View File

@ -4,34 +4,34 @@ generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl).
""" """
abstract type Documenter <: CustomPlugin end abstract type Documenter <: CustomPlugin end
function gen_plugin( function gen_plugin(p::Documenter, t::Template, pkg_name::AbstractString)
plugin::Documenter, path = joinpath(t.dir, pkg_name)
template::Template,
dir::AbstractString,
pkg_name::AbstractString,
)
path = joinpath(dir, pkg_name)
docs_dir = joinpath(path, "docs", "src") docs_dir = joinpath(path, "docs", "src")
mkpath(docs_dir) mkpath(docs_dir)
if !isempty(plugin.assets)
assets_string = if !isempty(p.assets)
mkpath(joinpath(docs_dir, "assets")) mkpath(joinpath(docs_dir, "assets"))
for file in plugin.assets for file in p.assets
cp(file, joinpath(docs_dir, "assets", basename(file))) cp(file, joinpath(docs_dir, "assets", basename(file)))
end end
# We want something that looks like the following: # We want something that looks like the following:
# [ # [
# assets/file1, # assets/file1,
# assets/file2, # assets/file2,
# ] # ]
tab = repeat(" ", 4) tab = repeat(" ", 4)
assets_string = "[\n" s = "[\n"
for asset in plugin.assets for asset in p.assets
assets_string *= """$(tab^2)"assets/$(basename(asset))",\n""" s *= """$(tab^2)"assets/$(basename(asset))",\n"""
end end
assets_string *= "$tab]" s *= "$tab]"
s
else else
assets_string = "[]" "[]"
end end
text = """ text = """
using Documenter, $pkg_name using Documenter, $pkg_name
@ -41,20 +41,21 @@ function gen_plugin(
pages=[ pages=[
"Home" => "index.md", "Home" => "index.md",
], ],
repo="https://$(template.host)/$(template.user)/$pkg_name.jl/blob/{commit}{path}#L{line}", repo="https://$(t.host)/$(t.user)/$pkg_name.jl/blob/{commit}{path}#L{line}",
sitename="$pkg_name.jl", sitename="$pkg_name.jl",
authors="$(template.authors)", authors="$(t.authors)",
assets=$assets_string, assets=$assets_string,
) )
""" """
gen_file(joinpath(dirname(docs_dir), "make.jl"), text) gen_file(joinpath(dirname(docs_dir), "make.jl"), text)
open(joinpath(docs_dir, "index.md"), "w") do fp
write(fp, "# $pkg_name") # If the README exists, use it as the default docs.
end readme_path = joinpath(t.dir, pkg_name, "README.md")
readme_path = joinpath(dir, pkg_name, "README.md")
if isfile(readme_path) if isfile(readme_path)
cp(readme_path, joinpath(docs_dir, "index.md"), force=true) cp(readme_path, joinpath(docs_dir, "index.md"))
else
gen_file(joinpath(docs_dir, "index.md"), "# $pkg_name")
end end
end end
@ -77,8 +78,8 @@ function Base.show(io::IO, p::Documenter)
n > 0 && print(io, ": $(join(map(g -> "\"$g\"", p.gitignore), ", "))") n > 0 && print(io, ": $(join(map(g -> "\"$g\"", p.gitignore), ", "))")
end end
function interactive(plugin_type::Type{<:Documenter}) function interactive(t::Type{<:Documenter})
t = nameof(plugin_type) name = string(nameof(t))
print("$t: Enter any Documenter asset files (separated by spaces) []: ") print("$name: Enter any Documenter asset files (separated by spaces) []: ")
return plugin_type(; assets=String.(split(readline()))) return t(; assets=string.(split(readline())))
end end

View File

@ -38,25 +38,18 @@ function badges(::GitHubPages, user::AbstractString, pkg_name::AbstractString)
] ]
end end
function gen_plugin( function gen_plugin(p::GitHubPages, t::Template, pkg_name::AbstractString)
plugin::GitHubPages, invoke(gen_plugin, Tuple{Documenter, Template, AbstractString}, p, t, pkg_name)
template::Template,
dir::AbstractString, if haskey(t.plugins, TravisCI)
pkg_name::AbstractString, docs_src = joinpath(t.dir, pkg_name, "docs", "src")
)
invoke(
gen_plugin, Tuple{Documenter, Template, AbstractString, AbstractString},
plugin, template, dir, pkg_name,
)
if haskey(template.plugins, TravisCI)
docs_src = joinpath(dir, pkg_name, "docs", "src")
open(joinpath(dirname(docs_src), "make.jl"), "a") do file open(joinpath(dirname(docs_src), "make.jl"), "a") do file
write( write(
file, file,
""" """
deploydocs(; deploydocs(;
repo="github.com/$(template.user)/$pkg_name.jl", repo="$(t.host)/$(t.user)/$pkg_name.jl",
target="build", target="build",
julia="1.0", julia="1.0",
deps=nothing, deps=nothing,

View File

@ -55,11 +55,11 @@ generated repositories, and appropriate badge(s) to the README.
end end
end end
function interactive(plugin_type::Type{GitLabCI}) function interactive(::Type{GitLabCI})
name = "GitLabCI" name = "GitLabCI"
kwargs = Dict{Symbol, Any}() kwargs = Dict{Symbol, Any}()
default_config_file = joinpath(DEFAULTS_DIR, "gitlab-ci.yml") default_config_file = joinpath(DEFAULTS_DIR, "gitlab-ci.yml")
print("$name: Enter the config template filename (\"None\" for no file) ") print("$name: Enter the config template filename (\"None\" for no file) ")
print("[$default_config_file]: ") print("[$default_config_file]: ")
config_file = readline() config_file = readline()

View File

@ -1,6 +1,5 @@
t = Template(; user=me) t = Template(; user=me)
temp_dir = mktempdir() pkg_dir = joinpath(t.dir, test_pkg)
pkg_dir = joinpath(temp_dir, test_pkg)
@testset "AppVeyor" begin @testset "AppVeyor" begin
@testset "Plugin creation" begin @testset "Plugin creation" begin
@ -31,7 +30,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@testset "File generation" begin @testset "File generation" begin
# Without a coverage plugin in the template, there should be no post-test step. # Without a coverage plugin in the template, there should be no post-test step.
p = AppVeyor() p = AppVeyor()
@test gen_plugin(p, t, temp_dir, test_pkg) == [".appveyor.yml"] @test gen_plugin(p, t, test_pkg) == [".appveyor.yml"]
@test isfile(joinpath(pkg_dir, ".appveyor.yml")) @test isfile(joinpath(pkg_dir, ".appveyor.yml"))
appveyor = read(joinpath(pkg_dir, ".appveyor.yml"), String) appveyor = read(joinpath(pkg_dir, ".appveyor.yml"), String)
@test !occursin("on_success", appveyor) @test !occursin("on_success", appveyor)
@ -40,7 +39,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
# Generating the plugin with CodeCov in the template should create a post-test step. # Generating the plugin with CodeCov in the template should create a post-test step.
t.plugins[CodeCov] = CodeCov() t.plugins[CodeCov] = CodeCov()
gen_plugin(p, t, temp_dir, test_pkg) gen_plugin(p, t, test_pkg)
delete!(t.plugins, CodeCov) delete!(t.plugins, CodeCov)
appveyor = read(joinpath(pkg_dir, ".appveyor.yml"), String) appveyor = read(joinpath(pkg_dir, ".appveyor.yml"), String)
@test occursin("on_success", appveyor) @test occursin("on_success", appveyor)
@ -50,9 +49,9 @@ pkg_dir = joinpath(temp_dir, test_pkg)
# TODO: Add Coveralls tests when AppVeyor.jl supports it. # TODO: Add Coveralls tests when AppVeyor.jl supports it.
p = AppVeyor(; config_file=nothing) p = AppVeyor(; config_file=nothing)
@test isempty(gen_plugin(p, t, temp_dir, test_pkg)) @test isempty(gen_plugin(p, t, test_pkg))
@test !isfile(joinpath(pkg_dir, ".appveyor.yml")) @test !isfile(joinpath(pkg_dir, ".appveyor.yml"))
end end
end end
rm(temp_dir; recursive=true) rm(pkg_dir; recursive=true)

View File

@ -1,6 +1,5 @@
t = Template(; user=me) t = Template(; user=me)
temp_dir = mktempdir() pkg_dir = joinpath(t.dir, test_pkg)
pkg_dir = joinpath(temp_dir, test_pkg)
@testset "CodeCov" begin @testset "CodeCov" begin
@testset "Plugin creation" begin @testset "Plugin creation" begin
@ -30,12 +29,13 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@testset "File generation" begin @testset "File generation" begin
p = CodeCov() p = CodeCov()
@test isempty(gen_plugin(p, t, temp_dir, test_pkg)) @test isempty(gen_plugin(p, t, test_pkg))
@test !isfile(joinpath(pkg_dir, ".codecov.yml"))
p = CodeCov(; config_file=nothing)
@test isempty(gen_plugin(p, t, temp_dir, test_pkg))
@test !isfile(joinpath(pkg_dir, ".codecov.yml")) @test !isfile(joinpath(pkg_dir, ".codecov.yml"))
p = CodeCov(; config_file=test_file)
@test gen_plugin(p, t, test_pkg) == [".codecov.yml"]
@test isfile(joinpath(pkg_dir, ".codecov.yml"))
end end
end end
rm(temp_dir; recursive=true) rm(pkg_dir; recursive=true)

View File

@ -1,6 +1,5 @@
t = Template(; user=me) t = Template(; user=me)
temp_dir = mktempdir() pkg_dir = joinpath(t.dir, test_pkg)
pkg_dir = joinpath(temp_dir, test_pkg)
@testset "Coveralls" begin @testset "Coveralls" begin
@testset "Plugin creation" begin @testset "Plugin creation" begin
@ -30,13 +29,12 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@testset "File generation" begin @testset "File generation" begin
p = Coveralls() p = Coveralls()
@test isempty(gen_plugin(p, t, temp_dir, test_pkg)) @test isempty(gen_plugin(p, t, test_pkg))
@test !isfile(joinpath(pkg_dir, ".coveralls.yml")) @test !isfile(joinpath(pkg_dir, ".coveralls.yml"))
p = Coveralls(; config_file=test_file) p = Coveralls(; config_file=test_file)
@test gen_plugin(p, t, temp_dir, test_pkg) == [".coveralls.yml"] @test gen_plugin(p, t, test_pkg) == [".coveralls.yml"]
@test isfile(joinpath(pkg_dir, ".coveralls.yml")) @test isfile(joinpath(pkg_dir, ".coveralls.yml"))
rm(joinpath(pkg_dir, ".coveralls.yml"))
end end
end end
rm(temp_dir; recursive=true) rm(pkg_dir; recursive=true)

View File

@ -1,6 +1,5 @@
t = Template(; user=me) t = Template(; user=me)
temp_dir = mktempdir() pkg_dir = joinpath(t.dir, test_pkg)
pkg_dir = joinpath(temp_dir, test_pkg)
@testset "GitHubPages" begin @testset "GitHubPages" begin
@testset "Plugin creation" begin @testset "Plugin creation" begin
@ -22,7 +21,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@testset "File generation" begin @testset "File generation" begin
p = GitHubPages() p = GitHubPages()
@test gen_plugin(p, t, temp_dir, test_pkg) == ["docs/"] @test gen_plugin(p, t, test_pkg) == ["docs/"]
@test isdir(joinpath(pkg_dir, "docs")) @test isdir(joinpath(pkg_dir, "docs"))
@test isfile(joinpath(pkg_dir, "docs", "make.jl")) @test isfile(joinpath(pkg_dir, "docs", "make.jl"))
make = readchomp(joinpath(pkg_dir, "docs", "make.jl")) make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
@ -34,7 +33,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test index == "# $test_pkg" @test index == "# $test_pkg"
rm(joinpath(pkg_dir, "docs"); recursive=true) rm(joinpath(pkg_dir, "docs"); recursive=true)
p = GitHubPages(; assets=[test_file]) p = GitHubPages(; assets=[test_file])
@test gen_plugin(p, t, temp_dir, test_pkg) == ["docs/"] @test gen_plugin(p, t, test_pkg) == ["docs/"]
make = readchomp(joinpath(pkg_dir, "docs", "make.jl")) make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
# Check the formatting of the assets list. # Check the formatting of the assets list.
@test occursin( @test occursin(
@ -48,16 +47,17 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test isfile(joinpath(pkg_dir, "docs", "src", "assets", basename(test_file))) @test isfile(joinpath(pkg_dir, "docs", "src", "assets", basename(test_file)))
rm(joinpath(pkg_dir, "docs"); recursive=true) rm(joinpath(pkg_dir, "docs"); recursive=true)
t.plugins[TravisCI] = TravisCI() t.plugins[TravisCI] = TravisCI()
@test gen_plugin(p, t, temp_dir, test_pkg) == ["docs/"] @test gen_plugin(p, t, test_pkg) == ["docs/"]
make = readchomp(joinpath(pkg_dir, "docs", "make.jl")) make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
@test occursin("deploydocs", make) @test occursin("deploydocs", make)
rm(joinpath(pkg_dir, "docs"); recursive=true) rm(joinpath(pkg_dir, "docs"); recursive=true)
end end
@testset "Package generation with GitHubPages plugin" begin @testset "Package generation with GitHubPages plugin" begin
t = Template(; user=me, plugins=[GitHubPages()]) temp_dir = mktempdir()
t = Template(; user=me, dir=temp_dir, plugins=[GitHubPages()])
generate(test_pkg, t) generate(test_pkg, t)
pkg_dir = joinpath(default_dir, test_pkg) pkg_dir = joinpath(t.dir, test_pkg)
# Check that the gh-pages branch exists. # Check that the gh-pages branch exists.
repo = LibGit2.GitRepo(pkg_dir) repo = LibGit2.GitRepo(pkg_dir)
@ -68,8 +68,8 @@ pkg_dir = joinpath(temp_dir, test_pkg)
readme = read(joinpath(pkg_dir, "README.md"), String) readme = read(joinpath(pkg_dir, "README.md"), String)
index = read(joinpath(pkg_dir, "docs", "src", "index.md"), String) index = read(joinpath(pkg_dir, "docs", "src", "index.md"), String)
@test readme == index @test readme == index
rm(pkg_dir; recursive=true) rm(temp_dir; recursive=true)
end end
end end
rm(temp_dir; recursive=true) rm(pkg_dir; recursive=true)

View File

@ -1,6 +1,5 @@
t = Template(; user=me) t = Template(; user=me)
temp_dir = mktempdir() pkg_dir = joinpath(t.dir, test_pkg)
pkg_dir = joinpath(temp_dir, test_pkg)
@testset "GitLabCI" begin @testset "GitLabCI" begin
@testset "Plugin creation" begin @testset "Plugin creation" begin
@ -47,7 +46,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@testset "File generation" begin @testset "File generation" begin
p = GitLabCI() p = GitLabCI()
@test gen_plugin(p, t, temp_dir, test_pkg) == [".gitlab-ci.yml"] @test gen_plugin(p, t, test_pkg) == [".gitlab-ci.yml"]
@test isfile(joinpath(pkg_dir, ".gitlab-ci.yml")) @test isfile(joinpath(pkg_dir, ".gitlab-ci.yml"))
gitlab = read(joinpath(pkg_dir, ".gitlab-ci.yml"), String) gitlab = read(joinpath(pkg_dir, ".gitlab-ci.yml"), String)
# The default plugin should enable the coverage step. # The default plugin should enable the coverage step.
@ -55,16 +54,16 @@ pkg_dir = joinpath(temp_dir, test_pkg)
rm(joinpath(pkg_dir, ".gitlab-ci.yml")) rm(joinpath(pkg_dir, ".gitlab-ci.yml"))
p = GitLabCI(; coverage=false) p = GitLabCI(; coverage=false)
gen_plugin(p, t, temp_dir, test_pkg) gen_plugin(p, t, test_pkg)
gitlab = read(joinpath(pkg_dir, ".gitlab-ci.yml"), String) gitlab = read(joinpath(pkg_dir, ".gitlab-ci.yml"), String)
# If coverage is false, there should be no coverage step. # If coverage is false, there should be no coverage step.
@test !occursin("using Coverage", gitlab) @test !occursin("using Coverage", gitlab)
rm(joinpath(pkg_dir, ".gitlab-ci.yml")) rm(joinpath(pkg_dir, ".gitlab-ci.yml"))
p = GitLabCI(; config_file=nothing) p = GitLabCI(; config_file=nothing)
@test isempty(gen_plugin(p, t, temp_dir, test_pkg)) @test isempty(gen_plugin(p, t, test_pkg))
@test !isfile(joinpath(pkg_dir, ".gitlab-ci.yml")) @test !isfile(joinpath(pkg_dir, ".gitlab-ci.yml"))
end end
end end
rm(temp_dir; recursive=true) rm(pkg_dir; recursive=true)

View File

@ -1,6 +1,5 @@
t = Template(; user=me) t = Template(; user=me)
temp_dir = mktempdir() pkg_dir = joinpath(t.dir, test_pkg)
pkg_dir = joinpath(temp_dir, test_pkg)
@testset "TravisCI" begin @testset "TravisCI" begin
@testset "Plugin creation" begin @testset "Plugin creation" begin
@ -31,7 +30,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@testset "File generation" begin @testset "File generation" begin
# Without a coverage plugin in the template, there should be no post-test step. # Without a coverage plugin in the template, there should be no post-test step.
p = TravisCI() p = TravisCI()
@test gen_plugin(p, t, temp_dir, test_pkg) == [".travis.yml"] @test gen_plugin(p, t, test_pkg) == [".travis.yml"]
@test isfile(joinpath(pkg_dir, ".travis.yml")) @test isfile(joinpath(pkg_dir, ".travis.yml"))
travis = read(joinpath(pkg_dir, ".travis.yml"), String) travis = read(joinpath(pkg_dir, ".travis.yml"), String)
@ -43,7 +42,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
# Generating the plugin with CodeCov in the template should create a post-test step. # Generating the plugin with CodeCov in the template should create a post-test step.
t.plugins[CodeCov] = CodeCov() t.plugins[CodeCov] = CodeCov()
gen_plugin(p, t, temp_dir, test_pkg) gen_plugin(p, t, test_pkg)
delete!(t.plugins, CodeCov) delete!(t.plugins, CodeCov)
travis = read(joinpath(pkg_dir, ".travis.yml"), String) travis = read(joinpath(pkg_dir, ".travis.yml"), String)
@test occursin("after_success", travis) @test occursin("after_success", travis)
@ -54,7 +53,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
# Coveralls should do the same. # Coveralls should do the same.
t.plugins[Coveralls] = Coveralls() t.plugins[Coveralls] = Coveralls()
gen_plugin(p, t, temp_dir, test_pkg) gen_plugin(p, t, test_pkg)
delete!(t.plugins, Coveralls) delete!(t.plugins, Coveralls)
travis = read(joinpath(pkg_dir, ".travis.yml"), String) travis = read(joinpath(pkg_dir, ".travis.yml"), String)
@test occursin("after_success", travis) @test occursin("after_success", travis)
@ -65,7 +64,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
# With a Documenter plugin, there should be a docs deployment step. # With a Documenter plugin, there should be a docs deployment step.
t.plugins[GitHubPages] = GitHubPages() t.plugins[GitHubPages] = GitHubPages()
gen_plugin(p, t, temp_dir, test_pkg) gen_plugin(p, t, test_pkg)
delete!(t.plugins, GitHubPages) delete!(t.plugins, GitHubPages)
travis = read(joinpath(pkg_dir, ".travis.yml"), String) travis = read(joinpath(pkg_dir, ".travis.yml"), String)
@test occursin("after_success", travis) @test occursin("after_success", travis)
@ -75,9 +74,9 @@ pkg_dir = joinpath(temp_dir, test_pkg)
rm(joinpath(pkg_dir, ".travis.yml")) rm(joinpath(pkg_dir, ".travis.yml"))
p = TravisCI(; config_file=nothing) p = TravisCI(; config_file=nothing)
@test isempty(gen_plugin(p, t, temp_dir, test_pkg)) @test isempty(gen_plugin(p, t, test_pkg))
@test !isfile(joinpath(pkg_dir, ".travis.yml")) @test !isfile(joinpath(pkg_dir, ".travis.yml"))
end end
end end
rm(temp_dir; recursive=true) rm(pkg_dir; recursive=true)

View File

@ -368,8 +368,7 @@ end
@testset "Plugins" begin @testset "Plugins" begin
t = Template(; user=me) t = Template(; user=me)
temp_dir = mktempdir() pkg_dir = joinpath(t.dir, test_pkg)
pkg_dir = joinpath(temp_dir, test_pkg)
# Check badge constructor and formatting. # Check badge constructor and formatting.
badge = Badge("A", "B", "C") badge = Badge("A", "B", "C")
@ -380,11 +379,11 @@ end
p = Bar() p = Bar()
@test isempty(badges(p, me, test_pkg)) @test isempty(badges(p, me, test_pkg))
@test isempty(gen_plugin(p, t, temp_dir, test_pkg)) @test isempty(gen_plugin(p, t, test_pkg))
p = Baz() p = Baz()
@test isempty(badges(p, me, test_pkg)) @test isempty(badges(p, me, test_pkg))
@test isempty(gen_plugin(p, t, temp_dir, test_pkg)) @test isempty(gen_plugin(p, t, test_pkg))
include(joinpath("plugins", "travisci.jl")) include(joinpath("plugins", "travisci.jl"))
include(joinpath("plugins", "appveyor.jl")) include(joinpath("plugins", "appveyor.jl"))
@ -392,8 +391,6 @@ end
include(joinpath("plugins", "codecov.jl")) include(joinpath("plugins", "codecov.jl"))
include(joinpath("plugins", "coveralls.jl")) include(joinpath("plugins", "coveralls.jl"))
include(joinpath("plugins", "githubpages.jl")) include(joinpath("plugins", "githubpages.jl"))
rm(temp_dir; recursive=true)
end end
rm(test_file) rm(test_file)