Skip to content

Commit

Permalink
Fix indentation in pkg and replcompletions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tkelman committed Oct 2, 2015
1 parent 26b58c6 commit 52d940e
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 130 deletions.
240 changes: 120 additions & 120 deletions test/pkg.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 52d940e

Please sign in to comment.