From 52d940e24b7268d3114d15cbc4e4320fc3201c9e Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Fri, 2 Oct 2015 01:48:42 -0400 Subject: [PATCH 1/4] Fix indentation in pkg and replcompletions tests --- test/pkg.jl | 240 ++++++++++++++++++++-------------------- test/replcompletions.jl | 20 ++-- 2 files changed, 130 insertions(+), 130 deletions(-) diff --git a/test/pkg.jl b/test/pkg.jl index 794442d4e9e3c..e2f74d8ca86d4 100644 --- a/test/pkg.jl +++ b/test/pkg.jl @@ -1,128 +1,128 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license 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()) - @test !isdir(Pkg.dir()) - try - Pkg.init() - @test isdir(Pkg.dir()) - Pkg.resolve() - - fn() - finally - rm(tmpdir, recursive=true) - end + # Used in tests below to setup and teardown a sandboxed package directory + const tmpdir = ENV["JULIA_PKGDIR"] = joinpath(tempdir(),randstring()) + @test !isdir(Pkg.dir()) + try + Pkg.init() + @test isdir(Pkg.dir()) + Pkg.resolve() + + fn() + finally + rm(tmpdir, recursive=true) + end end # Test basic operations: adding or removing a package, status, free #Also test for the existence of REQUIRE and META_Branch temp_pkg_dir() do - @test isfile(joinpath(Pkg.dir(),"REQUIRE")) - @test isfile(joinpath(Pkg.dir(),"META_BRANCH")) - @test isempty(Pkg.installed()) - Pkg.add("Example") - @test [keys(Pkg.installed())...] == ["Example"] - iob = IOBuffer() - Pkg.checkout("Example") - Pkg.status("Example", iob) - str = chomp(takebuf_string(iob)) - @test startswith(str, " - Example") - @test endswith(str, "master") - Pkg.free("Example") - Pkg.status("Example", iob) - str = chomp(takebuf_string(iob)) - @test endswith(str, string(Pkg.installed("Example"))) - Pkg.checkout("Example") - Pkg.free(("Example",)) - Pkg.status("Example", iob) - str = chomp(takebuf_string(iob)) - @test endswith(str, string(Pkg.installed("Example"))) - 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) - str = chomp(takebuf_string(iob)) - @test startswith(str, " - Example") - @test endswith(str, "master") - Pkg.free("Example") - Pkg.status("Example", iob) - str = chomp(takebuf_string(iob)) - @test endswith(str, string(Pkg.installed("Example"))) - Pkg.checkout("Example") - Pkg.free(("Example",)) - Pkg.status("Example", iob) - str = chomp(takebuf_string(iob)) - @test endswith(str, string(Pkg.installed("Example"))) - Pkg.rm("Example") - @test isempty(Pkg.installed()) + @test isfile(joinpath(Pkg.dir(),"REQUIRE")) + @test isfile(joinpath(Pkg.dir(),"META_BRANCH")) + @test isempty(Pkg.installed()) + Pkg.add("Example") + @test [keys(Pkg.installed())...] == ["Example"] + iob = IOBuffer() + Pkg.checkout("Example") + Pkg.status("Example", iob) + str = chomp(takebuf_string(iob)) + @test startswith(str, " - Example") + @test endswith(str, "master") + Pkg.free("Example") + Pkg.status("Example", iob) + str = chomp(takebuf_string(iob)) + @test endswith(str, string(Pkg.installed("Example"))) + Pkg.checkout("Example") + Pkg.free(("Example",)) + Pkg.status("Example", iob) + str = chomp(takebuf_string(iob)) + @test endswith(str, string(Pkg.installed("Example"))) + 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) + str = chomp(takebuf_string(iob)) + @test startswith(str, " - Example") + @test endswith(str, "master") + Pkg.free("Example") + Pkg.status("Example", iob) + str = chomp(takebuf_string(iob)) + @test endswith(str, string(Pkg.installed("Example"))) + Pkg.checkout("Example") + Pkg.free(("Example",)) + Pkg.status("Example", iob) + str = chomp(takebuf_string(iob)) + @test endswith(str, string(Pkg.installed("Example"))) + 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 temp_pkg_dir() do - Pkg.generate("PackageWithTestDependencies", "MIT", config=Dict("user.name"=>"Julia Test", "user.email"=>"test@julialang.org")) - @test [keys(Pkg.installed())...] == ["PackageWithTestDependencies"] - @test readall(Pkg.dir("PackageWithTestDependencies","REQUIRE")) == "julia $(Pkg.Generate.versionfloor(VERSION))\n" + Pkg.generate("PackageWithTestDependencies", "MIT", config=Dict("user.name"=>"Julia Test", "user.email"=>"test@julialang.org")) + @test [keys(Pkg.installed())...] == ["PackageWithTestDependencies"] + @test readall(Pkg.dir("PackageWithTestDependencies","REQUIRE")) == "julia $(Pkg.Generate.versionfloor(VERSION))\n" - isdir(Pkg.dir("PackageWithTestDependencies","test")) || mkdir(Pkg.dir("PackageWithTestDependencies","test")) - open(Pkg.dir("PackageWithTestDependencies","test","REQUIRE"),"w") do f - println(f,"Example") - end + isdir(Pkg.dir("PackageWithTestDependencies","test")) || mkdir(Pkg.dir("PackageWithTestDependencies","test")) + open(Pkg.dir("PackageWithTestDependencies","test","REQUIRE"),"w") do f + println(f,"Example") + end - open(Pkg.dir("PackageWithTestDependencies","test","runtests.jl"),"w") do f - println(f,"using Base.Test") - println(f,"@test haskey(Pkg.installed(), \"Example\")") - end + open(Pkg.dir("PackageWithTestDependencies","test","runtests.jl"),"w") do f + println(f,"using Base.Test") + println(f,"@test haskey(Pkg.installed(), \"Example\")") + end - Pkg.resolve() - @test [keys(Pkg.installed())...] == ["PackageWithTestDependencies"] + Pkg.resolve() + @test [keys(Pkg.installed())...] == ["PackageWithTestDependencies"] - Pkg.test("PackageWithTestDependencies") + Pkg.test("PackageWithTestDependencies") - @test [keys(Pkg.installed())...] == ["PackageWithTestDependencies"] + @test [keys(Pkg.installed())...] == ["PackageWithTestDependencies"] end # testing a package with no runtests.jl errors temp_pkg_dir() do - Pkg.generate("PackageWithNoTests", "MIT", config=Dict("user.name"=>"Julia Test", "user.email"=>"test@julialang.org")) + Pkg.generate("PackageWithNoTests", "MIT", config=Dict("user.name"=>"Julia Test", "user.email"=>"test@julialang.org")) - if isfile(Pkg.dir("PackageWithNoTests", "test", "runtests.jl")) - rm(Pkg.dir("PackageWithNoTests", "test", "runtests.jl")) - end + if isfile(Pkg.dir("PackageWithNoTests", "test", "runtests.jl")) + rm(Pkg.dir("PackageWithNoTests", "test", "runtests.jl")) + end - try - Pkg.test("PackageWithNoTests") - catch err - @test err.msg == "PackageWithNoTests did not provide a test/runtests.jl file" - end + try + Pkg.test("PackageWithNoTests") + catch err + @test err.msg == "PackageWithNoTests did not provide a test/runtests.jl file" + end end # testing a package with failing tests errors temp_pkg_dir() do - Pkg.generate("PackageWithFailingTests", "MIT", config=Dict("user.name"=>"Julia Test", "user.email"=>"test@julialang.org")) - - isdir(Pkg.dir("PackageWithFailingTests","test")) || mkdir(Pkg.dir("PackageWithFailingTests","test")) - open(Pkg.dir("PackageWithFailingTests", "test", "runtests.jl"),"w") do f - println(f,"using Base.Test") - println(f,"@test false") - end - - try - Pkg.test("PackageWithFailingTests") - catch err - @test err.msg == "PackageWithFailingTests had test errors" - end + Pkg.generate("PackageWithFailingTests", "MIT", config=Dict("user.name"=>"Julia Test", "user.email"=>"test@julialang.org")) + + isdir(Pkg.dir("PackageWithFailingTests","test")) || mkdir(Pkg.dir("PackageWithFailingTests","test")) + open(Pkg.dir("PackageWithFailingTests", "test", "runtests.jl"),"w") do f + println(f,"using Base.Test") + println(f,"@test false") + end + + try + Pkg.test("PackageWithFailingTests") + catch err + @test err.msg == "PackageWithFailingTests had test errors" + end end # Testing with code-coverage temp_pkg_dir() do - Pkg.generate("PackageWithCodeCoverage", "MIT", config=Dict("user.name"=>"Julia Test", "user.email"=>"test@julialang.org")) + Pkg.generate("PackageWithCodeCoverage", "MIT", config=Dict("user.name"=>"Julia Test", "user.email"=>"test@julialang.org")) - src = """ + src = """ module PackageWithCodeCoverage export f1, f2, f3, untested @@ -135,34 +135,34 @@ end untested(x) = 7 end""" - linetested = [false, false, false, false, true, true, false, true, false, false] - open(Pkg.dir("PackageWithCodeCoverage", "src", "PackageWithCodeCoverage.jl"), "w") do f - println(f, src) - end - isdir(Pkg.dir("PackageWithCodeCoverage","test")) || mkdir(Pkg.dir("PackageWithCodeCoverage","test")) - open(Pkg.dir("PackageWithCodeCoverage", "test", "runtests.jl"),"w") do f - println(f,"using PackageWithCodeCoverage, Base.Test") - println(f,"@test f2(2) == 4") - println(f,"@test f3(5) == 15") - end - - Pkg.test("PackageWithCodeCoverage") - covdir = Pkg.dir("PackageWithCodeCoverage","src") - covfiles = filter!(x -> contains(x, "PackageWithCodeCoverage.jl") && contains(x,".cov"), readdir(covdir)) - @test isempty(covfiles) - Pkg.test("PackageWithCodeCoverage", coverage=true) - covfiles = filter!(x -> contains(x, "PackageWithCodeCoverage.jl") && contains(x,".cov"), readdir(covdir)) - @test !isempty(covfiles) - for file in covfiles - @test isfile(joinpath(covdir,file)) - covstr = readall(joinpath(covdir,file)) - srclines = split(src, '\n') - covlines = split(covstr, '\n') - for i = 1:length(linetested) - covline = (linetested[i] ? " 1 " : " - ")*srclines[i] - @test covlines[i] == covline - end - end + linetested = [false, false, false, false, true, true, false, true, false, false] + open(Pkg.dir("PackageWithCodeCoverage", "src", "PackageWithCodeCoverage.jl"), "w") do f + println(f, src) + end + isdir(Pkg.dir("PackageWithCodeCoverage","test")) || mkdir(Pkg.dir("PackageWithCodeCoverage","test")) + open(Pkg.dir("PackageWithCodeCoverage", "test", "runtests.jl"),"w") do f + println(f,"using PackageWithCodeCoverage, Base.Test") + println(f,"@test f2(2) == 4") + println(f,"@test f3(5) == 15") + end + + Pkg.test("PackageWithCodeCoverage") + covdir = Pkg.dir("PackageWithCodeCoverage","src") + covfiles = filter!(x -> contains(x, "PackageWithCodeCoverage.jl") && contains(x,".cov"), readdir(covdir)) + @test isempty(covfiles) + Pkg.test("PackageWithCodeCoverage", coverage=true) + covfiles = filter!(x -> contains(x, "PackageWithCodeCoverage.jl") && contains(x,".cov"), readdir(covdir)) + @test !isempty(covfiles) + for file in covfiles + @test isfile(joinpath(covdir,file)) + covstr = readall(joinpath(covdir,file)) + srclines = split(src, '\n') + covlines = split(covstr, '\n') + for i = 1:length(linetested) + covline = (linetested[i] ? " 1 " : " - ")*srclines[i] + @test covlines[i] == covline + end + end end # issue #13373 diff --git a/test/replcompletions.jl b/test/replcompletions.jl index 4a0e2bb060526..7e9f55e7ae305 100644 --- a/test/replcompletions.jl +++ b/test/replcompletions.jl @@ -37,16 +37,16 @@ module CompletionFoo end 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()) - @test !isdir(Pkg.dir()) - try - mkpath(Pkg.dir()) - @test isdir(Pkg.dir()) - fn() - finally - rm(tmpdir, recursive=true) - end + # Used in tests below to setup and teardown a sandboxed package directory + const tmpdir = ENV["JULIA_PKGDIR"] = joinpath(tempdir(),randstring()) + @test !isdir(Pkg.dir()) + try + mkpath(Pkg.dir()) + @test isdir(Pkg.dir()) + fn() + finally + rm(tmpdir, recursive=true) + end end test_complete(s) = completions(s,endof(s)) From bcd744dc7aa1be3f1c59ffe44727b3715034fa88 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Fri, 2 Oct 2015 02:38:04 -0400 Subject: [PATCH 2/4] Add error("unexpected") in try-catches that should fail --- test/backtrace.jl | 2 ++ test/misc.jl | 1 + test/parallel.jl | 2 ++ test/unicode/utf32.jl | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/backtrace.jl b/test/backtrace.jl index c33bcd65ad8d3..19c0f4f17eeeb 100644 --- a/test/backtrace.jl +++ b/test/backtrace.jl @@ -39,6 +39,7 @@ eval(Expr(:function, Expr(:call, :test_inline_2), try eval(:(test_inline_1())) + error("unexpected") catch err lkup = get_bt_frame(:test_inline_1, catch_backtrace()) if is(lkup, nothing) @@ -51,6 +52,7 @@ catch err end try eval(:(test_inline_2())) + error("unexpected") catch err lkup = get_bt_frame(:test_inline_2, catch_backtrace()) if is(lkup, nothing) diff --git a/test/misc.jl b/test/misc.jl index b605fd6f2f1cd..2c76e387ace96 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -94,6 +94,7 @@ let deepthought(x, y) = 42 try @assert 1 == 2 string("the answer to the ultimate question: ", deepthought(6, 9)) + error("unexpected") catch ex @test isa(ex, AssertionError) @test ex.msg == "the answer to the ultimate question: 42" diff --git a/test/parallel.jl b/test/parallel.jl index 8d5d14cfa9b1a..dc4a01a8e58c8 100644 --- a/test/parallel.jl +++ b/test/parallel.jl @@ -383,6 +383,7 @@ try @async error(i) end end + error("unexpected") catch ex @test typeof(ex) == CompositeException @test length(ex) == 5 @@ -394,6 +395,7 @@ end try remotecall_fetch(()->throw(ErrorException("foobar")), id_other) + error("unexpected") catch ex @test typeof(ex) == RemoteException @test typeof(ex.captured) == CapturedException diff --git a/test/unicode/utf32.jl b/test/unicode/utf32.jl index 2b9488a024e07..53e7de500ed3e 100644 --- a/test/unicode/utf32.jl +++ b/test/unicode/utf32.jl @@ -163,7 +163,7 @@ for T in (UTF8String, UTF16String, UTF32String) # Lead followed by non-continuation character > 0xbf @test_throws UnicodeError convert(T, strval(T, UInt8[byt,0x80,0x80,0xc0])) end - catch exp ; + catch exp println("Error checking $T: $byt") throw(exp) end From 9d368d4fdb3b5634a638ed388ebea982d371dd92 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Fri, 2 Oct 2015 02:38:04 -0400 Subject: [PATCH 3/4] Actually throw PkgErrors, add Pkg error tests 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 --- base/pkg/dir.jl | 10 +--------- base/pkg/entry.jl | 2 +- test/pkg.jl | 41 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/base/pkg/dir.jl b/base/pkg/dir.jl index 4925eee06640f..7566f6ec2c9ad 100644 --- a/base/pkg/dir.jl +++ b/base/pkg/dir.jl @@ -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) diff --git a/base/pkg/entry.jl b/base/pkg/entry.jl index b9de6dd87269a..0e767fd0aa4a2 100644 --- a/base/pkg/entry.jl +++ b/base/pkg/entry.jl @@ -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 ") diff --git a/test/pkg.jl b/test/pkg.jl index e2f74d8ca86d4..d60c7bfd776ab 100644 --- a/test/pkg.jl +++ b/test/pkg.jl @@ -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()) @@ -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) @@ -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 @@ -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 @@ -113,6 +149,7 @@ temp_pkg_dir() do try Pkg.test("PackageWithFailingTests") + error("unexpected") catch err @test err.msg == "PackageWithFailingTests had test errors" end @@ -165,7 +202,7 @@ end""" end end -# issue #13373 +# issue #13374 temp_pkg_dir() do Pkg.generate("Foo", "MIT") Pkg.tag("Foo") From 3a57ccbc21e3543379055573b5e711630f83bff0 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Fri, 2 Oct 2015 04:09:42 -0400 Subject: [PATCH 4/4] Remove extraneous .tmp in Pkg.pin error paths and add corresponding tests --- base/pkg/entry.jl | 4 ++-- test/pkg.jl | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/base/pkg/entry.jl b/base/pkg/entry.jl index 0e767fd0aa4a2..ef6d561b99d56 100644 --- a/base/pkg/entry.jl +++ b/base/pkg/entry.jl @@ -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 diff --git a/test/pkg.jl b/test/pkg.jl index d60c7bfd776ab..a40fc31dd315f 100644 --- a/test/pkg.jl +++ b/test/pkg.jl @@ -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 @@ -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 @@ -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