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

(cherry picked from commit 3a57ccb)
  • Loading branch information
tkelman committed Oct 3, 2015
1 parent 1931681 commit 778c5d9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
6 changes: 3 additions & 3 deletions base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ pin(pkg::AbstractString) = pin(pkg,Git.head(dir=pkg))

function pin(pkg::AbstractString, ver::VersionNumber)
ispath(pkg,".git") || error("$pkg is not a git repo")
Read.isinstalled(pkg) || error("$pkg cannot be pinned – not an installed package".tmp)
Read.isinstalled(pkg) || error("$pkg cannot be pinned – not an installed package")
avail = Read.available(pkg)
isempty(avail) && error("$pkg cannot be pinned – not a registered package".tmp)
isempty(avail) && error("$pkg cannot be pinned – not a registered package")
haskey(avail,ver) || error("$pkg$ver is not a registered version")
pin(pkg,avail[ver].sha1)
pin(pkg, avail[ver].sha1)
end

function update(branch::AbstractString)
Expand Down
29 changes: 27 additions & 2 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,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 @@ -89,6 +87,25 @@ temp_pkg_dir() do
catch err
@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 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 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 @@ -113,6 +130,14 @@ 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 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 778c5d9

Please sign in to comment.