Skip to content

Commit

Permalink
Remove extraneous .tmp in Pkg.pin error paths
Browse files Browse the repository at this point in the history
and add corresponding tests
  • Loading branch information
tkelman committed Oct 2, 2015
1 parent 9d368d4 commit 3a57ccb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ pin(pkg::AbstractString) = pin(pkg, "")

function pin(pkg::AbstractString, ver::VersionNumber)
ispath(pkg,".git") || throw(PkgError("$pkg is not a git repo"))
Read.isinstalled(pkg) || throw(PkgError("$pkg cannot be pinned – not an installed package".tmp))
Read.isinstalled(pkg) || throw(PkgError("$pkg cannot be pinned – not an installed package"))
avail = Read.available(pkg)
isempty(avail) && throw(PkgError("$pkg cannot be pinned – not a registered package".tmp))
isempty(avail) && throw(PkgError("$pkg cannot be pinned – not a registered package"))
haskey(avail,ver) || throw(PkgError("$pkg$ver is not a registered version"))
pin(pkg, avail[ver].sha1)
end
Expand Down
32 changes: 30 additions & 2 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ temp_pkg_dir() do
Pkg.status("Example", iob)
str = chomp(takebuf_string(iob))
@test endswith(str, string(Pkg.installed("Example")))
Pkg.rm("Example")
@test isempty(Pkg.installed())

# adding a package with unsatisfiable julia version requirements (REPL.jl) errors
try
Expand Down Expand Up @@ -95,6 +93,27 @@ temp_pkg_dir() do
@test isa(err, PkgError)
@test err.msg == "NonexistentPackage is not a git repo"
end

# trying to pin a git repo under Pkg.dir that is not an installed package errors
try
Pkg.pin("METADATA", v"1.0.0")
error("unexpected")
catch err
@test isa(err, PkgError)
@test err.msg == "METADATA cannot be pinned – not an installed package"
end

# trying to pin an installed, registered package to an unregistered version errors
try
Pkg.pin("Example", v"2147483647.0.0")
error("unexpected")
catch err
@test isa(err, PkgError)
@test err.msg == "Example – 2147483647.0.0 is not a registered version"
end

Pkg.rm("Example")
@test isempty(Pkg.installed())
end

# testing a package with test dependencies causes them to be installed for the duration of the test
Expand All @@ -119,6 +138,15 @@ temp_pkg_dir() do
Pkg.test("PackageWithTestDependencies")

@test [keys(Pkg.installed())...] == ["PackageWithTestDependencies"]

# trying to pin an unregistered package errors
try
Pkg.pin("PackageWithTestDependencies", v"1.0.0")
error("unexpected")
catch err
@test isa(err, PkgError)
@test err.msg == "PackageWithTestDependencies cannot be pinned – not a registered package"
end
end

# testing a package with no runtests.jl errors
Expand Down

0 comments on commit 3a57ccb

Please sign in to comment.