From ce0277af5fd75c3dc815007f2c45df5de1ca48d6 Mon Sep 17 00:00:00 2001 From: Mary Jo Ramos Date: Thu, 17 Jun 2021 15:26:25 -0500 Subject: [PATCH 1/5] Remove SimpleMock and add Mocking --- Project.toml | 5 +++-- src/PkgTemplates.jl | 2 ++ test/runtests.jl | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index 67a1d5f3..eb3e5877 100644 --- a/Project.toml +++ b/Project.toml @@ -7,6 +7,7 @@ version = "0.7.16" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" +Mocking = "78c3b35d-d492-501b-9361-3d52fe80e533" Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" @@ -14,6 +15,7 @@ REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] +Mocking = "0.7" Mustache = "1" Parameters = "0.12" julia = "1" @@ -21,9 +23,8 @@ julia = "1" [extras] DeepDiffs = "ab62b9b5-e342-54a8-a765-a90f495de1a6" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -SimpleMock = "a896ed2c-15a5-4479-b61d-a0e88e2a1d25" Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["DeepDiffs", "Random", "Suppressor", "SimpleMock", "Test"] +test = ["DeepDiffs", "Random", "Suppressor", "Test"] diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index ba693138..4f581074 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -13,6 +13,8 @@ using UUIDs: uuid4 using Mustache: render using Parameters: @with_kw_noshow +using Mocking + export Template, AppVeyor, diff --git a/test/runtests.jl b/test/runtests.jl index e017b8d2..eb23f096 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,12 +7,14 @@ using Random: Random, randstring using Test: @test, @testset, @test_broken, @test_logs, @test_throws using DeepDiffs: deepdiff -using SimpleMock: mock +using Mocking using Suppressor: @suppress using PkgTemplates -const PT = PkgTemplates +Mocking.activate() + +const PT = PkgTemplates const USER = "tester" Random.seed!(1) From 5a61567871d8bf9d10f15ef1888ee50663dd052b Mon Sep 17 00:00:00 2001 From: Mary Jo Ramos Date: Thu, 17 Jun 2021 15:27:17 -0500 Subject: [PATCH 2/5] Update template tests to use Mocking --- src/plugins/git.jl | 4 ++-- src/template.jl | 2 +- test/template.jl | 16 ++++++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/plugins/git.jl b/src/plugins/git.jl index 5b235d56..90911efd 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -48,7 +48,7 @@ function validate(p::Git, t::Template) foreach((:name, :email)) do k user_k = "user.$k" - if getproperty(p, k) === nothing && isempty(LibGit2.getconfig(user_k, "")) + if getproperty(p, k) === nothing && isempty(@mock LibGit2.getconfig(user_k, "")) throw(ArgumentError("Git: Global Git config is missing required value '$user_k'")) end end @@ -56,7 +56,7 @@ end # Set up the Git repository. function prehook(p::Git, t::Template, pkg_dir::AbstractString) - LibGit2.with(LibGit2.init(pkg_dir)) do repo + LibGit2.with(@mock LibGit2.init(pkg_dir)) do repo LibGit2.with(GitConfig(repo)) do config foreach((:name, :email)) do k v = getproperty(p, k) diff --git a/src/template.jl b/src/template.jl index ce8d1935..c5232718 100644 --- a/src/template.jl +++ b/src/template.jl @@ -84,7 +84,7 @@ Template(::Val{true}; kwargs...) = interactive(Template; kwargs...) function Template(::Val{false}; kwargs...) kwargs = Dict(kwargs) - user = getkw!(kwargs, :user) + user = @mock getkw!(kwargs, :user) dir = abspath(expanduser(getkw!(kwargs, :dir))) host = replace(getkw!(kwargs, :host), r".*://" => "") julia = getkw!(kwargs, :julia) diff --git a/test/template.jl b/test/template.jl index a865ad42..538f8557 100644 --- a/test/template.jl +++ b/test/template.jl @@ -5,11 +5,15 @@ @testset "user" begin msg = sprint(showerror, PT.MissingUserException{TravisCI}()) @test startswith(msg, "TravisCI: ") - mock(PT.default_user => () -> "") do _du + + patch = @patch PkgTemplates.getkw!(kwargs, k) = "" + apply(patch) do @test_throws PT.MissingUserException Template() @test isempty(Template(; plugins=[!Git]).user) end - mock(PT.default_user => () -> "username") do _du + + patch = @patch PkgTemplates.getkw!(kwargs, k) = "username" + apply(patch) do @test Template().user == "username" end end @@ -76,7 +80,9 @@ foreach((GitHubActions, TravisCI, GitLabCI)) do T @test_throws ArgumentError tpl(; plugins=[Documenter{T}()]) end - mock(LibGit2.getconfig => (_k, _d) -> "") do _gc + + patch = @patch LibGit2.getconfig(r, n) = "" + apply(patch) do @test_throws ArgumentError tpl(; plugins=[Git()]) end end @@ -95,7 +101,9 @@ end t = tpl() pkg = pkgname() - mock(LibGit2.init => dir -> (@test isdir(dir); error())) do _init + + patch = @patch LibGit2.init(pkg_dir) = error() + apply(patch) do @test_throws ErrorException @suppress t(pkg) end @test !isdir(joinpath(t.dir, pkg)) From 2b2482a63548db3400d1e1fef5c0d52dda1ed3eb Mon Sep 17 00:00:00 2001 From: Mary Jo Ramos Date: Thu, 17 Jun 2021 15:41:28 -0500 Subject: [PATCH 3/5] Update interactive tests to use Mocking --- src/template.jl | 2 +- test/interactive.jl | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/template.jl b/src/template.jl index c5232718..cd5eebd5 100644 --- a/src/template.jl +++ b/src/template.jl @@ -216,7 +216,7 @@ end prompt(::Type{Template}, ::Type, ::Val{:pkg}) = Base.prompt("Package name") function prompt(::Type{Template}, ::Type, ::Val{:user}) - return if isempty(default_user()) + return if isempty(@mock default_user()) input = Base.prompt("Enter value for 'user' (String, required)") input === nothing && throw(InterruptException()) return input diff --git a/test/interactive.jl b/test/interactive.jl index 53543289..77b76f1f 100644 --- a/test/interactive.jl +++ b/test/interactive.jl @@ -237,7 +237,9 @@ end DONE, # Customize nothing "username", LF, # Enter user after it's prompted ) - mock(PT.default_user => () -> "") do _du + + patch = @patch PkgTemplates.default_user() = "" + apply(patch) do @test Template(; interactive=true) == Template(; user="username") end end From 68fcf7278925403435d059319dedfa7154871688 Mon Sep 17 00:00:00 2001 From: Mary Jo Ramos Date: Thu, 17 Jun 2021 15:47:11 -0500 Subject: [PATCH 4/5] Update git tests to use Mocking --- src/plugins/git.jl | 2 +- test/git.jl | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/git.jl b/src/plugins/git.jl index 90911efd..b1f65b72 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -108,7 +108,7 @@ function posthook(p::Git, ::Template, pkg_dir::AbstractString) LibGit2.with(GitRepo(pkg_dir)) do repo LibGit2.add!(repo, ".") msg = "Files generated by PkgTemplates" - v = version_of("PkgTemplates") + v = @mock version_of("PkgTemplates") v === nothing || (msg *= "\n\nPkgTemplates version: $v") # TODO: Put the template config in the message too? commit(p, repo, pkg_dir, msg) diff --git a/test/git.jl b/test/git.jl index b5805203..7b5bfbb2 100644 --- a/test/git.jl +++ b/test/git.jl @@ -69,7 +69,9 @@ @testset "Adds version to commit message" begin # We're careful to avoid a Pkg.update as it triggers Cassette#130. t = tpl(; plugins=[Git(), !Tests]) - mock(PT.version_of => _p -> v"1.2.3") do _i + + patch = @patch PkgTemplates.version_of(t) = v"1.2.3" + apply(patch) do with_pkg(t) do pkg pkg_dir = joinpath(t.dir, pkg) LibGit2.with(GitRepo(pkg_dir)) do repo From 7f6882dfc0fd452cd9f67022146f443cfb7da9e7 Mon Sep 17 00:00:00 2001 From: Mary Jo Ramos Date: Thu, 17 Jun 2021 15:47:44 -0500 Subject: [PATCH 5/5] Set version to 0.7.17 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index eb3e5877..b10b75f2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PkgTemplates" uuid = "14b8a8f1-9102-5b29-a752-f990bacb7fe1" authors = ["Chris de Graaf", "Invenia Technical Computing Corporation"] -version = "0.7.16" +version = "0.7.17" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"