A few more tests

This commit is contained in:
Chris de Graaf 2019-09-01 08:36:33 +07:00
parent e4f97431b5
commit b70d3c9cf8
No known key found for this signature in database
GPG Key ID: 150FFDD9B0073C7B
6 changed files with 59 additions and 24 deletions

View File

@ -1,5 +1,16 @@
const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults"))
badge_order() = [
Documenter{GitLabCI},
Documenter{TravisCI},
GitLabCI,
TravisCI,
AppVeyor,
CirrusCI,
Codecov,
Coveralls,
]
"""
A simple plugin that, in general, manages a single file.
For example, most CI services reply on one configuration file.
@ -151,14 +162,3 @@ include(joinpath("plugins", "coverage.jl"))
include(joinpath("plugins", "ci.jl"))
include(joinpath("plugins", "citation.jl"))
include(joinpath("plugins", "documenter.jl"))
const BADGE_ORDER = [
Documenter{GitLabCI},
Documenter{TravisCI},
TravisCI,
AppVeyor,
GitLabCI,
CirrusCI,
Codecov,
Coveralls,
]

View File

@ -27,7 +27,7 @@ function view(p::Readme, t::Template, pkg::AbstractString)
# Explicitly ordered badges go first.
strings = String[]
done = DataType[]
foreach(BADGE_ORDER) do T
foreach(badge_order()) do T
if hasplugin(t, T)
bs = badges(t.plugins[T], t, pkg)
append!(strings, badges(t.plugins[T], t, pkg))

View File

@ -1,9 +1,9 @@
# AllPlugins
[![Build Status](https://travis-ci.com/tester/AllPlugins.jl.svg?branch=master)](https://travis-ci.com/tester/AllPlugins.jl)
[![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/AllPlugins.jl?svg=true)](https://ci.appveyor.com/project/tester/AllPlugins-jl)
[![Build Status](https://gitlab.com/tester/AllPlugins.jl/badges/master/build.svg)](https://gitlab.com/tester/AllPlugins.jl/pipelines)
[![Coverage](https://gitlab.com/tester/AllPlugins.jl/badges/master/coverage.svg)](https://gitlab.com/tester/AllPlugins.jl/commits/master)
[![Build Status](https://travis-ci.com/tester/AllPlugins.jl.svg?branch=master)](https://travis-ci.com/tester/AllPlugins.jl)
[![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/AllPlugins.jl?svg=true)](https://ci.appveyor.com/project/tester/AllPlugins-jl)
[![Build Status](https://api.cirrus-ci.com/github/tester/.jl.svg)](https://cirrus-ci.com/github/tester/AllPlugins.jl)
[![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl)
[![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master)

26
test/plugin.jl Normal file
View File

@ -0,0 +1,26 @@
# Don't move this line from the top, please. {{X}} {{Y}} {{Z}}
struct BasicTest <: PT.BasicPlugin end
PT.gitignore(::BasicTest) = ["a", "aa", "aaa"]
PT.source(::BasicTest) = @__FILE__
PT.destination(::BasicTest) = "foo.txt"
PT.badges(::BasicTest) = PT.Badge("{{X}}", "{{Y}}", "{{Z}}")
PT.view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 0, "Y" => 2)
PT.user_view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 1, "Z" => 3)
@testset "BasicPlugin" begin
p = BasicTest()
t = tpl(; plugins=[p])
# The X from user_view should override the X from view.
s = PT.render_plugin(p, t, "")
@test occursin("1 2 3", first(split(s, "\n")))
with_pkg(t) do pkg
pkg_dir = joinpath(t.dir, pkg)
badge = string(PT.Badge("1", "2", "3"))
@test occursin(badge, read(joinpath(pkg_dir, "README.md"), String))
@test read(joinpath(pkg_dir, "foo.txt"), String) == s
end
end

View File

@ -6,26 +6,23 @@ end
function test_all(pkg::AbstractString; kwargs...)
t = tpl(; kwargs...)
with_pkg(t, pkg) do pkg
pkg_dir = joinpath(t.dir, pkg)
t(pkg)
try
foreach(readlines(`git -C $pkg_dir ls-files`)) do f
# All fixture files are .txt so that ReferenceTests can handle them.
reference = joinpath(@__DIR__, "fixtures", pkg, f * ".txt")
observed = read(joinpath(pkg_dir, f), String)
@test_reference reference observed
end
finally
rm(pkg_dir; recursive=true, force=true)
end
end
@testset "Default package" begin
test_all("Basic"; authors=USER, develop=false, manifest=true)
test_all("Basic"; authors=USER, manifest=true)
end
@testset "All plugins" begin
test_all("AllPlugins"; authors=USER, develop=false, manifest=true, plugins=[
test_all("AllPlugins"; authors=USER, manifest=true, plugins=[
AppVeyor(), CirrusCI(), Citation(), Codecov(),
Coveralls(), Documenter(), GitLabCI(), TravisCI(),
])

View File

@ -9,22 +9,34 @@ using ReferenceTests: @test_reference
using PkgTemplates
const PT = PkgTemplates
const PKG = "TestPkg"
const USER = "tester"
Random.seed!(1)
tpl(; kwargs...) = Template(; user=USER, kwargs...)
function with_pkg(f::Function, t::Template, pkg::AbstractString=PKG)
t(pkg)
try
f(pkg)
finally
haskey(Pkg.installed(), pkg) && 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
include("template.jl")
include("plugin.jl")
# Quite a bit of output depends on the Julia version,
# and the test fixtures are generated with Julia 1.2.
if 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. Also, Windows uses CRLF which breaks everything.
if !Sys.iswindows() && VERSION.major == 1 && VERSION.minor == 2
include("reference.jl")
else
@info "Skipping reference tests" julia=VERSION