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
@testset "File generation" begin
# Without a coverage plugin in the template, there should be no post-test step.
p = AppVeyor()
@test gen_plugin(p, t, temp_dir, test_pkg) == [".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("Coveralls.submit", appveyor)
rm(joinpath(pkg_dir, ".appveyor.yml"))
# Generating the plugin with CodeCov in the template should create a post-test step.
t.plugins[CodeCov] = CodeCov()
gen_plugin(p, t, temp_dir, test_pkg)
delete!(t.plugins, CodeCov)
@ -48,6 +51,8 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test occursin("Codecov.submit", appveyor)
@test !occursin("Coveralls.submit", appveyor)
rm(joinpath(pkg_dir, ".appveyor.yml"))
# Coveralls should do the same.
t.plugins[Coveralls] = Coveralls()
gen_plugin(p, t, temp_dir, test_pkg)
delete!(t.plugins, Coveralls)
@ -57,6 +62,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test occursin("Coveralls.submit", appveyor)
@test !occursin("Codecov.submit", appveyor)
rm(joinpath(pkg_dir, ".appveyor.yml"))
p = AppVeyor(; config_file=nothing)
@test isempty(gen_plugin(p, t, temp_dir, test_pkg))
@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])
@test gen_plugin(p, t, temp_dir, test_pkg) == ["docs/"]
make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
# Check the formatting of the assets list.
@test occursin(
strip("""
assets=[

View File

@ -52,14 +52,18 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test isfile(joinpath(pkg_dir, ".gitlab-ci.yml"))
gitlab = read(joinpath(pkg_dir, ".gitlab-ci.yml"), String)
@test occursin("test_template", gitlab)
# The default plugin should enable the coverage step.
@test occursin("using Coverage", gitlab)
rm(joinpath(pkg_dir, ".gitlab-ci.yml"))
p = GitLabCI(; coverage=false)
gen_plugin(p, t, temp_dir, test_pkg)
gitlab = read(joinpath(pkg_dir, ".gitlab-ci.yml"), String)
# If coverage is false, there should be no coverage step.
@test !occursin("using Coverage", gitlab)
rm(joinpath(pkg_dir, ".gitlab-ci.yml"))
p = GitLabCI(; config_file=nothing)
@test isempty(gen_plugin(p, t, temp_dir, test_pkg))
@test !isfile(joinpath(pkg_dir, ".gitlab-ci.yml"))
end

View File

@ -30,15 +30,19 @@ pkg_dir = joinpath(temp_dir, test_pkg)
end
@testset "File generation" begin
# Without a coverage plugin in the template, there should be no post-test step.
p = TravisCI()
@test gen_plugin(p, t, temp_dir, test_pkg) == [".travis.yml"]
@test isfile(joinpath(pkg_dir, ".travis.yml"))
travis = read(joinpath(pkg_dir, ".travis.yml"), String)
@test !occursin("after_success", travis)
@test !occursin("Codecov.submit", travis)
@test !occursin("Coveralls.submit", travis)
@test !occursin("Pkg.add(\"Documenter\")", travis)
rm(joinpath(pkg_dir, ".travis.yml"))
# Generating the plugin with CodeCov in the template should create a post-test step.
t.plugins[CodeCov] = CodeCov()
gen_plugin(p, t, temp_dir, test_pkg)
delete!(t.plugins, CodeCov)
@ -48,6 +52,8 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test !occursin("Coveralls.submit", travis)
@test !occursin("Pkg.add(\"Documenter\")", travis)
rm(joinpath(pkg_dir, ".travis.yml"))
# Coveralls should do the same.
t.plugins[Coveralls] = Coveralls()
gen_plugin(p, t, temp_dir, test_pkg)
delete!(t.plugins, Coveralls)
@ -57,6 +63,8 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test !occursin("Codecov.submit", travis)
@test !occursin("Pkg.add(\"Documenter\")", travis)
rm(joinpath(pkg_dir, ".travis.yml"))
# With a Documenter plugin, there should be a docs deployment step.
t.plugins[GitHubPages] = GitHubPages()
gen_plugin(p, t, temp_dir, test_pkg)
delete!(t.plugins, GitHubPages)
@ -66,6 +74,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@test !occursin("Codecov.submit", travis)
@test !occursin("Coveralls.submit", travis)
rm(joinpath(pkg_dir, ".travis.yml"))
p = TravisCI(; config_file=nothing)
@test isempty(gen_plugin(p, t, temp_dir, test_pkg))
@test !isfile(joinpath(pkg_dir, ".travis.yml"))

View File

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