Deprecation fixes, mostly in tests (local tests are passing!)

This commit is contained in:
Chris de Graaf 2018-09-19 14:19:16 -05:00
parent 1385d6fa4b
commit e29a6b9d31
12 changed files with 148 additions and 141 deletions

View File

@ -11,4 +11,5 @@ InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
TerminalMenus = "dc548174-15c3-5faf-af27-7997cfbde655" TerminalMenus = "dc548174-15c3-5faf-af27-7997cfbde655"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
URIParser = "30578b45-9adc-5946-b283-645ec420af67" URIParser = "30578b45-9adc-5946-b283-645ec420af67"

View File

@ -8,7 +8,7 @@ const LICENSES = Dict(
"GPL-2.0+" => "GNU Public License, Version 2.0+", "GPL-2.0+" => "GNU Public License, Version 2.0+",
"GPL-3.0+" => "GNU Public License, Version 3.0+", "GPL-3.0+" => "GNU Public License, Version 3.0+",
"LGPL-2.1+" => "Lesser GNU Public License, Version 2.1+", "LGPL-2.1+" => "Lesser GNU Public License, Version 2.1+",
"LGPL-3.0+" => "Lesser GNU Public License, Version 3.0+" "LGPL-3.0+" => "Lesser GNU Public License, Version 3.0+",
) )
""" """
@ -16,16 +16,16 @@ const LICENSES = Dict(
Print the names of all available licenses. Print the names of all available licenses.
""" """
available_licenses(io::IO) = println(io, join(("$k: $v" for (k, v) in LICENSES), "\n")) available_licenses(io::IO) = print(io, join(("$k: $v" for (k, v) in LICENSES), "\n"))
available_licenses() = available_licenses(STDOUT) available_licenses() = available_licenses(stdout)
""" """
show_license([io::IO], license::AbstractString) -> Nothing show_license([io::IO], license::AbstractString) -> Nothing
Print the text of `license`. Errors if the license is not found. Print the text of `license`. Errors if the license is not found.
""" """
show_license(io::IO, license::AbstractString) = println(io, read_license(license)) show_license(io::IO, license::AbstractString) = print(io, read_license(license))
show_license(license::AbstractString) = show_license(STDOUT, license) show_license(license::AbstractString) = show_license(stdout, license)
""" """
read_license(license::AbstractString) -> String read_license(license::AbstractString) -> String

View File

@ -1,5 +1,12 @@
import Base.show import Base.show
"""
dev_dir() -> String
Get the default development directory (~/.julia/dev).
"""
dev_dir() = joinpath(first(DEPOT_PATH), "dev")
""" """
Template(; kwargs...) -> Template Template(; kwargs...) -> Template
@ -24,10 +31,10 @@ create a template, you can use [`interactive_template`](@ref) instead.
license. Supply a string for one author or an array for multiple. Similarly to `user`, license. Supply a string for one author or an array for multiple. Similarly to `user`,
it will try to take the value of a supplied git config's "user.name" key, then the global it will try to take the value of a supplied git config's "user.name" key, then the global
git config's value, if it is left unset. git config's value, if it is left unset.
* `years::Union{Integer, AbstractString}=Dates.year(Dates.today())`: Copyright years on the * `years::Union{Integer, AbstractString}=$(Dates.year(Dates.today()))`: Copyright years on
license. Can be supplied by a number, or a string such as "2016 - 2017". the license. Can be supplied by a number, or a string such as "2016 - 2017".
* `dir::AbstractString=joinpath(first(DEPOT_PATH), "dev")`: Directory in which the package * `dir::AbstractString=$(dev_dir())`: Directory in which the package will go. Relative
will go. Relative paths are converted to absolute ones at template creation time. paths are converted to absolute ones at template creation time.
* `precompile::Bool=true`: Whether or not to enable precompilation in generated packages. * `precompile::Bool=true`: Whether or not to enable precompilation in generated packages.
* `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version. * `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version.
* `requirements::Vector{<:AbstractString}=String[]`: Package requirements. If there are * `requirements::Vector{<:AbstractString}=String[]`: Package requirements. If there are
@ -53,10 +60,10 @@ create a template, you can use [`interactive_template`](@ref) instead.
function Template(; function Template(;
user::AbstractString="", user::AbstractString="",
host::AbstractString="https://github.com", host::AbstractString="https://github.com",
license::Union{AbstractString, Nothing}="MIT", license::AbstractString="MIT",
authors::Union{AbstractString, Vector{<:AbstractString}}="", authors::Union{AbstractString, Vector{<:AbstractString}}="",
years::Union{Integer, AbstractString}=Dates.year(Dates.today()), years::Union{Integer, AbstractString}=Dates.year(Dates.today()),
dir::AbstractString=joinpath(first(DEPOT_PATH), "dev"), dir::AbstractString=dev_dir(),
precompile::Bool=true, precompile::Bool=true,
julia_version::VersionNumber=VERSION, julia_version::VersionNumber=VERSION,
requirements::Vector{<:AbstractString}=String[], requirements::Vector{<:AbstractString}=String[],
@ -98,12 +105,12 @@ create a template, you can use [`interactive_template`](@ref) instead.
"requirements contains duplicate packages with conflicting versions" "requirements contains duplicate packages with conflicting versions"
)) ))
elseif diff > 0 elseif diff > 0
warn("Removed $(diff) duplicate$(diff == 1 ? "" : "s") from requirements") @warn "Removed $(diff) duplicate$(diff == 1 ? "" : "s") from requirements"
end end
plugin_dict = Dict{DataType, Plugin}(typeof(p) => p for p in plugins) plugin_dict = Dict{DataType, Plugin}(typeof(p) => p for p in plugins)
if (length(plugins) != length(plugin_dict)) if (length(plugins) != length(plugin_dict))
warn("Plugin list contained duplicates, only the last of each type was kept") @warn "Plugin list contained duplicates, only the last of each type was kept"
end end
new( new(
@ -206,7 +213,7 @@ function interactive_template(; fast::Bool=false)
io = IOBuffer() io = IOBuffer()
available_licenses(io) available_licenses(io)
licenses = ["" => "", collect(LICENSES)...] licenses = ["" => "", collect(LICENSES)...]
menu = RadioMenu(["None", split(String(take!(io)), "\n")...]) menu = RadioMenu(String["None", split(String(take!(io)), "\n")...])
# If the user breaks out of the menu with Ctrl-c, the result is -1, the absolute # If the user breaks out of the menu with Ctrl-c, the result is -1, the absolute
# value of which correponds to no license. # value of which correponds to no license.
licenses[abs(request(menu))].first licenses[abs(request(menu))].first
@ -235,9 +242,9 @@ function interactive_template(; fast::Bool=false)
end end
kwargs[:dir] = if fast kwargs[:dir] = if fast
joinpath(first(DEPOT_PATH), "dev") dev_dir()
else else
default_dir = "." default_dir = dev_dir()
print("Enter the path to the package directory [$default_dir]: ") print("Enter the path to the package directory [$default_dir]: ")
dir = readline() dir = readline()
isempty(dir) ? default_dir : dir isempty(dir) ? default_dir : dir

View File

@ -2,30 +2,30 @@
# which seems to be the case in Travis CI OSX builds. # which seems to be the case in Travis CI OSX builds.
# https://travis-ci.org/invenia/PkgTemplates.jl/jobs/267682403#L115 # https://travis-ci.org/invenia/PkgTemplates.jl/jobs/267682403#L115
# https://github.com/nick-paul/TerminalMenus.jl/issues/5 # https://github.com/nick-paul/TerminalMenus.jl/issues/5
# This also affects any time we write to STDIN.buffer, because # This also affects any time we write to stdin.buffer, because
# IOStreams do not have that attribute. # IOStreams do not have that attribute.
# Therefore, we skip any interactive tests on OSX builds. # Therefore, we skip any interactive tests on OSX builds.
@testset "Interactive template creation" begin @testset "Interactive template creation" begin
write(STDIN.buffer, "$me\n\n\r\n\n\n\n\nd") write(stdin.buffer, "$me\n\n\r\n\n\n\n\nd")
t = interactive_template() t = interactive_template()
@test t.user == me @test t.user == me
@test t.host == "github.com" @test t.host == "github.com"
@test isempty(t.license) @test isempty(t.license)
@test t.authors == LibGit2.getconfig("user.name", "") @test t.authors == LibGit2.getconfig("user.name", "")
@test t.years == string(Dates.year(Dates.today())) @test t.years == string(Dates.year(Dates.today()))
@test t.dir == Pkg.dir() @test t.dir == default_dir
@test t.julia_version == VERSION @test t.julia_version == VERSION
@test isempty(t.requirements) @test isempty(t.requirements)
@test isempty(t.gitconfig) @test isempty(t.gitconfig)
@test isempty(t.plugins) @test isempty(t.plugins)
if isempty(LibGit2.getconfig("github.user", "")) if isempty(LibGit2.getconfig("github.user", ""))
write(STDIN.buffer, "\n") write(stdin.buffer, "\n")
@test_throws ArgumentError t = interactive_template() @test_throws ArgumentError t = interactive_template()
end end
write(STDIN.buffer, "$me\ngitlab.com\n$('\x1b')[B\r$me\n2016\n$test_file\nno\n0.5\nX Y\nkey val val\nkey2 val2\n\n$('\x1b')[B\r$('\x1b')[B\rd\n\n") write(stdin.buffer, "$me\ngitlab.com\n$('\x1b')[B\r$me\n2016\n$test_file\nno\n0.5\nX Y\nkey val val\nkey2 val2\n\n$('\x1b')[B\r$('\x1b')[B\rd\n\n")
t = interactive_template() t = interactive_template()
@test t.user == me @test t.user == me
@test t.host == "gitlab.com" @test t.host == "gitlab.com"
@ -41,10 +41,10 @@
# Like above, not sure which plugins this will generate. # Like above, not sure which plugins this will generate.
@test length(t.plugins) == 2 @test length(t.plugins) == 2
write(STDIN.buffer, "$me\n\n\r\n\n\n\nA B\n A B\n\nd") write(stdin.buffer, "$me\n\n\r\n\n\n\nA B\nA B\n\nd")
@test_warn r".+" interactive_template() @test_logs (:warn, r".+") match_mode=:any interactive_template()
write(STDIN.buffer, "$me\nd") write(stdin.buffer, "$me\nd")
t = interactive_template(; fast=true) t = interactive_template(; fast=true)
@test t.user == me @test t.user == me
@test t.host == "github.com" @test t.host == "github.com"
@ -52,7 +52,7 @@
@test t.authors == LibGit2.getconfig("user.name", "") @test t.authors == LibGit2.getconfig("user.name", "")
# I guess this could technically break if it runs on New Year's Eve... # I guess this could technically break if it runs on New Year's Eve...
@test t.years == string(Dates.year(Dates.today())) @test t.years == string(Dates.year(Dates.today()))
@test t.dir == Pkg.dir() @test t.dir == default_dir
@test t.julia_version == VERSION @test t.julia_version == VERSION
@test isempty(t.requirements) @test isempty(t.requirements)
@test isempty(t.gitconfig) @test isempty(t.gitconfig)
@ -62,8 +62,8 @@ end
@testset "Interactive package generation" begin @testset "Interactive package generation" begin
cfg = join(("$k $v" for (k, v) in gitconfig), "\n") cfg = join(("$k $v" for (k, v) in gitconfig), "\n")
write(STDIN.buffer, "$me\n\n\r\n\n\n\n$cfg\n\nd") write(stdin.buffer, "$me\n\n\r\n\n\n\n$cfg\n\nd")
generate_interactive(test_pkg) generate_interactive(test_pkg)
@test isdir(Pkg.dir(test_pkg)) @test isdir(joinpath(default_dir, test_pkg))
rm(Pkg.dir(test_pkg); force=true, recursive=true) rm(joinpath(default_dir, test_pkg); force=true, recursive=true)
end end

View File

@ -1,90 +1,90 @@
# These tests are to be skipped in OSX builds, see ./interactive.jl for more info. # These tests are to be skipped in OSX builds, see ./interactive.jl for more info.
@testset "TravisCI" begin @testset "TravisCI" begin
write(STDIN.buffer, "\n") write(stdin.buffer, "\n")
p = interactive(TravisCI) p = interactive(TravisCI)
@test get(p.src, "") == joinpath(DEFAULTS_DIR, "travis.yml") @test p.src == joinpath(DEFAULTS_DIR, "travis.yml")
write(STDIN.buffer, "$test_file\n") write(stdin.buffer, "$test_file\n")
p = interactive(TravisCI) p = interactive(TravisCI)
@test get(p.src, "") == test_file @test p.src == test_file
write(STDIN.buffer, "none\n") write(stdin.buffer, "none\n")
p = interactive(TravisCI) p = interactive(TravisCI)
@test isnull(p.src) @test p.src === nothing
write(STDIN.buffer, "$fake_path\n") write(stdin.buffer, "$fake_path\n")
@test_throws ArgumentError interactive(TravisCI) @test_throws ArgumentError interactive(TravisCI)
println() println()
end end
@testset "AppVeyor" begin @testset "AppVeyor" begin
write(STDIN.buffer, "\n") write(stdin.buffer, "\n")
p = interactive(AppVeyor) p = interactive(AppVeyor)
@test get(p.src, "") == joinpath(DEFAULTS_DIR, "appveyor.yml") @test p.src == joinpath(DEFAULTS_DIR, "appveyor.yml")
write(STDIN.buffer, "$test_file\n") write(stdin.buffer, "$test_file\n")
p = interactive(AppVeyor) p = interactive(AppVeyor)
@test get(p.src, "") == test_file @test p.src == test_file
write(STDIN.buffer, "none\n") write(stdin.buffer, "none\n")
p = interactive(AppVeyor) p = interactive(AppVeyor)
@test isnull(p.src) @test p.src === nothing
write(STDIN.buffer, "$fake_path\n") write(stdin.buffer, "$fake_path\n")
@test_throws ArgumentError interactive(AppVeyor) @test_throws ArgumentError interactive(AppVeyor)
println() println()
end end
@testset "GitLabCI" begin @testset "GitLabCI" begin
write(STDIN.buffer, "\n\n") write(stdin.buffer, "\n\n")
p = interactive(GitLabCI) p = interactive(GitLabCI)
@test get(p.src, "") == joinpath(DEFAULTS_DIR, "gitlab-ci.yml") @test p.src == joinpath(DEFAULTS_DIR, "gitlab-ci.yml")
@test p.view == Dict("GITLABCOVERAGE" => true) @test p.view == Dict("GITLABCOVERAGE" => true)
write(STDIN.buffer, "$test_file\nno\n") write(stdin.buffer, "$test_file\nno\n")
p = interactive(GitLabCI) p = interactive(GitLabCI)
@test get(p.src, "") == test_file @test p.src == test_file
@test p.view == Dict("GITLABCOVERAGE" => false) @test p.view == Dict("GITLABCOVERAGE" => false)
write(STDIN.buffer, "none\n\n") write(stdin.buffer, "none\n\n")
p = interactive(GitLabCI) p = interactive(GitLabCI)
@test isnull(p.src) @test p.src === nothing
write(STDIN.buffer, "$fake_path\n\n") write(stdin.buffer, "$fake_path\n\n")
@test_throws ArgumentError interactive(GitLabCI) @test_throws ArgumentError interactive(GitLabCI)
println() println()
end end
@testset "CodeCov" begin @testset "CodeCov" begin
write(STDIN.buffer, "\n") write(stdin.buffer, "\n")
p = interactive(CodeCov) p = interactive(CodeCov)
@test isnull(p.src) @test p.src === nothing
write(STDIN.buffer, "$test_file\n") write(stdin.buffer, "$test_file\n")
p = interactive(CodeCov) p = interactive(CodeCov)
@test get(p.src, "") == test_file @test p.src == test_file
write(STDIN.buffer, "none\n") write(stdin.buffer, "none\n")
p = interactive(CodeCov) p = interactive(CodeCov)
@test isnull(p.src) @test p.src === nothing
write(STDIN.buffer, "$fake_path\n") write(stdin.buffer, "$fake_path\n")
@test_throws ArgumentError interactive(CodeCov) @test_throws ArgumentError interactive(CodeCov)
println() println()
end end
@testset "Coveralls" begin @testset "Coveralls" begin
write(STDIN.buffer, "\n") write(stdin.buffer, "\n")
p = interactive(Coveralls) p = interactive(Coveralls)
@test isnull(p.src) @test p.src === nothing
write(STDIN.buffer, "$test_file\n") write(stdin.buffer, "$test_file\n")
p = interactive(Coveralls) p = interactive(Coveralls)
@test get(p.src, "") == test_file @test p.src == test_file
write(STDIN.buffer, "none\n") write(stdin.buffer, "none\n")
p = interactive(Coveralls) p = interactive(Coveralls)
@test isnull(p.src) @test p.src === nothing
write(STDIN.buffer, "$fake_path\n") write(stdin.buffer, "$fake_path\n")
@test_throws ArgumentError interactive(Coveralls) @test_throws ArgumentError interactive(Coveralls)
println() println()
end end
@testset "GitHubPages" begin @testset "GitHubPages" begin
write(STDIN.buffer, "\n") write(stdin.buffer, "\n")
p = interactive(GitHubPages) p = interactive(GitHubPages)
@test isempty(p.assets) @test isempty(p.assets)
write(STDIN.buffer, "$test_file\n") write(stdin.buffer, "$test_file\n")
p = interactive(GitHubPages) p = interactive(GitHubPages)
@test p.assets == [test_file] @test p.assets == [test_file]
write(STDIN.buffer, "$fake_path\n") write(stdin.buffer, "$fake_path\n")
@test_throws ArgumentError interactive(GitHubPages) @test_throws ArgumentError interactive(GitHubPages)
println() println()
end end

View File

@ -7,7 +7,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@testset "Plugin creation" begin @testset "Plugin creation" begin
p = AppVeyor() p = AppVeyor()
@test isempty(p.gitignore) @test isempty(p.gitignore)
@test get(p.src, "") == joinpath(PkgTemplates.DEFAULTS_DIR, "appveyor.yml") @test p.src == joinpath(PkgTemplates.DEFAULTS_DIR, "appveyor.yml")
@test p.dest == ".appveyor.yml" @test p.dest == ".appveyor.yml"
@test p.badges == [ @test p.badges == [
Badge( Badge(
@ -18,9 +18,9 @@ pkg_dir = joinpath(temp_dir, test_pkg)
] ]
@test isempty(p.view) @test isempty(p.view)
p = AppVeyor(; config_file=nothing) p = AppVeyor(; config_file=nothing)
@test isnull(p.src) @test p.src === nothing
p = AppVeyor(; config_file=test_file) p = AppVeyor(; config_file=test_file)
@test get(p.src, "") == test_file @test p.src == test_file
@test_throws ArgumentError AppVeyor(; config_file=fake_path) @test_throws ArgumentError AppVeyor(; config_file=fake_path)
end end

View File

@ -7,7 +7,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@testset "Plugin creation" begin @testset "Plugin creation" begin
p = CodeCov() p = CodeCov()
@test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] @test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"]
@test isnull(p.src) @test p.src === nothing
@test p.dest == ".codecov.yml" @test p.dest == ".codecov.yml"
@test p.badges == [ @test p.badges == [
Badge( Badge(
@ -18,9 +18,9 @@ pkg_dir = joinpath(temp_dir, test_pkg)
] ]
@test isempty(p.view) @test isempty(p.view)
p = CodeCov(; config_file=nothing) p = CodeCov(; config_file=nothing)
@test isnull(p.src) @test p.src === nothing
p = CodeCov(; config_file=test_file) p = CodeCov(; config_file=test_file)
@test get(p.src, "") == test_file @test p.src == test_file
@test_throws ArgumentError CodeCov(; config_file=fake_path) @test_throws ArgumentError CodeCov(; config_file=fake_path)
end end

View File

@ -7,7 +7,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@testset "Plugin creation" begin @testset "Plugin creation" begin
p = Coveralls() p = Coveralls()
@test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] @test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"]
@test isnull(p.src) @test p.src === nothing
@test p.dest == ".coveralls.yml" @test p.dest == ".coveralls.yml"
@test p.badges == [ @test p.badges == [
Badge( Badge(
@ -18,9 +18,9 @@ pkg_dir = joinpath(temp_dir, test_pkg)
] ]
@test isempty(p.view) @test isempty(p.view)
p = Coveralls(; config_file=nothing) p = Coveralls(; config_file=nothing)
@test isnull(p.src) @test p.src === nothing
p = Coveralls(; config_file=test_file) p = Coveralls(; config_file=test_file)
@test get(p.src, "") == test_file @test p.src == test_file
@test_throws ArgumentError Coveralls(; config_file=fake_path) @test_throws ArgumentError Coveralls(; config_file=fake_path)
end end

View File

@ -7,7 +7,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@testset "Plugin creation" begin @testset "Plugin creation" begin
p = GitLabCI() p = GitLabCI()
@test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] @test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"]
@test get(p.src, "") == joinpath(PkgTemplates.DEFAULTS_DIR, "gitlab-ci.yml") @test p.src == joinpath(PkgTemplates.DEFAULTS_DIR, "gitlab-ci.yml")
@test p.dest == ".gitlab-ci.yml" @test p.dest == ".gitlab-ci.yml"
@test p.badges == [ @test p.badges == [
Badge( Badge(
@ -23,9 +23,9 @@ pkg_dir = joinpath(temp_dir, test_pkg)
] ]
@test p.view == Dict("GITLABCOVERAGE" => true) @test p.view == Dict("GITLABCOVERAGE" => true)
p = GitLabCI(; config_file=nothing) p = GitLabCI(; config_file=nothing)
@test isnull(p.src) @test p.src === nothing
p = GitLabCI(; config_file=test_file) p = GitLabCI(; config_file=test_file)
@test get(p.src, "") == test_file @test p.src == test_file
@test_throws ArgumentError GitLabCI(; config_file=fake_path) @test_throws ArgumentError GitLabCI(; config_file=fake_path)
p = GitLabCI(; coverage=false) p = GitLabCI(; coverage=false)
@test p.badges == [ @test p.badges == [

View File

@ -7,7 +7,7 @@ pkg_dir = joinpath(temp_dir, test_pkg)
@testset "Plugin creation" begin @testset "Plugin creation" begin
p = TravisCI() p = TravisCI()
@test isempty(p.gitignore) @test isempty(p.gitignore)
@test get(p.src, "") == joinpath(PkgTemplates.DEFAULTS_DIR, "travis.yml") @test p.src == joinpath(PkgTemplates.DEFAULTS_DIR, "travis.yml")
@test p.dest == ".travis.yml" @test p.dest == ".travis.yml"
@test p.badges == [ @test p.badges == [
Badge( Badge(
@ -18,9 +18,9 @@ pkg_dir = joinpath(temp_dir, test_pkg)
] ]
@test isempty(p.view) @test isempty(p.view)
p = TravisCI(; config_file=nothing) p = TravisCI(; config_file=nothing)
@test isnull(p.src) @test p.src === nothing
p = TravisCI(; config_file=test_file) p = TravisCI(; config_file=test_file)
@test get(p.src, "") == test_file @test p.src == test_file
@test_throws ArgumentError TravisCI(; config_file=fake_path) @test_throws ArgumentError TravisCI(; config_file=fake_path)
end end

View File

@ -1,5 +1,7 @@
using PkgTemplates using PkgTemplates
using Base.Test using Test
using Dates
using LibGit2
import PkgTemplates: badges, version_floor, substitute, read_license, gen_file, gen_readme, import PkgTemplates: badges, version_floor, substitute, read_license, gen_file, gen_readme,
gen_tests, gen_license, gen_require, gen_entrypoint, gen_gitignore, gen_plugin, gen_tests, gen_license, gen_require, gen_entrypoint, gen_gitignore, gen_plugin,
@ -7,17 +9,11 @@ import PkgTemplates: badges, version_floor, substitute, read_license, gen_file,
format, interactive, DEFAULTS_DIR format, interactive, DEFAULTS_DIR
mktempdir() do temp_dir mktempdir() do temp_dir
withenv("JULIA_PKGDIR" => temp_dir) do mkdir(joinpath(temp_dir, "dev"))
# We technically don't need to clone METADATA to run tests. pushfirst!(DEPOT_PATH, temp_dir)
if get(ENV, "PKGTEMPLATES_TEST_FAST", "false") == "true"
mkdir(joinpath(temp_dir, "v$(version_floor())"))
else
Pkg.init()
end
cd(temp_dir) do cd(temp_dir) do
@testset "PkgTemplates.jl" begin @testset "PkgTemplates.jl" begin
include("tests.jl") include("tests.jl")
end end
end end
end end
end

View File

@ -1,6 +1,6 @@
struct Foo <: GenericPlugin struct Foo <: GenericPlugin
gitignore::Vector{AbstractString} gitignore::Vector{AbstractString}
src::Nullable{AbstractString} src::Union{AbstractString, Nothing}
dest::AbstractString dest::AbstractString
badges::Vector{Badge} badges::Vector{Badge}
view::Dict{String, Any} view::Dict{String, Any}
@ -18,8 +18,9 @@ const gitconfig = Dict(
"github.user" => "TesterMcTestFace", "github.user" => "TesterMcTestFace",
) )
const test_pkg = "TestPkg" const test_pkg = "TestPkg"
const fake_path = bin(hash("/this/file/does/not/exist")) const fake_path = string(hash("/this/file/does/not/exist"); base=2)
const test_file = tempname() const test_file = tempname()
const default_dir = PkgTemplates.dev_dir()
const template_text = """ const template_text = """
PKGNAME: {{PKGNAME}} PKGNAME: {{PKGNAME}}
VERSION: {{VERSION}}} VERSION: {{VERSION}}}
@ -37,7 +38,7 @@ write(test_file, template_text)
@test t.license == "MIT" @test t.license == "MIT"
@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", "")
@test t.dir == Pkg.dir() @test t.dir == default_dir
@test t.julia_version == VERSION @test t.julia_version == VERSION
@test isempty(t.gitconfig) @test isempty(t.gitconfig)
@test isempty(t.plugins) @test isempty(t.plugins)
@ -61,7 +62,7 @@ write(test_file, template_text)
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 is_unix() # ~ means temporary file on Windows, not $HOME. if Sys.isunix() # ~ means temporary file on Windows, not $HOME.
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
@ -74,7 +75,7 @@ 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"]
@test_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]
@test_throws ArgumentError Template(; @test_throws ArgumentError Template(;
user=me, user=me,
@ -102,7 +103,7 @@ write(test_file, template_text)
[GitHubPages(), TravisCI(), AppVeyor(), CodeCov(), Coveralls()] [GitHubPages(), TravisCI(), AppVeyor(), CodeCov(), Coveralls()]
) )
@test_warn r".+" t = Template(; @test_logs (:warn, r".+") t = Template(;
user=me, user=me,
plugins=[TravisCI(), TravisCI()], plugins=[TravisCI(), TravisCI()],
) )
@ -126,7 +127,7 @@ else
end end
@testset "Show methods" begin @testset "Show methods" begin
pkgdir = replace(joinpath(ENV["JULIA_PKGDIR"], "v$(version_floor())"), homedir(), "~") pkg_dir = replace(default_dir, homedir() => "~")
buf = IOBuffer() buf = IOBuffer()
t = Template(; user=me, gitconfig=gitconfig) t = Template(; user=me, gitconfig=gitconfig)
show(buf, t) show(buf, t)
@ -136,7 +137,7 @@ end
User: $me User: $me
Host: github.com Host: github.com
License: MIT ($(gitconfig["user.name"]) $(Dates.year(now()))) License: MIT ($(gitconfig["user.name"]) $(Dates.year(now())))
Package directory: $pkgdir Package directory: $pkg_dir
Precompilation enabled: Yes Precompilation enabled: Yes
Minimum Julia version: v$(PkgTemplates.version_floor()) Minimum Julia version: v$(PkgTemplates.version_floor())
0 package requirements 0 package requirements
@ -165,7 +166,7 @@ end
User: $me User: $me
Host: github.com Host: github.com
License: None License: None
Package directory: $pkgdir Package directory: $pkg_dir
Precompilation enabled: Yes Precompilation enabled: Yes
Minimum Julia version: v$(PkgTemplates.version_floor()) Minimum Julia version: v$(PkgTemplates.version_floor())
2 package requirements: Bar, Foo 2 package requirements: Bar, Foo
@ -201,7 +202,7 @@ end
temp_file = tempname() temp_file = tempname()
gen_file(temp_file, "Hello, world") gen_file(temp_file, "Hello, world")
@test isfile(temp_file) @test isfile(temp_file)
@test readstring(temp_file) == "Hello, world\n" @test read(temp_file, String) == "Hello, world\n"
rm(temp_file) rm(temp_file)
@test gen_readme(temp_dir, test_pkg, t) == ["README.md"] @test gen_readme(temp_dir, test_pkg, t) == ["README.md"]
@ -227,7 +228,7 @@ end
@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 = readstring(joinpath(pkg_dir, ".gitignore")) gitignore = read(joinpath(pkg_dir, ".gitignore"), String)
rm(joinpath(pkg_dir, ".gitignore")) rm(joinpath(pkg_dir, ".gitignore"))
@test contains(gitignore, ".DS_Store") @test contains(gitignore, ".DS_Store")
for p in values(t.plugins) for p in values(t.plugins)
@ -278,15 +279,17 @@ end
@testset "Package generation" begin @testset "Package generation" begin
t = Template(; user=me, gitconfig=gitconfig) t = Template(; user=me, gitconfig=gitconfig)
generate(test_pkg, t) generate(test_pkg, t)
@test isfile(Pkg.dir(test_pkg, "LICENSE")) pkg_dir = joinpath(default_dir, test_pkg)
@test isfile(Pkg.dir(test_pkg, "README.md"))
@test isfile(Pkg.dir(test_pkg, "REQUIRE")) @test isfile(joinpath(pkg_dir, "LICENSE"))
@test isfile(Pkg.dir(test_pkg, ".gitignore")) @test isfile(joinpath(pkg_dir, "README.md"))
@test isdir(Pkg.dir(test_pkg, "src")) @test isfile(joinpath(pkg_dir, "REQUIRE"))
@test isfile(Pkg.dir(test_pkg, "src", "$test_pkg.jl")) @test isfile(joinpath(pkg_dir, ".gitignore"))
@test isdir(Pkg.dir(test_pkg, "test")) @test isdir(joinpath(pkg_dir, "src"))
@test isfile(Pkg.dir(test_pkg, "test", "runtests.jl")) @test isfile(joinpath(pkg_dir, "src", "$test_pkg.jl"))
repo = LibGit2.GitRepo(Pkg.dir(test_pkg)) @test isdir(joinpath(pkg_dir, "test"))
@test isfile(joinpath(pkg_dir, "test", "runtests.jl"))
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"]
@ -296,20 +299,20 @@ end
@test in("master", branches) @test in("master", branches)
@test !in("gh-pages", branches) @test !in("gh-pages", branches)
@test !LibGit2.isdirty(repo) @test !LibGit2.isdirty(repo)
rm(Pkg.dir(test_pkg); recursive=true) rm(pkg_dir; recursive=true)
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(test_pkg)) 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(test_pkg); recursive=true) rm(pkg_dir; recursive=true)
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(test_pkg)) repo = LibGit2.GitRepo(pkg_dir)
remote = LibGit2.get(LibGit2.GitRemote, repo, "origin") remote = LibGit2.get(LibGit2.GitRemote, repo, "origin")
@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(test_pkg); recursive=true) rm(pkg_dir; recursive=true)
temp_dir = mktempdir() temp_dir = mktempdir()
t = Template(; user=me, dir=temp_dir, gitconfig=gitconfig) t = Template(; user=me, dir=temp_dir, gitconfig=gitconfig)
@ -324,45 +327,45 @@ end
plugins=[AppVeyor(), GitHubPages(), Coveralls(), CodeCov(), TravisCI()], plugins=[AppVeyor(), GitHubPages(), Coveralls(), CodeCov(), TravisCI()],
) )
generate(test_pkg, t) generate(test_pkg, t)
@test isdir(joinpath(Pkg.dir(), test_pkg)) @test isdir(pkg_dir)
@test !isfile(Pkg.dir(test_pkg, "LICENSE")) @test !isfile(joinpath(pkg_dir, "LICENSE"))
@test isfile(Pkg.dir(test_pkg, ".travis.yml")) @test isfile(joinpath(pkg_dir, ".travis.yml"))
@test isfile(Pkg.dir(test_pkg, ".appveyor.yml")) @test isfile(joinpath(pkg_dir, ".appveyor.yml"))
@test isdir(Pkg.dir(test_pkg, "docs")) @test isdir(joinpath(pkg_dir, "docs"))
@test isfile(Pkg.dir(test_pkg, "docs", "make.jl")) @test isfile(joinpath(pkg_dir, "docs", "make.jl"))
@test isdir(Pkg.dir(test_pkg, "docs", "src")) @test isdir(joinpath(pkg_dir, "docs", "src"))
@test isfile(Pkg.dir(test_pkg, "docs", "src", "index.md")) @test isfile(joinpath(pkg_dir, "docs", "src", "index.md"))
repo = LibGit2.GitRepo(Pkg.dir(test_pkg)) 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))
@test in("gh-pages", branches) @test in("gh-pages", branches)
@test !LibGit2.isdirty(repo) @test !LibGit2.isdirty(repo)
rm(Pkg.dir(test_pkg); recursive=true) rm(pkg_dir; recursive=true)
mkdir(Pkg.dir(test_pkg)) 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(Pkg.dir(test_pkg, "README.md")) @test isfile(joinpath(pkg_dir, "README.md"))
rm(Pkg.dir(test_pkg); recursive=true) rm(pkg_dir; recursive=true)
temp_file, fd = mktemp() temp_file, io = mktemp()
close(fd) close(io)
temp_dir = mktempdir() temp_dir = mktempdir()
t = Template(; user=me, dir=temp_file, gitconfig=gitconfig) t = Template(; user=me, dir=temp_file)
@test_warn r".+" generate(test_pkg, t; backup_dir=temp_dir) @test_logs (:warn, r".+") match_mode=:any generate(test_pkg, t; backup_dir=temp_dir)
rm(temp_dir; recursive=true) rm(temp_dir; recursive=true)
temp_dir = mktempdir() temp_dir = mktempdir()
t = Template(; user=me, dir=joinpath(temp_file, "file"), gitconfig=gitconfig) t = Template(; user=me, dir=joinpath(temp_file, "dir"))
@test_warn r".+" generate(test_pkg, t; backup_dir=temp_dir) @test_logs (:warn, r".+") match_mode=:any generate(test_pkg, t; backup_dir=temp_dir)
rm(temp_dir; recursive=true) rm(temp_dir; recursive=true)
rm(temp_file) rm(temp_file)
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 = readstring(Pkg.dir(test_pkg, "README.md")) readme = read(joinpath(pkg_dir, "README.md"), String)
index = readstring(Pkg.dir(test_pkg, "docs", "src", "index.md")) index = read(joinpath(pkg_dir, "docs", "src", "index.md"), String)
@test readme == index @test readme == index
rm(Pkg.dir(test_pkg); recursive=true) rm(pkg_dir; recursive=true)
end end
@testset "Version floor" begin @testset "Version floor" begin
@ -435,7 +438,7 @@ end
@test contains(licenses, "$short: $long") @test contains(licenses, "$short: $long")
end end
@test strip(mit) == strip(read_license("MIT")) @test strip(mit) == strip(read_license("MIT"))
@test strip(read_license("MIT")) == strip(readstring(joinpath(LICENSE_DIR, "MIT"))) @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)
for license in readdir(LICENSE_DIR) for license in readdir(LICENSE_DIR)