diff --git a/Project.toml b/Project.toml index 8b84894..0121c42 100644 --- a/Project.toml +++ b/Project.toml @@ -11,4 +11,5 @@ InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" TerminalMenus = "dc548174-15c3-5faf-af27-7997cfbde655" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" URIParser = "30578b45-9adc-5946-b283-645ec420af67" diff --git a/src/licenses.jl b/src/licenses.jl index e3bfbeb..a0d1787 100644 --- a/src/licenses.jl +++ b/src/licenses.jl @@ -8,7 +8,7 @@ const LICENSES = Dict( "GPL-2.0+" => "GNU Public License, Version 2.0+", "GPL-3.0+" => "GNU Public License, Version 3.0+", "LGPL-2.1+" => "Lesser GNU Public License, Version 2.1+", - "LGPL-3.0+" => "Lesser GNU Public License, Version 3.0+" + "LGPL-3.0+" => "Lesser GNU Public License, Version 3.0+", ) """ @@ -16,16 +16,16 @@ const LICENSES = Dict( Print the names of all available licenses. """ -available_licenses(io::IO) = println(io, join(("$k: $v" for (k, v) in LICENSES), "\n")) -available_licenses() = available_licenses(STDOUT) +available_licenses(io::IO) = print(io, join(("$k: $v" for (k, v) in LICENSES), "\n")) +available_licenses() = available_licenses(stdout) """ show_license([io::IO], license::AbstractString) -> Nothing Print the text of `license`. Errors if the license is not found. """ -show_license(io::IO, license::AbstractString) = println(io, read_license(license)) -show_license(license::AbstractString) = show_license(STDOUT, license) +show_license(io::IO, license::AbstractString) = print(io, read_license(license)) +show_license(license::AbstractString) = show_license(stdout, license) """ read_license(license::AbstractString) -> String diff --git a/src/template.jl b/src/template.jl index 217310b..8a6587d 100644 --- a/src/template.jl +++ b/src/template.jl @@ -1,5 +1,12 @@ import Base.show +""" + dev_dir() -> String + +Get the default development directory (~/.julia/dev). +""" +dev_dir() = joinpath(first(DEPOT_PATH), "dev") + """ Template(; kwargs...) -> Template @@ -24,10 +31,10 @@ create a template, you can use [`interactive_template`](@ref) instead. license. Supply a string for one author or an array for multiple. Similarly to `user`, it will try to take the value of a supplied git config's "user.name" key, then the global git config's value, if it is left unset. -* `years::Union{Integer, AbstractString}=Dates.year(Dates.today())`: Copyright years on the - license. Can be supplied by a number, or a string such as "2016 - 2017". -* `dir::AbstractString=joinpath(first(DEPOT_PATH), "dev")`: Directory in which the package - will go. Relative paths are converted to absolute ones at template creation time. +* `years::Union{Integer, AbstractString}=$(Dates.year(Dates.today()))`: Copyright years on + the license. Can be supplied by a number, or a string such as "2016 - 2017". +* `dir::AbstractString=$(dev_dir())`: Directory in which the package will go. Relative + paths are converted to absolute ones at template creation time. * `precompile::Bool=true`: Whether or not to enable precompilation in generated packages. * `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version. * `requirements::Vector{<:AbstractString}=String[]`: Package requirements. If there are @@ -53,10 +60,10 @@ create a template, you can use [`interactive_template`](@ref) instead. function Template(; user::AbstractString="", host::AbstractString="https://github.com", - license::Union{AbstractString, Nothing}="MIT", + license::AbstractString="MIT", authors::Union{AbstractString, Vector{<:AbstractString}}="", years::Union{Integer, AbstractString}=Dates.year(Dates.today()), - dir::AbstractString=joinpath(first(DEPOT_PATH), "dev"), + dir::AbstractString=dev_dir(), precompile::Bool=true, julia_version::VersionNumber=VERSION, requirements::Vector{<:AbstractString}=String[], @@ -98,12 +105,12 @@ create a template, you can use [`interactive_template`](@ref) instead. "requirements contains duplicate packages with conflicting versions" )) elseif diff > 0 - warn("Removed $(diff) duplicate$(diff == 1 ? "" : "s") from requirements") + @warn "Removed $(diff) duplicate$(diff == 1 ? "" : "s") from requirements" end plugin_dict = Dict{DataType, Plugin}(typeof(p) => p for p in plugins) if (length(plugins) != length(plugin_dict)) - warn("Plugin list contained duplicates, only the last of each type was kept") + @warn "Plugin list contained duplicates, only the last of each type was kept" end new( @@ -206,7 +213,7 @@ function interactive_template(; fast::Bool=false) io = IOBuffer() available_licenses(io) licenses = ["" => "", collect(LICENSES)...] - menu = RadioMenu(["None", split(String(take!(io)), "\n")...]) + menu = RadioMenu(String["None", split(String(take!(io)), "\n")...]) # If the user breaks out of the menu with Ctrl-c, the result is -1, the absolute # value of which correponds to no license. licenses[abs(request(menu))].first @@ -235,9 +242,9 @@ function interactive_template(; fast::Bool=false) end kwargs[:dir] = if fast - joinpath(first(DEPOT_PATH), "dev") + dev_dir() else - default_dir = "." + default_dir = dev_dir() print("Enter the path to the package directory [$default_dir]: ") dir = readline() isempty(dir) ? default_dir : dir diff --git a/test/interactive/interactive.jl b/test/interactive/interactive.jl index 51ec178..df4743b 100644 --- a/test/interactive/interactive.jl +++ b/test/interactive/interactive.jl @@ -2,30 +2,30 @@ # which seems to be the case in Travis CI OSX builds. # https://travis-ci.org/invenia/PkgTemplates.jl/jobs/267682403#L115 # https://github.com/nick-paul/TerminalMenus.jl/issues/5 -# This also affects any time we write to STDIN.buffer, because +# This also affects any time we write to stdin.buffer, because # IOStreams do not have that attribute. # Therefore, we skip any interactive tests on OSX builds. @testset "Interactive template creation" begin - write(STDIN.buffer, "$me\n\n\r\n\n\n\n\nd") + write(stdin.buffer, "$me\n\n\r\n\n\n\n\nd") t = interactive_template() @test t.user == me @test t.host == "github.com" @test isempty(t.license) @test t.authors == LibGit2.getconfig("user.name", "") @test t.years == string(Dates.year(Dates.today())) - @test t.dir == Pkg.dir() + @test t.dir == default_dir @test t.julia_version == VERSION @test isempty(t.requirements) @test isempty(t.gitconfig) @test isempty(t.plugins) if isempty(LibGit2.getconfig("github.user", "")) - write(STDIN.buffer, "\n") + write(stdin.buffer, "\n") @test_throws ArgumentError t = interactive_template() end - write(STDIN.buffer, "$me\ngitlab.com\n$('\x1b')[B\r$me\n2016\n$test_file\nno\n0.5\nX Y\nkey val val\nkey2 val2\n\n$('\x1b')[B\r$('\x1b')[B\rd\n\n") + write(stdin.buffer, "$me\ngitlab.com\n$('\x1b')[B\r$me\n2016\n$test_file\nno\n0.5\nX Y\nkey val val\nkey2 val2\n\n$('\x1b')[B\r$('\x1b')[B\rd\n\n") t = interactive_template() @test t.user == me @test t.host == "gitlab.com" @@ -41,10 +41,10 @@ # Like above, not sure which plugins this will generate. @test length(t.plugins) == 2 - write(STDIN.buffer, "$me\n\n\r\n\n\n\nA B\n A B\n\nd") - @test_warn r".+" interactive_template() + write(stdin.buffer, "$me\n\n\r\n\n\n\nA B\nA B\n\nd") + @test_logs (:warn, r".+") match_mode=:any interactive_template() - write(STDIN.buffer, "$me\nd") + write(stdin.buffer, "$me\nd") t = interactive_template(; fast=true) @test t.user == me @test t.host == "github.com" @@ -52,7 +52,7 @@ @test t.authors == LibGit2.getconfig("user.name", "") # I guess this could technically break if it runs on New Year's Eve... @test t.years == string(Dates.year(Dates.today())) - @test t.dir == Pkg.dir() + @test t.dir == default_dir @test t.julia_version == VERSION @test isempty(t.requirements) @test isempty(t.gitconfig) @@ -62,8 +62,8 @@ end @testset "Interactive package generation" begin cfg = join(("$k $v" for (k, v) in gitconfig), "\n") - write(STDIN.buffer, "$me\n\n\r\n\n\n\n$cfg\n\nd") + write(stdin.buffer, "$me\n\n\r\n\n\n\n$cfg\n\nd") generate_interactive(test_pkg) - @test isdir(Pkg.dir(test_pkg)) - rm(Pkg.dir(test_pkg); force=true, recursive=true) + @test isdir(joinpath(default_dir, test_pkg)) + rm(joinpath(default_dir, test_pkg); force=true, recursive=true) end diff --git a/test/interactive/plugins.jl b/test/interactive/plugins.jl index ddf3efa..36cf86c 100644 --- a/test/interactive/plugins.jl +++ b/test/interactive/plugins.jl @@ -1,90 +1,90 @@ # These tests are to be skipped in OSX builds, see ./interactive.jl for more info. @testset "TravisCI" begin - write(STDIN.buffer, "\n") + write(stdin.buffer, "\n") p = interactive(TravisCI) - @test get(p.src, "") == joinpath(DEFAULTS_DIR, "travis.yml") - write(STDIN.buffer, "$test_file\n") + @test p.src == joinpath(DEFAULTS_DIR, "travis.yml") + write(stdin.buffer, "$test_file\n") p = interactive(TravisCI) - @test get(p.src, "") == test_file - write(STDIN.buffer, "none\n") + @test p.src == test_file + write(stdin.buffer, "none\n") p = interactive(TravisCI) - @test isnull(p.src) - write(STDIN.buffer, "$fake_path\n") + @test p.src === nothing + write(stdin.buffer, "$fake_path\n") @test_throws ArgumentError interactive(TravisCI) println() end @testset "AppVeyor" begin - write(STDIN.buffer, "\n") + write(stdin.buffer, "\n") p = interactive(AppVeyor) - @test get(p.src, "") == joinpath(DEFAULTS_DIR, "appveyor.yml") - write(STDIN.buffer, "$test_file\n") + @test p.src == joinpath(DEFAULTS_DIR, "appveyor.yml") + write(stdin.buffer, "$test_file\n") p = interactive(AppVeyor) - @test get(p.src, "") == test_file - write(STDIN.buffer, "none\n") + @test p.src == test_file + write(stdin.buffer, "none\n") p = interactive(AppVeyor) - @test isnull(p.src) - write(STDIN.buffer, "$fake_path\n") + @test p.src === nothing + write(stdin.buffer, "$fake_path\n") @test_throws ArgumentError interactive(AppVeyor) println() end @testset "GitLabCI" begin - write(STDIN.buffer, "\n\n") + write(stdin.buffer, "\n\n") p = interactive(GitLabCI) - @test get(p.src, "") == joinpath(DEFAULTS_DIR, "gitlab-ci.yml") + @test p.src == joinpath(DEFAULTS_DIR, "gitlab-ci.yml") @test p.view == Dict("GITLABCOVERAGE" => true) - write(STDIN.buffer, "$test_file\nno\n") + write(stdin.buffer, "$test_file\nno\n") p = interactive(GitLabCI) - @test get(p.src, "") == test_file + @test p.src == test_file @test p.view == Dict("GITLABCOVERAGE" => false) - write(STDIN.buffer, "none\n\n") + write(stdin.buffer, "none\n\n") p = interactive(GitLabCI) - @test isnull(p.src) - write(STDIN.buffer, "$fake_path\n\n") + @test p.src === nothing + write(stdin.buffer, "$fake_path\n\n") @test_throws ArgumentError interactive(GitLabCI) println() end @testset "CodeCov" begin - write(STDIN.buffer, "\n") + write(stdin.buffer, "\n") p = interactive(CodeCov) - @test isnull(p.src) - write(STDIN.buffer, "$test_file\n") + @test p.src === nothing + write(stdin.buffer, "$test_file\n") p = interactive(CodeCov) - @test get(p.src, "") == test_file - write(STDIN.buffer, "none\n") + @test p.src == test_file + write(stdin.buffer, "none\n") p = interactive(CodeCov) - @test isnull(p.src) - write(STDIN.buffer, "$fake_path\n") + @test p.src === nothing + write(stdin.buffer, "$fake_path\n") @test_throws ArgumentError interactive(CodeCov) println() end @testset "Coveralls" begin - write(STDIN.buffer, "\n") + write(stdin.buffer, "\n") p = interactive(Coveralls) - @test isnull(p.src) - write(STDIN.buffer, "$test_file\n") + @test p.src === nothing + write(stdin.buffer, "$test_file\n") p = interactive(Coveralls) - @test get(p.src, "") == test_file - write(STDIN.buffer, "none\n") + @test p.src == test_file + write(stdin.buffer, "none\n") p = interactive(Coveralls) - @test isnull(p.src) - write(STDIN.buffer, "$fake_path\n") + @test p.src === nothing + write(stdin.buffer, "$fake_path\n") @test_throws ArgumentError interactive(Coveralls) println() end @testset "GitHubPages" begin - write(STDIN.buffer, "\n") + write(stdin.buffer, "\n") p = interactive(GitHubPages) @test isempty(p.assets) - write(STDIN.buffer, "$test_file\n") + write(stdin.buffer, "$test_file\n") p = interactive(GitHubPages) @test p.assets == [test_file] - write(STDIN.buffer, "$fake_path\n") + write(stdin.buffer, "$fake_path\n") @test_throws ArgumentError interactive(GitHubPages) println() end diff --git a/test/plugins/appveyor.jl b/test/plugins/appveyor.jl index ef0a9e6..46276da 100644 --- a/test/plugins/appveyor.jl +++ b/test/plugins/appveyor.jl @@ -7,7 +7,7 @@ pkg_dir = joinpath(temp_dir, test_pkg) @testset "Plugin creation" begin p = AppVeyor() @test isempty(p.gitignore) - @test get(p.src, "") == joinpath(PkgTemplates.DEFAULTS_DIR, "appveyor.yml") + @test p.src == joinpath(PkgTemplates.DEFAULTS_DIR, "appveyor.yml") @test p.dest == ".appveyor.yml" @test p.badges == [ Badge( @@ -18,9 +18,9 @@ pkg_dir = joinpath(temp_dir, test_pkg) ] @test isempty(p.view) p = AppVeyor(; config_file=nothing) - @test isnull(p.src) + @test p.src === nothing p = AppVeyor(; config_file=test_file) - @test get(p.src, "") == test_file + @test p.src == test_file @test_throws ArgumentError AppVeyor(; config_file=fake_path) end diff --git a/test/plugins/codecov.jl b/test/plugins/codecov.jl index e4db4bf..e410363 100644 --- a/test/plugins/codecov.jl +++ b/test/plugins/codecov.jl @@ -7,7 +7,7 @@ pkg_dir = joinpath(temp_dir, test_pkg) @testset "Plugin creation" begin p = CodeCov() @test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] - @test isnull(p.src) + @test p.src === nothing @test p.dest == ".codecov.yml" @test p.badges == [ Badge( @@ -18,9 +18,9 @@ pkg_dir = joinpath(temp_dir, test_pkg) ] @test isempty(p.view) p = CodeCov(; config_file=nothing) - @test isnull(p.src) + @test p.src === nothing p = CodeCov(; config_file=test_file) - @test get(p.src, "") == test_file + @test p.src == test_file @test_throws ArgumentError CodeCov(; config_file=fake_path) end diff --git a/test/plugins/coveralls.jl b/test/plugins/coveralls.jl index fabce93..3b257c2 100644 --- a/test/plugins/coveralls.jl +++ b/test/plugins/coveralls.jl @@ -7,7 +7,7 @@ pkg_dir = joinpath(temp_dir, test_pkg) @testset "Plugin creation" begin p = Coveralls() @test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] - @test isnull(p.src) + @test p.src === nothing @test p.dest == ".coveralls.yml" @test p.badges == [ Badge( @@ -18,9 +18,9 @@ pkg_dir = joinpath(temp_dir, test_pkg) ] @test isempty(p.view) p = Coveralls(; config_file=nothing) - @test isnull(p.src) + @test p.src === nothing p = Coveralls(; config_file=test_file) - @test get(p.src, "") == test_file + @test p.src == test_file @test_throws ArgumentError Coveralls(; config_file=fake_path) end diff --git a/test/plugins/gitlabci.jl b/test/plugins/gitlabci.jl index 732ac62..905859d 100644 --- a/test/plugins/gitlabci.jl +++ b/test/plugins/gitlabci.jl @@ -7,7 +7,7 @@ pkg_dir = joinpath(temp_dir, test_pkg) @testset "Plugin creation" begin p = GitLabCI() @test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] - @test get(p.src, "") == joinpath(PkgTemplates.DEFAULTS_DIR, "gitlab-ci.yml") + @test p.src == joinpath(PkgTemplates.DEFAULTS_DIR, "gitlab-ci.yml") @test p.dest == ".gitlab-ci.yml" @test p.badges == [ Badge( @@ -23,9 +23,9 @@ pkg_dir = joinpath(temp_dir, test_pkg) ] @test p.view == Dict("GITLABCOVERAGE" => true) p = GitLabCI(; config_file=nothing) - @test isnull(p.src) + @test p.src === nothing p = GitLabCI(; config_file=test_file) - @test get(p.src, "") == test_file + @test p.src == test_file @test_throws ArgumentError GitLabCI(; config_file=fake_path) p = GitLabCI(; coverage=false) @test p.badges == [ diff --git a/test/plugins/travisci.jl b/test/plugins/travisci.jl index 4b2409e..530a3a1 100644 --- a/test/plugins/travisci.jl +++ b/test/plugins/travisci.jl @@ -7,7 +7,7 @@ pkg_dir = joinpath(temp_dir, test_pkg) @testset "Plugin creation" begin p = TravisCI() @test isempty(p.gitignore) - @test get(p.src, "") == joinpath(PkgTemplates.DEFAULTS_DIR, "travis.yml") + @test p.src == joinpath(PkgTemplates.DEFAULTS_DIR, "travis.yml") @test p.dest == ".travis.yml" @test p.badges == [ Badge( @@ -18,9 +18,9 @@ pkg_dir = joinpath(temp_dir, test_pkg) ] @test isempty(p.view) p = TravisCI(; config_file=nothing) - @test isnull(p.src) + @test p.src === nothing p = TravisCI(; config_file=test_file) - @test get(p.src, "") == test_file + @test p.src == test_file @test_throws ArgumentError TravisCI(; config_file=fake_path) end diff --git a/test/runtests.jl b/test/runtests.jl index c4fbac2..0bc2150 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,7 @@ using PkgTemplates -using Base.Test +using Test +using Dates +using LibGit2 import PkgTemplates: badges, version_floor, substitute, read_license, gen_file, gen_readme, gen_tests, gen_license, gen_require, gen_entrypoint, gen_gitignore, gen_plugin, @@ -7,17 +9,11 @@ import PkgTemplates: badges, version_floor, substitute, read_license, gen_file, format, interactive, DEFAULTS_DIR mktempdir() do temp_dir - withenv("JULIA_PKGDIR" => temp_dir) do - # We technically don't need to clone METADATA to run tests. - if get(ENV, "PKGTEMPLATES_TEST_FAST", "false") == "true" - mkdir(joinpath(temp_dir, "v$(version_floor())")) - else - Pkg.init() - end - cd(temp_dir) do - @testset "PkgTemplates.jl" begin - include("tests.jl") - end + mkdir(joinpath(temp_dir, "dev")) + pushfirst!(DEPOT_PATH, temp_dir) + cd(temp_dir) do + @testset "PkgTemplates.jl" begin + include("tests.jl") end end end diff --git a/test/tests.jl b/test/tests.jl index 9f7c176..8622be6 100644 --- a/test/tests.jl +++ b/test/tests.jl @@ -1,6 +1,6 @@ struct Foo <: GenericPlugin gitignore::Vector{AbstractString} - src::Nullable{AbstractString} + src::Union{AbstractString, Nothing} dest::AbstractString badges::Vector{Badge} view::Dict{String, Any} @@ -18,8 +18,9 @@ const gitconfig = Dict( "github.user" => "TesterMcTestFace", ) const test_pkg = "TestPkg" -const fake_path = bin(hash("/this/file/does/not/exist")) +const fake_path = string(hash("/this/file/does/not/exist"); base=2) const test_file = tempname() +const default_dir = PkgTemplates.dev_dir() const template_text = """ PKGNAME: {{PKGNAME}} VERSION: {{VERSION}}} @@ -37,7 +38,7 @@ write(test_file, template_text) @test t.license == "MIT" @test t.years == string(Dates.year(Dates.today())) @test t.authors == LibGit2.getconfig("user.name", "") - @test t.dir == Pkg.dir() + @test t.dir == default_dir @test t.julia_version == VERSION @test isempty(t.gitconfig) @test isempty(t.plugins) @@ -61,7 +62,7 @@ write(test_file, template_text) t = Template(; user=me, dir=test_file) @test t.dir == abspath(test_file) - if is_unix() # ~ means temporary file on Windows, not $HOME. + if Sys.isunix() # ~ means temporary file on Windows, not $HOME. t = Template(; user=me, dir="~/$(basename(test_file))") @test t.dir == joinpath(homedir(), basename(test_file)) end @@ -74,7 +75,7 @@ write(test_file, template_text) t = Template(; user=me, requirements=["$test_pkg 0.1"]) @test t.requirements == ["$test_pkg 0.1"] - @test_warn r".+" t = Template(; user=me, requirements=[test_pkg, test_pkg]) + @test_logs (:warn, r".+") t = Template(; user=me, requirements=[test_pkg, test_pkg]) @test t.requirements == [test_pkg] @test_throws ArgumentError Template(; user=me, @@ -102,7 +103,7 @@ write(test_file, template_text) [GitHubPages(), TravisCI(), AppVeyor(), CodeCov(), Coveralls()] ) - @test_warn r".+" t = Template(; + @test_logs (:warn, r".+") t = Template(; user=me, plugins=[TravisCI(), TravisCI()], ) @@ -126,7 +127,7 @@ else end @testset "Show methods" begin - pkgdir = replace(joinpath(ENV["JULIA_PKGDIR"], "v$(version_floor())"), homedir(), "~") + pkg_dir = replace(default_dir, homedir() => "~") buf = IOBuffer() t = Template(; user=me, gitconfig=gitconfig) show(buf, t) @@ -136,7 +137,7 @@ end → User: $me → Host: github.com → License: MIT ($(gitconfig["user.name"]) $(Dates.year(now()))) - → Package directory: $pkgdir + → Package directory: $pkg_dir → Precompilation enabled: Yes → Minimum Julia version: v$(PkgTemplates.version_floor()) → 0 package requirements @@ -165,7 +166,7 @@ end → User: $me → Host: github.com → License: None - → Package directory: $pkgdir + → Package directory: $pkg_dir → Precompilation enabled: Yes → Minimum Julia version: v$(PkgTemplates.version_floor()) → 2 package requirements: Bar, Foo @@ -201,7 +202,7 @@ end temp_file = tempname() gen_file(temp_file, "Hello, world") @test isfile(temp_file) - @test readstring(temp_file) == "Hello, world\n" + @test read(temp_file, String) == "Hello, world\n" rm(temp_file) @test gen_readme(temp_dir, test_pkg, t) == ["README.md"] @@ -227,7 +228,7 @@ end @test gen_gitignore(temp_dir, test_pkg, t) == [".gitignore"] @test isfile(joinpath(pkg_dir, ".gitignore")) - gitignore = readstring(joinpath(pkg_dir, ".gitignore")) + gitignore = read(joinpath(pkg_dir, ".gitignore"), String) rm(joinpath(pkg_dir, ".gitignore")) @test contains(gitignore, ".DS_Store") for p in values(t.plugins) @@ -278,15 +279,17 @@ end @testset "Package generation" begin t = Template(; user=me, gitconfig=gitconfig) generate(test_pkg, t) - @test isfile(Pkg.dir(test_pkg, "LICENSE")) - @test isfile(Pkg.dir(test_pkg, "README.md")) - @test isfile(Pkg.dir(test_pkg, "REQUIRE")) - @test isfile(Pkg.dir(test_pkg, ".gitignore")) - @test isdir(Pkg.dir(test_pkg, "src")) - @test isfile(Pkg.dir(test_pkg, "src", "$test_pkg.jl")) - @test isdir(Pkg.dir(test_pkg, "test")) - @test isfile(Pkg.dir(test_pkg, "test", "runtests.jl")) - repo = LibGit2.GitRepo(Pkg.dir(test_pkg)) + pkg_dir = joinpath(default_dir, test_pkg) + + @test isfile(joinpath(pkg_dir, "LICENSE")) + @test isfile(joinpath(pkg_dir, "README.md")) + @test isfile(joinpath(pkg_dir, "REQUIRE")) + @test isfile(joinpath(pkg_dir, ".gitignore")) + @test isdir(joinpath(pkg_dir, "src")) + @test isfile(joinpath(pkg_dir, "src", "$test_pkg.jl")) + @test isdir(joinpath(pkg_dir, "test")) + @test isfile(joinpath(pkg_dir, "test", "runtests.jl")) + repo = LibGit2.GitRepo(pkg_dir) remote = LibGit2.get(LibGit2.GitRemote, repo, "origin") branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo)) @test LibGit2.getconfig(repo, "user.name", "") == gitconfig["user.name"] @@ -296,20 +299,20 @@ end @test in("master", branches) @test !in("gh-pages", branches) @test !LibGit2.isdirty(repo) - rm(Pkg.dir(test_pkg); recursive=true) + rm(pkg_dir; recursive=true) generate(t, test_pkg; ssh=true) # Test the reversed-arguments method. - repo = LibGit2.GitRepo(Pkg.dir(test_pkg)) + repo = LibGit2.GitRepo(pkg_dir) remote = LibGit2.get(LibGit2.GitRemote, repo, "origin") @test LibGit2.url(remote) == "git@github.com:$me/$test_pkg.jl.git" - rm(Pkg.dir(test_pkg); recursive=true) + rm(pkg_dir; recursive=true) t = Template(; user=me, host="gitlab.com", gitconfig=gitconfig) generate(test_pkg, t) - repo = LibGit2.GitRepo(Pkg.dir(test_pkg)) + repo = LibGit2.GitRepo(pkg_dir) remote = LibGit2.get(LibGit2.GitRemote, repo, "origin") @test LibGit2.url(remote) == "https://gitlab.com/$me/$test_pkg.jl" - rm(Pkg.dir(test_pkg); recursive=true) + rm(pkg_dir; recursive=true) temp_dir = mktempdir() t = Template(; user=me, dir=temp_dir, gitconfig=gitconfig) @@ -324,45 +327,45 @@ end plugins=[AppVeyor(), GitHubPages(), Coveralls(), CodeCov(), TravisCI()], ) generate(test_pkg, t) - @test isdir(joinpath(Pkg.dir(), test_pkg)) - @test !isfile(Pkg.dir(test_pkg, "LICENSE")) - @test isfile(Pkg.dir(test_pkg, ".travis.yml")) - @test isfile(Pkg.dir(test_pkg, ".appveyor.yml")) - @test isdir(Pkg.dir(test_pkg, "docs")) - @test isfile(Pkg.dir(test_pkg, "docs", "make.jl")) - @test isdir(Pkg.dir(test_pkg, "docs", "src")) - @test isfile(Pkg.dir(test_pkg, "docs", "src", "index.md")) - repo = LibGit2.GitRepo(Pkg.dir(test_pkg)) + @test isdir(pkg_dir) + @test !isfile(joinpath(pkg_dir, "LICENSE")) + @test isfile(joinpath(pkg_dir, ".travis.yml")) + @test isfile(joinpath(pkg_dir, ".appveyor.yml")) + @test isdir(joinpath(pkg_dir, "docs")) + @test isfile(joinpath(pkg_dir, "docs", "make.jl")) + @test isdir(joinpath(pkg_dir, "docs", "src")) + @test isfile(joinpath(pkg_dir, "docs", "src", "index.md")) + repo = LibGit2.GitRepo(pkg_dir) @test LibGit2.getconfig(repo, "user.name", "") == gitconfig["user.name"] branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo)) @test in("gh-pages", branches) @test !LibGit2.isdirty(repo) - rm(Pkg.dir(test_pkg); recursive=true) + rm(pkg_dir; recursive=true) - mkdir(Pkg.dir(test_pkg)) + mkdir(pkg_dir) @test_throws ArgumentError generate(test_pkg, t) generate(test_pkg, t; force=true) - @test isfile(Pkg.dir(test_pkg, "README.md")) - rm(Pkg.dir(test_pkg); recursive=true) + @test isfile(joinpath(pkg_dir, "README.md")) + rm(pkg_dir; recursive=true) - temp_file, fd = mktemp() - close(fd) + temp_file, io = mktemp() + close(io) temp_dir = mktempdir() - t = Template(; user=me, dir=temp_file, gitconfig=gitconfig) - @test_warn r".+" generate(test_pkg, t; backup_dir=temp_dir) + t = Template(; user=me, dir=temp_file) + @test_logs (:warn, r".+") match_mode=:any generate(test_pkg, t; backup_dir=temp_dir) rm(temp_dir; recursive=true) temp_dir = mktempdir() - t = Template(; user=me, dir=joinpath(temp_file, "file"), gitconfig=gitconfig) - @test_warn r".+" generate(test_pkg, t; backup_dir=temp_dir) + t = Template(; user=me, dir=joinpath(temp_file, "dir")) + @test_logs (:warn, r".+") match_mode=:any generate(test_pkg, t; backup_dir=temp_dir) rm(temp_dir; recursive=true) rm(temp_file) t = Template(; user=me, gitconfig=gitconfig, plugins=[GitHubPages()]) generate(test_pkg, t) - readme = readstring(Pkg.dir(test_pkg, "README.md")) - index = readstring(Pkg.dir(test_pkg, "docs", "src", "index.md")) + readme = read(joinpath(pkg_dir, "README.md"), String) + index = read(joinpath(pkg_dir, "docs", "src", "index.md"), String) @test readme == index - rm(Pkg.dir(test_pkg); recursive=true) + rm(pkg_dir; recursive=true) end @testset "Version floor" begin @@ -435,7 +438,7 @@ end @test contains(licenses, "$short: $long") end @test strip(mit) == strip(read_license("MIT")) - @test strip(read_license("MIT")) == strip(readstring(joinpath(LICENSE_DIR, "MIT"))) + @test strip(read_license("MIT")) == strip(read(joinpath(LICENSE_DIR, "MIT"), String)) @test_throws ArgumentError read_license(fake_path) for license in readdir(LICENSE_DIR)