Skip to content

Commit

Permalink
Actually throw PkgErrors, add Pkg error tests
Browse files Browse the repository at this point in the history
Fix MethodError from giving too many inputs to PkgError

Add an unsatisfiable REQUIRES test

Add tests for Pkg.pin error cases

Adjust comment for issue number in a test
  • Loading branch information
tkelman committed Oct 2, 2015
1 parent bcd744d commit 9d368d4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
10 changes: 1 addition & 9 deletions base/pkg/dir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@ function cd(f::Function, args...; kws...)
!haskey(ENV,"JULIA_PKGDIR") ? init() :
throw(PkgError("Package metadata directory $metadata_dir doesn't exist; run Pkg.init() to initialize it."))
end
try
Base.cd(()->f(args...; kws...), dir)
catch err
if isa(err, PkgError)
print_with_color(:red, "ERROR: $(err.msg)")
else
throw(err)
end
end
Base.cd(()->f(args...; kws...), dir)
end

function init(meta::AbstractString=DEFAULT_META, branch::AbstractString=META_BRANCH)
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ function resolve(
for pkg in keys(reqs)
if !haskey(deps,pkg)
if "julia" in conflicts[pkg]
throw(PkgError("$pkg can't be installed because it has no versions that support ", VERSION, " of julia. " *
throw(PkgError("$pkg can't be installed because it has no versions that support $VERSION of julia. " *
"You may need to update METADATA by running `Pkg.update()`"))
else
sconflicts = join(conflicts[pkg], ", ", " and ")
Expand Down
41 changes: 39 additions & 2 deletions test/pkg.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

import Base.Pkg.PkgError

function temp_pkg_dir(fn::Function)
# Used in tests below to setup and teardown a sandboxed package directory
const tmpdir = ENV["JULIA_PKGDIR"] = joinpath(tempdir(),randstring())
Expand Down Expand Up @@ -42,7 +44,6 @@ temp_pkg_dir() do
Pkg.rm("Example")
@test isempty(Pkg.installed())
@test !isempty(Pkg.available("Example"))
@test Pkg.available("IDoNotExist") === nothing
Pkg.clone("https://github.com/JuliaLang/Example.jl.git")
@test [keys(Pkg.installed())...] == ["Example"]
Pkg.status("Example", iob)
Expand All @@ -60,6 +61,40 @@ temp_pkg_dir() do
@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
Pkg.add("REPL")
error("unexpected")
catch err
@test isa(err.exceptions[1].ex, PkgError)
@test err.exceptions[1].ex.msg == "REPL can't be installed because " *
"it has no versions that support $VERSION of julia. You may " *
"need to update METADATA by running `Pkg.update()`"
end

# trying to add, check availability, or pin a nonexistent package errors
try
Pkg.add("NonexistentPackage")
error("unexpected")
catch err
@test isa(err.exceptions[1].ex, PkgError)
@test err.exceptions[1].ex.msg == "unknown package NonexistentPackage"
end
try
Pkg.available("NonexistentPackage")
error("unexpected")
catch err
@test isa(err, PkgError)
@test err.msg == "NonexistentPackage is not a package (not registered or installed)"
end
try
Pkg.pin("NonexistentPackage", v"1.0.0")
error("unexpected")
catch err
@test isa(err, PkgError)
@test err.msg == "NonexistentPackage is not a git repo"
end
end

# testing a package with test dependencies causes them to be installed for the duration of the test
Expand Down Expand Up @@ -96,6 +131,7 @@ temp_pkg_dir() do

try
Pkg.test("PackageWithNoTests")
error("unexpected")
catch err
@test err.msg == "PackageWithNoTests did not provide a test/runtests.jl file"
end
Expand All @@ -113,6 +149,7 @@ temp_pkg_dir() do

try
Pkg.test("PackageWithFailingTests")
error("unexpected")
catch err
@test err.msg == "PackageWithFailingTests had test errors"
end
Expand Down Expand Up @@ -165,7 +202,7 @@ end"""
end
end

# issue #13373
# issue #13374
temp_pkg_dir() do
Pkg.generate("Foo", "MIT")
Pkg.tag("Foo")
Expand Down

0 comments on commit 9d368d4

Please sign in to comment.