Add plugin file generation tests

This commit is contained in:
Chris de Graaf 2017-08-14 17:57:49 -05:00
parent 87a41f00cd
commit 3410fbb406

View File

@ -1,10 +1,11 @@
const invenia_url = "https://github.com/invenia"
const git_config = Dict( const git_config = Dict(
"user.name" => "Tester McTestFace", "user.name" => "Tester McTestFace",
"user.email" => "email@web.site", "user.email" => "email@web.site",
) )
const fake_path = joinpath("fake", "path") const fake_path = joinpath(tempdir(), tempdir())
const test_file = "test.file" const test_file = tempname()
template_text = """ template_text = """
Hello, world Hello, world
{{PKGNAME}} {{PKGNAME}}
@ -17,8 +18,8 @@ template_text = """
write(test_file, template_text) write(test_file, template_text)
@testset "Template creation" begin @testset "Template creation" begin
t = Template(remote_prefix="https://github.com/invenia") t = Template(remote_prefix=invenia_url)
@test t.remote_prefix == "https://github.com/invenia/" @test t.remote_prefix == "$invenia_url/"
@test t.license == nothing @test t.license == nothing
@test t.years == string(Dates.year(Dates.today())) @test t.years == string(Dates.year(Dates.today()))
@test t.authors == LibGit2.getconfig("user.name", "") @test t.authors == LibGit2.getconfig("user.name", "")
@ -27,40 +28,40 @@ write(test_file, template_text)
@test isempty(t.git_config) @test isempty(t.git_config)
@test isempty(t.plugins) @test isempty(t.plugins)
t = Template(remote_prefix="https://github.com/invenia"; license="MIT") t = Template(remote_prefix=invenia_url; license="MIT")
@test t.license == "MIT" @test t.license == "MIT"
t = Template(remote_prefix="https://github.com/invenia"; years=2014) t = Template(remote_prefix=invenia_url; years=2014)
@test t.years == "2014" @test t.years == "2014"
t = Template(remote_prefix="https://github.com/invenia"; years="2014-2015") t = Template(remote_prefix=invenia_url; years="2014-2015")
@test t.years == "2014-2015" @test t.years == "2014-2015"
t = Template(remote_prefix="https://github.com/invenia"; authors="Some Guy") t = Template(remote_prefix=invenia_url; authors="Some Guy")
@test t.authors == "Some Guy" @test t.authors == "Some Guy"
t = Template(remote_prefix="https://github.com/invenia"; authors=["Guy", "Gal"]) t = Template(remote_prefix=invenia_url; authors=["Guy", "Gal"])
@test t.authors == "Guy, Gal" @test t.authors == "Guy, Gal"
t = Template(remote_prefix="https://github.com/invenia"; path=test_file) t = Template(remote_prefix=invenia_url; path=test_file)
@test t.path == test_file @test t.path == test_file
t = Template(remote_prefix="https://github.com/invenia"; julia_version=v"0.1.2") t = Template(remote_prefix=invenia_url; julia_version=v"0.1.2")
@test t.julia_version == v"0.1.2" @test t.julia_version == v"0.1.2"
t = Template(remote_prefix="https://github.com/invenia"; git_config=git_config) t = Template(remote_prefix=invenia_url; git_config=git_config)
@test t.git_config == git_config @test t.git_config == git_config
t = Template(remote_prefix="https://github.com/invenia"; git_config=git_config) t = Template(remote_prefix=invenia_url; git_config=git_config)
@test t.authors == get(git_config, "user.name", "ERROR") @test t.authors == get(git_config, "user.name", "ERROR")
t = Template( t = Template(
remote_prefix="https://github.com/invenia", remote_prefix=invenia_url,
plugins = [GitHubPages(), TravisCI(), AppVeyor(), CodeCov()], plugins = [GitHubPages(), TravisCI(), AppVeyor(), CodeCov()],
) )
@test Set(keys(t.plugins)) == Set([GitHubPages, TravisCI, AppVeyor, CodeCov]) @test Set(keys(t.plugins)) == Set([GitHubPages, TravisCI, AppVeyor, CodeCov])
@test Set(values(t.plugins)) == Set([GitHubPages(), TravisCI(), AppVeyor(), CodeCov()]) @test Set(values(t.plugins)) == Set([GitHubPages(), TravisCI(), AppVeyor(), CodeCov()])
@test_warn r".*" Template(; @test_warn r".*" Template(;
remote_prefix="https://github.com/invenia", remote_prefix=invenia_url,
plugins=[TravisCI(), TravisCI()], plugins=[TravisCI(), TravisCI()],
) )
@ -97,7 +98,7 @@ end
@testset "File generation" begin @testset "File generation" begin
t = Template(; t = Template(;
remote_prefix="https://github.com/invenia", remote_prefix=invenia_url,
license="MPL", license="MPL",
git_config=git_config, git_config=git_config,
plugins=[TravisCI(), CodeCov(), GitHubPages(), AppVeyor()], plugins=[TravisCI(), CodeCov(), GitHubPages(), AppVeyor()],
@ -169,3 +170,102 @@ end
@test contains(runtests, "using Base.Test") @test contains(runtests, "using Base.Test")
end end
end end
@testset "Package generation" begin
t = Template(;
remote_prefix=invenia_url,
license="MIT",
plugins=[AppVeyor(), GitHubPages(), CodeCov(), TravisCI()],
)
generate("TestPkg", t)
@test isfile(Pkg.dir("TestPkg", "LICENSE"))
@test isfile(Pkg.dir("TestPkg", "README.md"))
@test isfile(Pkg.dir("TestPkg", "REQUIRE"))
@test isfile(Pkg.dir("TestPkg", ".gitignore"))
@test isdir(Pkg.dir("TestPkg", "src"))
@test isfile(Pkg.dir("TestPkg", "src", "TestPkg.jl"))
@test isdir(Pkg.dir("TestPkg", "test"))
@test isfile(Pkg.dir("TestPkg", "test", "runtests.jl"))
@test isfile(Pkg.dir("TestPkg", ".travis.yml"))
@test isfile(Pkg.dir("TestPkg", ".appveyor.yml"))
@test isfile(Pkg.dir("TestPkg", ".codecov.yml"))
@test isdir(Pkg.dir("TestPkg", "docs"))
@test isfile(Pkg.dir("TestPkg", "docs", "make.jl"))
@test isdir(Pkg.dir("TestPkg", "docs", "src"))
@test isfile(Pkg.dir("TestPkg", "docs", "src", "index.md"))
repo = LibGit2.GitRepo(Pkg.dir("TestPkg"))
branches = [LibGit2.name(branch[1]) for branch in LibGit2.GitBranchIter(repo)]
@test in("refs/heads/master", branches)
@test in("refs/heads/gh-pages", branches)
@test !LibGit2.isdirty(repo)
rm(Pkg.dir("TestPkg"); recursive=true)
mkdir(Pkg.dir("TestPkg"))
@test_throws ArgumentError generate("TestPkg", t)
end
@testset "Plugin generation" begin
mktempdir() do temp_dir
pkg_dir = joinpath(temp_dir, "TestPkg")
t = Template(; remote_prefix=invenia_url, path=temp_dir)
p = TravisCI()
@test gen_plugin(p, t, "TestPkg") == [".travis.yml"]
@test isfile(joinpath(pkg_dir, ".travis.yml"))
rm(joinpath(pkg_dir, ".travis.yml"))
p = TravisCI(; config_file=nothing)
@test isempty(gen_plugin(p, t, "TestPkg"))
@test !isfile(joinpath(pkg_dir, ".travis.yml"))
@test_throws ArgumentError TravisCI(; config_file=fake_path)
p = AppVeyor()
@test gen_plugin(p, t, "TestPkg") == [".appveyor.yml"]
@test isfile(joinpath(pkg_dir, ".appveyor.yml"))
rm(joinpath(pkg_dir, ".appveyor.yml"))
p = AppVeyor(; config_file=nothing)
@test isempty(gen_plugin(p, t, "TestPkg"))
@test !isfile(joinpath(pkg_dir, ".appveyor.yml"))
@test_throws ArgumentError AppVeyor(; config_file=fake_path)
p = CodeCov()
@test gen_plugin(p, t, "TestPkg") == [".codecov.yml"]
@test isfile(joinpath(pkg_dir, ".codecov.yml"))
rm(joinpath(pkg_dir, ".codecov.yml"))
p = CodeCov(; config_file=nothing)
@test isempty(gen_plugin(p, t, "TestPkg"))
@test !isfile(joinpath(pkg_dir, ".codecov.yml"))
@test_throws ArgumentError CodeCov(; config_file=fake_path)
p = GitHubPages()
@test gen_plugin(p, t, "TestPkg") == ["docs/"]
@test isdir(joinpath(pkg_dir, "docs"))
@test isfile(joinpath(pkg_dir, "docs", "make.jl"))
make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
@test contains(make, "assets=[]")
@test !contains(make, "deploydocs")
@test isdir(joinpath(pkg_dir, "docs", "src"))
@test isfile(joinpath(pkg_dir, "docs", "src", "index.md"))
index = readchomp(joinpath(pkg_dir, "docs", "src", "index.md"))
@test index == "# TestPkg"
rm(joinpath(pkg_dir, "docs"); recursive=true)
p = GitHubPages(; assets=[test_file])
@test gen_plugin(p, t, "TestPkg") == ["docs/"]
make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
@test contains(
make,
strip("""
assets=[
"assets/$(basename(test_file))",
]
""")
)
@test isfile(joinpath(pkg_dir, "docs", "src", "assets", basename(test_file)))
rm(joinpath(pkg_dir, "docs"); recursive=true)
t.plugins[TravisCI] = TravisCI()
@test gen_plugin(p, t, "TestPkg") == ["docs/"]
make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
@test contains(make, "deploydocs")
rm(joinpath(pkg_dir, "docs"); recursive=true)
end
end