forked from JuliaCI/PkgTemplates.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
182 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
@context PTIsInstalled | ||
function Cassette.posthook(::PTIsInstalled, result::Dict, ::typeof(Pkg.installed)) | ||
result["PkgTemplates"] = v"1.2.3" | ||
return result | ||
end | ||
|
||
@testset "Git repositories" begin | ||
@testset "Does not create Git repo" begin | ||
t = tpl(; git=false) | ||
with_pkg(t) do pkg | ||
pkg_dir = joinpath(t.dir, pkg) | ||
@test !isdir(joinpath(pkg_dir, ".git")) | ||
end | ||
end | ||
|
||
@testset "Creates Git repo" begin | ||
t = tpl(; git=true) | ||
with_pkg(t) do pkg | ||
pkg_dir = joinpath(t.dir, pkg) | ||
@test isdir(joinpath(pkg_dir, ".git")) | ||
end | ||
end | ||
|
||
@testset "With HTTPS" begin | ||
t = tpl(; git=true, ssh=false) | ||
with_pkg(t) do pkg | ||
LibGit2.with(GitRepo(joinpath(t.dir, pkg))) do repo | ||
remote = LibGit2.get(GitRemote, repo, "origin") | ||
@test startswith(LibGit2.url(remote), "https://") | ||
end | ||
end | ||
end | ||
|
||
@testset "With SSH" begin | ||
t = tpl(; git=true, ssh=true) | ||
with_pkg(t) do pkg | ||
LibGit2.with(GitRepo(joinpath(t.dir, pkg))) do repo | ||
remote = LibGit2.get(GitRemote, repo, "origin") | ||
@test startswith(LibGit2.url(remote), "git@") | ||
end | ||
end | ||
end | ||
|
||
@testset "Adds version to commit message" begin | ||
# We're careful to avoid a Pkg.update as it triggers Cassette#130. | ||
t = tpl(; git=true, develop=false, disable_defaults=[Tests]) | ||
@overdub PTIsInstalled() with_pkg(t) do pkg | ||
pkg_dir = joinpath(t.dir, pkg) | ||
LibGit2.with(GitRepo(pkg_dir)) do repo | ||
commit = GitCommit(repo, "HEAD") | ||
@test occursin("PkgTemplates version: 1.2.3", LibGit2.message(commit)) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,59 @@ | ||
using Base.Filesystem: path_separator | ||
|
||
using LibGit2: LibGit2, GitCommit, GitRemote, GitRepo | ||
using Pkg: Pkg | ||
using Random: Random | ||
using Test: @test, @testset, @test_throws | ||
|
||
using Cassette: Cassette, @context, @overdub | ||
using ReferenceTests: @test_reference | ||
using Suppressor: @suppress | ||
|
||
using PkgTemplates | ||
const PT = PkgTemplates | ||
|
||
const PKG = "TestPkg" | ||
const USER = "tester" | ||
|
||
Random.seed!(1) | ||
|
||
# Creata a template that won't error because of a missing username. | ||
tpl(; kwargs...) = Template(; user=USER, kwargs...) | ||
|
||
function with_pkg(f::Function, t::Template, pkg::AbstractString=PKG) | ||
t(pkg) | ||
const pkg_name = Ref("A") | ||
|
||
# Generate an unused package name. | ||
pkgname() = pkg_name[] *= "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) | ||
try | ||
f(pkg) | ||
finally | ||
haskey(Pkg.installed(), pkg) && Pkg.rm(pkg) | ||
haskey(Pkg.installed(), pkg) && @suppress Pkg.rm(pkg) | ||
rm(joinpath(t.dir, pkg); recursive=true, force=true) | ||
end | ||
end | ||
|
||
@testset "PkgTemplates.jl" begin | ||
mktempdir() do dir | ||
Pkg.activate(dir) | ||
pushfirst!(DEPOT_PATH, dir) | ||
try | ||
mktempdir() do dir | ||
Pkg.activate(dir) | ||
pushfirst!(DEPOT_PATH, dir) | ||
try | ||
@testset "PkgTemplates.jl" begin | ||
include("template.jl") | ||
include("plugin.jl") | ||
include("git.jl") | ||
|
||
# Quite a bit of output depends on the Julia version, and the test fixtures are | ||
# made with Julia 1.2. Also, Windows uses CRLF which breaks everything. | ||
if !Sys.iswindows() && VERSION.major == 1 && VERSION.minor == 2 | ||
# 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") | ||
else | ||
@info "Skipping reference tests" julia=VERSION | ||
end | ||
finally | ||
popfirst!(DEPOT_PATH) | ||
end | ||
finally | ||
popfirst!(DEPOT_PATH) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,77 @@ | ||
@testset "Template constructor" begin | ||
@testset "user" begin | ||
if isempty(PT.default_user()) | ||
@test_throws ArgumentError Template() | ||
haskey(ENV, "CI") && run(`git config --global github.user $USER`) | ||
@testset "Template" begin | ||
@testset "Template constructor" begin | ||
@testset "user" begin | ||
if isempty(PT.default_user()) | ||
@test_throws ArgumentError Template() | ||
haskey(ENV, "CI") && run(`git config --global github.user $USER`) | ||
end | ||
@test Template().user == PT.default_user() | ||
end | ||
@test Template().user == PT.default_user() | ||
end | ||
|
||
@testset "authors" begin | ||
@test tpl(; authors=["a"]).authors == ["a"] | ||
@test tpl(; authors="a").authors == ["a"] | ||
@test tpl(; authors="a,b").authors == ["a", "b"] | ||
@test tpl(; authors="a, b").authors == ["a", "b"] | ||
end | ||
@testset "authors" begin | ||
@test tpl(; authors=["a"]).authors == ["a"] | ||
@test tpl(; authors="a").authors == ["a"] | ||
@test tpl(; authors="a,b").authors == ["a", "b"] | ||
@test tpl(; authors="a, b").authors == ["a", "b"] | ||
end | ||
|
||
@testset "host" begin | ||
@test tpl(; host="https://foo.com").host == "foo.com" | ||
end | ||
@testset "host" begin | ||
@test tpl(; host="https://foo.com").host == "foo.com" | ||
end | ||
|
||
@testset "dir" begin | ||
@test tpl(; dir="/foo/bar").dir == joinpath(path_separator, "foo", "bar") | ||
@test tpl(; dir="foo").dir == abspath("foo") | ||
@test tpl(; dir="~/foo").dir == abspath(expanduser("~/foo")) | ||
end | ||
@testset "dir" begin | ||
@test tpl(; dir="/foo/bar").dir == joinpath(path_separator, "foo", "bar") | ||
@test tpl(; dir="foo").dir == abspath("foo") | ||
@test tpl(; dir="~/foo").dir == abspath(expanduser("~/foo")) | ||
end | ||
|
||
@testset "plugins / disabled_defaults" begin | ||
function test_plugins(plugins, expected, disabled=DataType[]) | ||
t = tpl(; plugins=plugins, disable_defaults=disabled) | ||
@test issetequal(values(t.plugins), expected) | ||
end | ||
|
||
@testset "plugins / disabled_defaults" begin | ||
function test_plugins(plugins, expected, disabled=DataType[]) | ||
t = tpl(; plugins=plugins, disable_defaults=disabled) | ||
@test issetequal(values(t.plugins), expected) | ||
defaults = PT.default_plugins() | ||
test_plugins([], defaults) | ||
test_plugins([Citation()], union(defaults, [Citation()])) | ||
# Overriding a default plugin. | ||
gi = Gitignore(; dev=false) | ||
test_plugins([gi], union(setdiff(defaults, [Gitignore()]), [gi])) | ||
# Disabling a default plugin. | ||
test_plugins([], setdiff(defaults, [Gitignore()]), [Gitignore]) | ||
end | ||
end | ||
|
||
defaults = PT.default_plugins() | ||
test_plugins([], defaults) | ||
test_plugins([Citation()], union(defaults, [Citation()])) | ||
# Overriding a default plugin. | ||
gi = Gitignore(; dev=false) | ||
test_plugins([gi], union(setdiff(defaults, [Gitignore()]), [gi])) | ||
# Disabling a default plugin. | ||
test_plugins([], setdiff(defaults, [Gitignore()]), [Gitignore]) | ||
@testset "hasplugin" begin | ||
t = tpl(; plugins=[Documenter{TravisCI}()]) | ||
@test PT.hasplugin(t, typeof(first(PT.default_plugins()))) | ||
@test PT.hasplugin(t, Documenter) | ||
@test PT.hasplugin(t, _ -> true) | ||
@test !PT.hasplugin(t, _ -> false) | ||
@test !PT.hasplugin(t, Citation) | ||
@test !PT.hasplugin(t, PT.is_ci) | ||
end | ||
end | ||
|
||
@testset "hasplugin" begin | ||
t = tpl(; plugins=[Documenter{TravisCI}()]) | ||
@test PT.hasplugin(t, typeof(first(PT.default_plugins()))) | ||
@test PT.hasplugin(t, Documenter) | ||
@test PT.hasplugin(t, _ -> true) | ||
@test !PT.hasplugin(t, _ -> false) | ||
@test !PT.hasplugin(t, Citation) | ||
@test !PT.hasplugin(t, PT.is_ci) | ||
@context ErrorOnRepoInit | ||
function Cassette.prehook(::ErrorOnRepoInit, ::typeof(LibGit2.init), pkg_dir) | ||
@test isdir(pkg_dir) | ||
error() | ||
end | ||
|
||
@testset "Package generation errors" begin | ||
mktempdir() do dir | ||
t = tpl(; dir=dirname(dir)) | ||
@test_throws ArgumentError t(basename(dir)) | ||
end | ||
|
||
mktemp() do f, _io | ||
t = tpl(; dir=dirname(f)) | ||
@test_throws ArgumentError t(basename(f)) | ||
end | ||
|
||
t = tpl() | ||
pkg = pkgname() | ||
@test_throws ErrorException @overdub ErrorOnRepoInit() @suppress t(pkg) | ||
@test !isdir(joinpath(t.dir, pkg)) | ||
end |