Add a bunch of comments to the tests

This commit is contained in:
Chris de Graaf 2018-09-24 13:25:40 -05:00
parent 07d10c7869
commit ec518577a7
5 changed files with 66 additions and 10 deletions

View File

@ -30,6 +30,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
end end
@testset "File generation" begin @testset "File generation" begin
# 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, temp_dir, test_pkg) == [".appveyor.yml"]
@test isfile(joinpath(pkg_dir, ".appveyor.yml")) @test isfile(joinpath(pkg_dir, ".appveyor.yml"))
@ -39,6 +40,8 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test !occursin("Codecov.submit", appveyor) @test !occursin("Codecov.submit", appveyor)
@test !occursin("Coveralls.submit", appveyor) @test !occursin("Coveralls.submit", appveyor)
rm(joinpath(pkg_dir, ".appveyor.yml")) rm(joinpath(pkg_dir, ".appveyor.yml"))
# 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, temp_dir, test_pkg)
delete!(t.plugins, CodeCov) delete!(t.plugins, CodeCov)
@ -48,6 +51,8 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test occursin("Codecov.submit", appveyor) @test occursin("Codecov.submit", appveyor)
@test !occursin("Coveralls.submit", appveyor) @test !occursin("Coveralls.submit", appveyor)
rm(joinpath(pkg_dir, ".appveyor.yml")) rm(joinpath(pkg_dir, ".appveyor.yml"))
# 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, temp_dir, test_pkg)
delete!(t.plugins, Coveralls) delete!(t.plugins, Coveralls)
@ -57,6 +62,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test occursin("Coveralls.submit", appveyor) @test occursin("Coveralls.submit", appveyor)
@test !occursin("Codecov.submit", appveyor) @test !occursin("Codecov.submit", appveyor)
rm(joinpath(pkg_dir, ".appveyor.yml")) rm(joinpath(pkg_dir, ".appveyor.yml"))
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, temp_dir, test_pkg))
@test !isfile(joinpath(pkg_dir, ".appveyor.yml")) @test !isfile(joinpath(pkg_dir, ".appveyor.yml"))

View File

