A few more tests
This commit is contained in:
parent
e4f97431b5
commit
b70d3c9cf8
@ -1,5 +1,16 @@
|
|||||||
const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults"))
|
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.
|
A simple plugin that, in general, manages a single file.
|
||||||
For example, most CI services reply on one configuration 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", "ci.jl"))
|
||||||
include(joinpath("plugins", "citation.jl"))
|
include(joinpath("plugins", "citation.jl"))
|
||||||
include(joinpath("plugins", "documenter.jl"))
|
include(joinpath("plugins", "documenter.jl"))
|
||||||
|
|
||||||
const BADGE_ORDER = [
|
|
||||||
Documenter{GitLabCI},
|
|
||||||
Documenter{TravisCI},
|
|
||||||
TravisCI,
|
|
||||||
AppVeyor,
|
|
||||||
GitLabCI,
|
|
||||||
CirrusCI,
|
|
||||||
Codecov,
|
|
||||||
Coveralls,
|
|
||||||
]
|
|
||||||
|
@ -27,7 +27,7 @@ function view(p::Readme, t::Template, pkg::AbstractString)
|
|||||||
# Explicitly ordered badges go first.
|
# Explicitly ordered badges go first.
|
||||||
strings = String[]
|
strings = String[]
|
||||||
done = DataType[]
|
done = DataType[]
|
||||||
foreach(BADGE_ORDER) do T
|
foreach(badge_order()) do T
|
||||||
if hasplugin(t, T)
|
if hasplugin(t, T)
|
||||||
bs = badges(t.plugins[T], t, pkg)
|
bs = badges(t.plugins[T], t, pkg)
|
||||||
append!(strings, badges(t.plugins[T], t, pkg))
|
append!(strings, badges(t.plugins[T], t, pkg))
|
||||||
|
4
test/fixtures/AllPlugins/README.md.txt
vendored
4
test/fixtures/AllPlugins/README.md.txt
vendored
@ -1,9 +1,9 @@
|
|||||||
# AllPlugins
|
# AllPlugins
|
||||||
|
|
||||||
[](https://travis-ci.com/tester/AllPlugins.jl)
|
|
||||||
[](https://ci.appveyor.com/project/tester/AllPlugins-jl)
|
|
||||||
[](https://gitlab.com/tester/AllPlugins.jl/pipelines)
|
[](https://gitlab.com/tester/AllPlugins.jl/pipelines)
|
||||||
[](https://gitlab.com/tester/AllPlugins.jl/commits/master)
|
[](https://gitlab.com/tester/AllPlugins.jl/commits/master)
|
||||||
|
[](https://travis-ci.com/tester/AllPlugins.jl)
|
||||||
|
[](https://ci.appveyor.com/project/tester/AllPlugins-jl)
|
||||||
[](https://cirrus-ci.com/github/tester/AllPlugins.jl)
|
[](https://cirrus-ci.com/github/tester/AllPlugins.jl)
|
||||||
[](https://codecov.io/gh//.jl)
|
[](https://codecov.io/gh//.jl)
|
||||||
[](https://coveralls.io/github//.jl?branch=master)
|
[](https://coveralls.io/github//.jl?branch=master)
|
||||||
|
26
test/plugin.jl
Normal file
26
test/plugin.jl
Normal 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
|
@ -6,26 +6,23 @@ end
|
|||||||
|
|
||||||
function test_all(pkg::AbstractString; kwargs...)
|
function test_all(pkg::AbstractString; kwargs...)
|
||||||
t = tpl(; kwargs...)
|
t = tpl(; kwargs...)
|
||||||
|
with_pkg(t, pkg) do pkg
|
||||||
pkg_dir = joinpath(t.dir, pkg)
|
pkg_dir = joinpath(t.dir, pkg)
|
||||||
t(pkg)
|
|
||||||
try
|
|
||||||
foreach(readlines(`git -C $pkg_dir ls-files`)) do f
|
foreach(readlines(`git -C $pkg_dir ls-files`)) do f
|
||||||
# All fixture files are .txt so that ReferenceTests can handle them.
|
# All fixture files are .txt so that ReferenceTests can handle them.
|
||||||
reference = joinpath(@__DIR__, "fixtures", pkg, f * ".txt")
|
reference = joinpath(@__DIR__, "fixtures", pkg, f * ".txt")
|
||||||
observed = read(joinpath(pkg_dir, f), String)
|
observed = read(joinpath(pkg_dir, f), String)
|
||||||
@test_reference reference observed
|
@test_reference reference observed
|
||||||
end
|
end
|
||||||
finally
|
|
||||||
rm(pkg_dir; recursive=true, force=true)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "Default package" begin
|
@testset "Default package" begin
|
||||||
test_all("Basic"; authors=USER, develop=false, manifest=true)
|
test_all("Basic"; authors=USER, manifest=true)
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "All plugins" begin
|
@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(),
|
AppVeyor(), CirrusCI(), Citation(), Codecov(),
|
||||||
Coveralls(), Documenter(), GitLabCI(), TravisCI(),
|
Coveralls(), Documenter(), GitLabCI(), TravisCI(),
|
||||||
])
|
])
|
||||||
|
@ -9,22 +9,34 @@ using ReferenceTests: @test_reference
|
|||||||
using PkgTemplates
|
using PkgTemplates
|
||||||
const PT = PkgTemplates
|
const PT = PkgTemplates
|
||||||
|
|
||||||
|
const PKG = "TestPkg"
|
||||||
const USER = "tester"
|
const USER = "tester"
|
||||||
|
|
||||||
Random.seed!(1)
|
Random.seed!(1)
|
||||||
|
|
||||||
tpl(; kwargs...) = Template(; user=USER, kwargs...)
|
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
|
@testset "PkgTemplates.jl" begin
|
||||||
mktempdir() do dir
|
mktempdir() do dir
|
||||||
Pkg.activate(dir)
|
Pkg.activate(dir)
|
||||||
pushfirst!(DEPOT_PATH, dir)
|
pushfirst!(DEPOT_PATH, dir)
|
||||||
try
|
try
|
||||||
include("template.jl")
|
include("template.jl")
|
||||||
|
include("plugin.jl")
|
||||||
|
|
||||||
# Quite a bit of output depends on the Julia version,
|
# Quite a bit of output depends on the Julia version, and the test fixtures are
|
||||||
# and the test fixtures are generated with Julia 1.2.
|
# made with Julia 1.2. Also, Windows uses CRLF which breaks everything.
|
||||||
if VERSION.major == 1 && VERSION.minor == 2
|
if !Sys.iswindows() && VERSION.major == 1 && VERSION.minor == 2
|
||||||
include("reference.jl")
|
include("reference.jl")
|
||||||
else
|
else
|
||||||
@info "Skipping reference tests" julia=VERSION
|
@info "Skipping reference tests" julia=VERSION
|
||||||
|
Loading…
Reference in New Issue
Block a user