Add Test as a test-only dependency (close #25)

This commit is contained in:
Chris de Graaf 2018-10-22 14:35:15 -05:00
parent 9b6c320397
commit 68ccca2ad6
4 changed files with 30 additions and 9 deletions

View File

@ -37,9 +37,9 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
[[Mustache]]
deps = ["Pkg", "Tables", "Test"]
git-tree-sha1 = "455807b7c098d8a31f26792f685d5be250e83292"
git-tree-sha1 = "1cee2f530502aa2357724e7b19af3239b2e7f6b7"
uuid = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
version = "0.5.4"
version = "0.5.5"
[[Pkg]]
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]

View File

@ -1,7 +1,7 @@
name = "PkgTemplates"
uuid = "19f0ff7e-bab4-11e8-074b-97459630f98a"
authors = ["Chris de Graaf <chrisadegraaf@gmail.com>"]
version = "0.1.0"
version = "0.3.1"
[deps]
AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f"
@ -12,5 +12,10 @@ LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
URIParser = "30578b45-9adc-5946-b283-645ec420af67"
[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[targets]
test = ["Test"]

View File

@ -109,13 +109,28 @@ Create the test entrypoint in `pkg_dir`.
Returns an array of generated file/directory names.
"""
function gen_tests(pkg_dir::AbstractString, t::Template)
# TODO: Silence Pkg for this section? Adding and removing Test creates a lot of noise.
proj = Base.current_project()
try
Pkg.activate(pkg_dir)
Pkg.add("Test")
# Move the Test dependency into the [extras] section.
toml = read(joinpath(pkg_dir, "Project.toml"), String)
lines = split(toml, "\n")
idx = findfirst(l -> startswith(l, "Test = "), lines)
testdep = lines[idx]
deleteat!(lines, idx)
toml = join(lines, "\n") * """
[extras]
$testdep
[targets]
test = ["Test"]
"""
gen_file(joinpath(pkg_dir, "Project.toml"), toml)
Pkg.update() # Regenerate Manifest.toml (this cleans up Project.toml too).
finally
# TODO: What should we do if there is no current project?
# Activating the generated project is now a side effect.
proj !== nothing && Pkg.activate(dirname(proj))
end
@ -126,12 +141,10 @@ function gen_tests(pkg_dir::AbstractString, t::Template)
@testset "$pkg.jl" begin
# Write your own tests here.
@test 1 == 2
end
"""
gen_file(joinpath(pkg_dir, "test", "runtests.jl"), text)
# TODO: Should we be checking Manifest.toml into Git?
return ["Manifest.toml", "test/"]
end

View File

@ -225,6 +225,9 @@ end
# Test the test generation.
@test gen_tests(pkg_dir, t) == ["Manifest.toml", "test/"]
@test isfile(joinpath(pkg_dir, "Project.toml"))
project = read(joinpath(pkg_dir, "Project.toml"), String)
@test occursin("[extras]\nTest = ", project)
@test isdir(joinpath(pkg_dir, "test"))
@test isfile(joinpath(pkg_dir, "test", "runtests.jl"))
@test isfile(joinpath(pkg_dir, "Manifest.toml"))
@ -233,7 +236,7 @@ end
@test occursin("using $test_pkg", runtests)
@test occursin("using Test", runtests)
manifest = read(joinpath(pkg_dir, "Manifest.toml"), String)
@test occursin("[[Test]]", manifest)
@test !occursin("[[Test]]", manifest)
rm(temp_dir; recursive=true)
end