@ -37,6 +37,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
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, temp_dir, 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.
@test occursin( @test occursin(
strip(""" strip("""
assets=[ assets=[

View File

@ -52,14 +52,18 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@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)
@test occursin("test_template", gitlab) @test occursin("test_template", gitlab)
# The default plugin should enable the 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(; coverage=false) p = GitLabCI(; coverage=false)
gen_plugin(p, t, temp_dir, test_pkg) gen_plugin(p, t, temp_dir, 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.
@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, temp_dir, test_pkg))
@test !isfile(joinpath(pkg_dir, ".gitlab-ci.yml")) @test !isfile(joinpath(pkg_dir, ".gitlab-ci.yml"))
end end

View File

@ -30,15 +30,19 @@ pkg_dir = joinpath(temp_dir, test_pkg)
end end
@testset "File generation" begin @testset "File generation" begin
# 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, temp_dir, 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)
@test !occursin("after_success", travis) @test !occursin("after_success", travis)
@test !occursin("Codecov.submit", travis) @test !occursin("Codecov.submit", travis)
@test !occursin("Coveralls.submit", travis) @test !occursin("Coveralls.submit", travis)
@test !occursin("Pkg.add(\"Documenter\")", travis) @test !occursin("Pkg.add(\"Documenter\")", travis)
rm(joinpath(pkg_dir, ".travis.yml")) rm(joinpath(pkg_dir, ".travis.yml"))
# 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, temp_dir, test_pkg)
delete!(t.plugins, CodeCov) delete!(t.plugins, CodeCov)
@ -48,6 +52,8 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test !occursin("Coveralls.submit", travis) @test !occursin("Coveralls.submit", travis)
@test !occursin("Pkg.add(\"Documenter\")", travis) @test !occursin("Pkg.add(\"Documenter\")", travis)
rm(joinpath(pkg_dir, ".travis.yml")) rm(joinpath(pkg_dir, ".travis.yml"))
# 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, temp_dir, test_pkg)
delete!(t.plugins, Coveralls) delete!(t.plugins, Coveralls)
@ -57,6 +63,8 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test !occursin("Codecov.submit", travis) @test !occursin("Codecov.submit", travis)
@test !occursin("Pkg.add(\"Documenter\")", travis) @test !occursin("Pkg.add(\"Documenter\")", travis)
rm(joinpath(pkg_dir, ".travis.yml")) rm(joinpath(pkg_dir, ".travis.yml"))
# 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, temp_dir, test_pkg)
delete!(t.plugins, GitHubPages) delete!(t.plugins, GitHubPages)
@ -66,6 +74,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test !occursin("Codecov.submit", travis) @test !occursin("Codecov.submit", travis)
@test !occursin("Coveralls.submit", travis) @test !occursin("Coveralls.submit", travis)
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, temp_dir, test_pkg))
@test !isfile(joinpath(pkg_dir, ".travis.yml")) @test !isfile(joinpath(pkg_dir, ".travis.yml"))

View File

@ -1,3 +1,4 @@
# A dummy GenericPlugin subtype.
struct Foo <: GenericPlugin struct Foo <: GenericPlugin
gitignore::Vector{AbstractString} gitignore::Vector{AbstractString}
src::Union{AbstractString, Nothing} src::Union{AbstractString, Nothing}
@ -8,9 +9,12 @@ struct Foo <: GenericPlugin
new([], @__FILE__, config_file, [Badge("foo", "bar", "baz")], Dict{String, Any}()) new([], @__FILE__, config_file, [Badge("foo", "bar", "baz")], Dict{String, Any}())
end end
end end
# A dummy CustomPlugin subtype.
struct Bar <: CustomPlugin end struct Bar <: CustomPlugin end
# A dummy Plugin subtype.
struct Baz <: Plugin end struct Baz <: Plugin end
# Various options to be passed into templates.
const me = "christopher-dG" const me = "christopher-dG"
const gitconfig = Dict( const gitconfig = Dict(
"user.name" => "Tester McTestFace", "user.name" => "Tester McTestFace",
@ -33,6 +37,7 @@ const template_text = """
write(test_file, template_text) write(test_file, template_text)
@testset "Template creation" begin @testset "Template creation" begin
# Checking default field assignments.
t = Template(; user=me) t = Template(; user=me)
@test t.user == me @test t.user == me
@test t.license == "MIT" @test t.license == "MIT"
@ -43,6 +48,8 @@ write(test_file, template_text)
@test isempty(t.gitconfig) @test isempty(t.gitconfig)
@test isempty(t.plugins) @test isempty(t.plugins)
# Checking non-default field assignments.
t = Template(; user=me, license="") t = Template(; user=me, license="")
@test t.license == "" @test t.license == ""
@ -57,12 +64,14 @@ write(test_file, template_text)
t = Template(; user=me, authors="Some Guy") t = Template(; user=me, authors="Some Guy")
@test t.authors == "Some Guy" @test t.authors == "Some Guy"
# Vectors of authors should be comma-joined.
t = Template(; user=me, authors=["Guy", "Gal"]) t = Template(; user=me, authors=["Guy", "Gal"])
@test t.authors == "Guy, Gal" @test t.authors == "Guy, Gal"
t = Template(; user=me, dir=test_file) t = Template(; user=me, dir=test_file)
@test t.dir == abspath(test_file) @test t.dir == abspath(test_file)
if Sys.isunix() # ~ means temporary file on Windows, not $HOME. if Sys.isunix() # ~ means temporary file on Windows, not $HOME.
# '~' should be replaced by home dir.
t = Template(; user=me, dir="~/$(basename(test_file))") t = Template(; user=me, dir="~/$(basename(test_file))")
@test t.dir == joinpath(homedir(), basename(test_file)) @test t.dir == joinpath(homedir(), basename(test_file))
end end
@ -75,8 +84,10 @@ write(test_file, template_text)
t = Template(; user=me, requirements=["$test_pkg 0.1"]) t = Template(; user=me, requirements=["$test_pkg 0.1"])
@test t.requirements == ["$test_pkg 0.1"] @test t.requirements == ["$test_pkg 0.1"]
# Duplicate requirements should warn.
@test_logs (:warn, r".+") t = Template(; user=me, requirements=[test_pkg, test_pkg]) @test_logs (:warn, r".+") t = Template(; user=me, requirements=[test_pkg, test_pkg])
@test t.requirements == [test_pkg] @test t.requirements == [test_pkg]
# Duplicate requirements with non-matching versions should throw.
@test_throws ArgumentError Template(; @test_throws ArgumentError Template(;
user=me, user=me,
requirements=[test_pkg, "$test_pkg 0.1"] requirements=[test_pkg, "$test_pkg 0.1"]
@ -85,6 +96,9 @@ write(test_file, template_text)
t = Template(; user=me, gitconfig=gitconfig) t = Template(; user=me, gitconfig=gitconfig)
@test t.gitconfig == gitconfig @test t.gitconfig == gitconfig
# Git options should be used as fallbacks for template user and authors.
# But an explicitly passed username trumps the gitconfig.
t = Template(; user=me, gitconfig=gitconfig) t = Template(; user=me, gitconfig=gitconfig)
@test t.authors == gitconfig["user.name"] @test t.authors == gitconfig["user.name"]
@ -92,6 +106,7 @@ write(test_file, template_text)
@test t.user == gitconfig["github.user"] @test t.user == gitconfig["github.user"]
@test t.authors == gitconfig["user.name"] @test t.authors == gitconfig["user.name"]
# The template should contain whatever plugins you give it.
t = Template(; t = Template(;
user=me, user=me,
plugins = [GitHubPages(), TravisCI(), AppVeyor(), CodeCov(), Coveralls()], plugins = [GitHubPages(), TravisCI(), AppVeyor(), CodeCov(), Coveralls()],
@ -103,11 +118,13 @@ write(test_file, template_text)
[GitHubPages(), TravisCI(), AppVeyor(), CodeCov(), Coveralls()] [GitHubPages(), TravisCI(), AppVeyor(), CodeCov(), Coveralls()]
) )
# Duplicate plugins should warn.
@test_logs (:warn, r".+") t = Template(; @test_logs (:warn, r".+") t = Template(;
user=me, user=me,
plugins=[TravisCI(), TravisCI()], plugins=[TravisCI(), TravisCI()],
) )
# If github.user is configured, use that as a default.
if isempty(LibGit2.getconfig("github.user", "")) if isempty(LibGit2.getconfig("github.user", ""))
@test_throws ArgumentError Template() @test_throws ArgumentError Template()
else else
@ -117,13 +134,14 @@ write(test_file, template_text)
@test_throws ArgumentError Template(; user=me, license="FakeLicense") @test_throws ArgumentError Template(; user=me, license="FakeLicense")
end end
# TerminalMenus doesn't work quite right on Travis OSX.
if get(ENV, "TRAVIS_OS_NAME", "") != "osx" if get(ENV, "TRAVIS_OS_NAME", "") != "osx"
include(joinpath("interactive", "interactive.jl")) include(joinpath("interactive", "interactive.jl"))
@testset "Interactive plugin creation" begin @testset "Interactive plugin creation" begin
include(joinpath("interactive", "plugins.jl")) include(joinpath("interactive", "plugins.jl"))
end end
else else
@info "Skipping tests that require TerminalMenus" @info "Skipping tests that require TerminalMenus on OSX"
end end
@testset "Show methods" begin @testset "Show methods" begin
@ -205,6 +223,7 @@ end
@test read(temp_file, String) == "Hello, world\n" @test read(temp_file, String) == "Hello, world\n"
rm(temp_file) rm(temp_file)
# Test the README generation.
@test gen_readme(temp_dir, test_pkg, t) == ["README.md"] @test gen_readme(temp_dir, test_pkg, t) == ["README.md"]
@test isfile(joinpath(pkg_dir, "README.md")) @test isfile(joinpath(pkg_dir, "README.md"))
readme = readchomp(joinpath(pkg_dir, "README.md")) readme = readchomp(joinpath(pkg_dir, "README.md"))
@ -229,6 +248,7 @@ end
something(findfirst("baz", readme)).start, something(findfirst("baz", readme)).start,
) )
# Test the gitignore generation.
@test gen_gitignore(temp_dir, test_pkg, t) == [".gitignore"] @test gen_gitignore(temp_dir, test_pkg, t) == [".gitignore"]
@test isfile(joinpath(pkg_dir, ".gitignore")) @test isfile(joinpath(pkg_dir, ".gitignore"))
gitignore = read(joinpath(pkg_dir, ".gitignore"), String) gitignore = read(joinpath(pkg_dir, ".gitignore"), String)
@ -240,6 +260,7 @@ end
end end
end end
# Test the license generation.
@test gen_license(temp_dir, test_pkg, t) == ["LICENSE"] @test gen_license(temp_dir, test_pkg, t) == ["LICENSE"]
@test isfile(joinpath(pkg_dir, "LICENSE")) @test isfile(joinpath(pkg_dir, "LICENSE"))
license = readchomp(joinpath(pkg_dir, "LICENSE")) license = readchomp(joinpath(pkg_dir, "LICENSE"))
@ -248,6 +269,7 @@ end
@test occursin(t.years, license) @test occursin(t.years, license)
@test occursin(read_license(t.license), license) @test occursin(read_license(t.license), license)
# Test the source code entrypoint generation.
@test gen_entrypoint(temp_dir, test_pkg, t) == ["src/"] @test gen_entrypoint(temp_dir, test_pkg, t) == ["src/"]
@test isdir(joinpath(pkg_dir, "src")) @test isdir(joinpath(pkg_dir, "src"))
@test isfile(joinpath(pkg_dir, "src", "$test_pkg.jl")) @test isfile(joinpath(pkg_dir, "src", "$test_pkg.jl"))
@ -262,12 +284,14 @@ end
@test occursin("module $test_pkg", entrypoint) @test occursin("module $test_pkg", entrypoint)
rm(joinpath(pkg_dir, "src"); recursive=true) rm(joinpath(pkg_dir, "src"); recursive=true)
# Test the REQUIRE generation.
@test gen_require(temp_dir, test_pkg, t) == ["REQUIRE"] @test gen_require(temp_dir, test_pkg, t) == ["REQUIRE"]
@test isfile(joinpath(pkg_dir, "REQUIRE")) @test isfile(joinpath(pkg_dir, "REQUIRE"))
vf = version_floor(t.julia_version) vf = version_floor(t.julia_version)
@test readchomp(joinpath(pkg_dir, "REQUIRE")) == "julia $vf\n$test_pkg" @test readchomp(joinpath(pkg_dir, "REQUIRE")) == "julia $vf\n$test_pkg"
rm(joinpath(pkg_dir, "REQUIRE")) rm(joinpath(pkg_dir, "REQUIRE"))
# Test the test generation.
@test gen_tests(temp_dir, test_pkg, t) == ["test/"] @test gen_tests(temp_dir, test_pkg, t) == ["test/"]
@test isdir(joinpath(pkg_dir, "test")) @test isdir(joinpath(pkg_dir, "test"))
@test isfile(joinpath(pkg_dir, "test", "runtests.jl")) @test isfile(joinpath(pkg_dir, "test", "runtests.jl"))
@ -284,6 +308,7 @@ end
generate(test_pkg, t) generate(test_pkg, t)
pkg_dir = joinpath(default_dir, test_pkg) pkg_dir = joinpath(default_dir, test_pkg)
# Check that the expected files all exist.
@test isfile(joinpath(pkg_dir, "LICENSE")) @test isfile(joinpath(pkg_dir, "LICENSE"))
@test isfile(joinpath(pkg_dir, "README.md")) @test isfile(joinpath(pkg_dir, "README.md"))
@test isfile(joinpath(pkg_dir, "REQUIRE")) @test isfile(joinpath(pkg_dir, "REQUIRE"))
@ -292,10 +317,12 @@ end
@test isfile(joinpath(pkg_dir, "src", "$test_pkg.jl")) @test isfile(joinpath(pkg_dir, "src", "$test_pkg.jl"))
@test isdir(joinpath(pkg_dir, "test")) @test isdir(joinpath(pkg_dir, "test"))
@test isfile(joinpath(pkg_dir, "test", "runtests.jl")) @test isfile(joinpath(pkg_dir, "test", "runtests.jl"))
# Check the gitconfig.
repo = LibGit2.GitRepo(pkg_dir) repo = LibGit2.GitRepo(pkg_dir)
remote = LibGit2.get(LibGit2.GitRemote, repo, "origin") remote = LibGit2.get(LibGit2.GitRemote, repo, "origin")
branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo)) branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo))
@test LibGit2.getconfig(repo, "user.name", "") == gitconfig["user.name"] @test LibGit2.getconfig(repo, "user.name", "") == gitconfig["user.name"]
# Check the configured remote and branches.
# Note: This test will fail on your system if you've configured Git # Note: This test will fail on your system if you've configured Git
# to replace all HTTPS URLs with SSH. # to replace all HTTPS URLs with SSH.
@test LibGit2.url(remote) == "https://github.com/$me/$test_pkg.jl" @test LibGit2.url(remote) == "https://github.com/$me/$test_pkg.jl"
@ -304,12 +331,14 @@ end
@test !LibGit2.isdirty(repo) @test !LibGit2.isdirty(repo)
rm(pkg_dir; recursive=true) rm(pkg_dir; recursive=true)
# Check that the remote is an SSH URL.
generate(t, test_pkg; ssh=true) # Test the reversed-arguments method. generate(t, test_pkg; ssh=true) # Test the reversed-arguments method.
repo = LibGit2.GitRepo(pkg_dir) repo = LibGit2.GitRepo(pkg_dir)
remote = LibGit2.get(LibGit2.GitRemote, repo, "origin") remote = LibGit2.get(LibGit2.GitRemote, repo, "origin")
@test LibGit2.url(remote) == "git@github.com:$me/$test_pkg.jl.git" @test LibGit2.url(remote) == "git@github.com:$me/$test_pkg.jl.git"
rm(pkg_dir; recursive=true) rm(pkg_dir; recursive=true)
# Check that the remote is set correctly for non-default hosts.
t = Template(; user=me, host="gitlab.com", gitconfig=gitconfig) t = Template(; user=me, host="gitlab.com", gitconfig=gitconfig)
generate(test_pkg, t) generate(test_pkg, t)
repo = LibGit2.GitRepo(pkg_dir) repo = LibGit2.GitRepo(pkg_dir)
@ -317,12 +346,14 @@ end
@test LibGit2.url(remote) == "https://gitlab.com/$me/$test_pkg.jl" @test LibGit2.url(remote) == "https://gitlab.com/$me/$test_pkg.jl"
rm(pkg_dir; recursive=true) rm(pkg_dir; recursive=true)
# Check that the package ends up in the right directory.
temp_dir = mktempdir() temp_dir = mktempdir()
t = Template(; user=me, dir=temp_dir, gitconfig=gitconfig) t = Template(; user=me, dir=temp_dir, gitconfig=gitconfig)
generate(test_pkg, t) generate(test_pkg, t)
@test isdir(joinpath(temp_dir, test_pkg)) @test isdir(joinpath(temp_dir, test_pkg))
rm(temp_dir; recursive=true) rm(temp_dir; recursive=true)
# Check that all the plugin files are generated.
t = Template(; t = Template(;
user=me, user=me,
license="", license="",
@ -338,6 +369,7 @@ end
@test isfile(joinpath(pkg_dir, "docs", "make.jl")) @test isfile(joinpath(pkg_dir, "docs", "make.jl"))
@test isdir(joinpath(pkg_dir, "docs", "src")) @test isdir(joinpath(pkg_dir, "docs", "src"))
@test isfile(joinpath(pkg_dir, "docs", "src", "index.md")) @test isfile(joinpath(pkg_dir, "docs", "src", "index.md"))
# Test that the gh-pages exists for GitHubPages.
repo = LibGit2.GitRepo(pkg_dir) repo = LibGit2.GitRepo(pkg_dir)
@test LibGit2.getconfig(repo, "user.name", "") == gitconfig["user.name"] @test LibGit2.getconfig(repo, "user.name", "") == gitconfig["user.name"]
branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo)) branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo))
@ -345,12 +377,14 @@ end
@test !LibGit2.isdirty(repo) @test !LibGit2.isdirty(repo)
rm(pkg_dir; recursive=true) rm(pkg_dir; recursive=true)
# Check that an existing directory is removed when force is set.
mkdir(pkg_dir) mkdir(pkg_dir)
@test_throws ArgumentError generate(test_pkg, t) @test_throws ArgumentError generate(test_pkg, t)
generate(test_pkg, t; force=true) generate(test_pkg, t; force=true)
@test isfile(joinpath(pkg_dir, "README.md")) @test isfile(joinpath(pkg_dir, "README.md"))
rm(pkg_dir; recursive=true) rm(pkg_dir; recursive=true)
# Check that the backup directory mechanism works.
temp_file, io = mktemp() temp_file, io = mktemp()
close(io) close(io)
temp_dir = mktempdir() temp_dir = mktempdir()
@ -363,6 +397,7 @@ end
rm(temp_dir; recursive=true) rm(temp_dir; recursive=true)
rm(temp_file) rm(temp_file)
# Check that the generated docs root is just the copied README.
t = Template(; user=me, gitconfig=gitconfig, plugins=[GitHubPages()]) t = Template(; user=me, gitconfig=gitconfig, plugins=[GitHubPages()])
generate(test_pkg, t) generate(test_pkg, t)
readme = read(joinpath(pkg_dir, "README.md"), String) readme = read(joinpath(pkg_dir, "README.md"), String)
@ -427,16 +462,13 @@ end
end end
@testset "License display" begin @testset "License display" begin
old_stdout = stdout io = IOBuffer()
out_read, out_write = redirect_stdout() available_licenses(io)
available_licenses() licenses = String(take!(io))
licenses = String(readavailable(out_read)) show_license(io, "MIT")
show_license("MIT") mit = String(take!(io))
mit = String(readavailable(out_read))
close(out_write)
close(out_read)
redirect_stdout(old_stdout)
# Check that all licenses are included in the display.
for (short, long) in LICENSES for (short, long) in LICENSES
@test occursin("$short: $long", licenses) @test occursin("$short: $long", licenses)
end end
@ -444,9 +476,12 @@ end
@test strip(read_license("MIT")) == strip(read(joinpath(LICENSE_DIR, "MIT"), String)) @test strip(read_license("MIT")) == strip(read(joinpath(LICENSE_DIR, "MIT"), String))
@test_throws ArgumentError read_license(fake_path) @test_throws ArgumentError read_license(fake_path)
# Check that all licenses included with the package are displayed.
for license in readdir(LICENSE_DIR) for license in readdir(LICENSE_DIR)
@test haskey(LICENSES, license) @test haskey(LICENSES, license)
end end
# Check that all licenses displayed are included with the package.
@test length(readdir(LICENSE_DIR)) == length(LICENSES)
end end
@testset "Plugins" begin @testset "Plugins" begin
@ -455,6 +490,7 @@ end
temp_dir = mktempdir() temp_dir = mktempdir()
pkg_dir = joinpath(temp_dir, test_pkg) pkg_dir = joinpath(temp_dir, test_pkg)
# Check badge constructor and formatting.
badge = Badge("A", "B", "C") badge = Badge("A", "B", "C")
@test badge.hover == "A" @test badge.hover == "A"
@test badge.image == "B" @test badge.image == "B"