PkgTemplates.jl/test/runtests.jl

63 lines
1.8 KiB
Julia
Raw Normal View History

2019-09-02 14:20:33 +00:00
using Base.Filesystem: contractuser, path_separator
using LibGit2: LibGit2, GitCommit, GitRemote, GitRepo
2019-08-31 10:33:33 +00:00
using Pkg: Pkg
using Random: Random
using Test: @test, @testset, @test_throws
using ReferenceTests: @test_reference
2019-09-26 06:22:20 +00:00
using SimpleMock: mock
using Suppressor: @suppress
2019-08-31 10:33:33 +00:00
using PkgTemplates
const PT = PkgTemplates
const USER = "tester"
Random.seed!(1)
# Creata a template that won't error because of a missing username.
2019-08-31 10:33:33 +00:00
tpl(; kwargs...) = Template(; user=USER, kwargs...)
const PKG = Ref("A")
# Generate an unused package name.
pkgname() = PKG[] *= "a"
# Create a randomly named package with a template, and delete it afterwards.
function with_pkg(f::Function, t::Template, pkg::AbstractString=pkgname())
@suppress t(pkg)
2019-09-01 01:36:33 +00:00
try
f(pkg)
finally
2019-09-26 06:22:20 +00:00
# On 1.4, this sometimes won't work, but the error is that the package isn't installed.
# We're going to delete the package directory anyways, so just ignore any errors.
PT.version_of(pkg) === nothing || try @suppress Pkg.rm(pkg) catch; end
2019-09-01 01:36:33 +00:00
rm(joinpath(t.dir, pkg); recursive=true, force=true)
end
end
mktempdir() do dir
Pkg.activate(dir)
pushfirst!(DEPOT_PATH, dir)
try
@testset "PkgTemplates.jl" begin
2019-08-31 10:33:33 +00:00
include("template.jl")
2019-09-01 01:36:33 +00:00
include("plugin.jl")
include("git.jl")
2019-09-02 14:20:33 +00:00
include("show.jl")
2019-08-31 11:45:41 +00:00
# Quite a bit of output depends on the Julia version,
# and the test fixtures are made with Julia 1.2.
# TODO: Keep this on the latest stable Julia version.
if VERSION.major == 1 && VERSION.minor == 2
include("reference.jl")
2019-08-31 11:45:41 +00:00
else
@info "Skipping reference tests" julia=VERSION
2019-08-31 11:45:41 +00:00
end
2019-08-31 10:33:33 +00:00
end
finally
popfirst!(DEPOT_PATH)
2019-08-31 10:33:33 +00:00
end
end