Skip to content

Commit

Permalink
Base testing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
montyvesselinov committed May 14, 2017
1 parent 7383322 commit 27dc55b
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions test/runtests.jl
@@ -1,22 +1,39 @@
import RobustPmap
import Base.Test

if !isdefined(Symbol("@stderrcapture"))
macro stderrcapture(block)
quote
if ccall(:jl_generating_output, Cint, ()) == 0
errororiginal = STDERR;
(errR, errW) = redirect_stderr();
errorreader = @async readstring(errR);
evalvalue = $(esc(block))
redirect_stderr(errororiginal);
close(errW);
close(errR);
return evalvalue
end
end
end
end

procschage = false
if nworkers() < 2
procschage = true
addprocs(2)
end
@everywhere f1(x) = x > 0 ? 1 : 1.
function testtypecheck()
@stderrcapture @everywhere f1(x) = x > 0 ? 1 : 1.
@stderrcapture function testtypecheck()
@Base.Test.test_throws TypeError RobustPmap.rpmap(f1, [-1, 0, 1]; t=Int)
end
function testworks()
@stderrcapture function testworks()
@Base.Test.test RobustPmap.rpmap(f1, [-1, 0, 1]) == Any[1., 1., 1]
end
function testparallel()
@stderrcapture function testparallel()
@Base.Test.test length(unique(RobustPmap.rpmap(i->myid(), 1:2))) != 1
end
function testcheckpoint()
@stderrcapture function testcheckpoint()
result = RobustPmap.crpmap(x->x, 2, joinpath(pwd(), "test"), [-1, 0, 1]; t=Int)
result2 = RobustPmap.crpmap(x->pi, 2, joinpath(pwd(), "test"), [-1, 0, 1]; t=Int)#test it with a different function to make sure it loads from the checkpoints
rm(joinpath(pwd(), string("test", "_", hash(([-1, 0, 1],)), "_1.jld")))
Expand All @@ -33,14 +50,17 @@ function testcheckpoint()
@Base.Test.test result == RobustPmap.rpmap((x, y)->x + y, x, y; t=Float64)
@Base.Test.test result == result2
end
testtypecheck()
testworks()
testparallel()
testcheckpoint()
function onlyonproc1(x)
@stderrcapture function onlyonproc1(x)
return x
end
@Base.Test.test_throws RemoteException RobustPmap.rpmap(onlyonproc1, 1:10)

@Base.Test.testset "RobustPmap" begin
testtypecheck()
testworks()
testparallel()
testcheckpoint()
@Base.Test.test_throws RemoteException RobustPmap.rpmap(onlyonproc1, 1:10)
end
if procschage
rmprocs(workers())
end
Expand Down

0 comments on commit 27dc55b

Please sign in to comment.