diff --git a/src/plugin.jl b/src/plugin.jl index ae33102..187fcda 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -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, -] diff --git a/src/plugins/defaults.jl b/src/plugins/defaults.jl index 2c4d596..c66e8b4 100644 --- a/src/plugins/defaults.jl +++ b/src/plugins/defaults.jl @@ -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)) diff --git a/test/fixtures/AllPlugins/README.md.txt b/test/fixtures/AllPlugins/README.md.txt index 603070b..35d94a0 100644 --- a/test/fixtures/AllPlugins/README.md.txt +++ b/test/fixtures/AllPlugins/README.md.txt @@ -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) diff --git a/test/plugin.jl b/test/plugin.jl new file mode 100644 index 0000000..92ec338 --- /dev/null +++ b/test/plugin.jl @@ -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 diff --git a/test/reference.jl b/test/reference.jl index bd31ea5..bafe07a 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -6,26 +6,23 @@ end function test_all(pkg::AbstractString; kwargs...) t = tpl(; kwargs...) - pkg_dir = joinpath(t.dir, pkg) - t(pkg) - try + with_pkg(t, pkg) do pkg + pkg_dir = joinpath(t.dir, pkg) 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(), ]) diff --git a/test/runtests.jl b/test/runtests.jl index 0075aec..2121039 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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