From 680573ecfcbd11fe08b7e1a9d80d6ad33c8bec91 Mon Sep 17 00:00:00 2001 From: Sam O'Connor Date: Mon, 18 Jan 2016 08:22:19 +1100 Subject: [PATCH] test/read/jl: close temporary test streams --- test/read.jl | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/test/read.jl b/test/read.jl index 7c8cb68b80ff51..8923d955ab6255 100644 --- a/test/read.jl +++ b/test/read.jl @@ -13,22 +13,28 @@ l = Vector{Tuple{AbstractString,Function}}() # File io = ()->Base.Filesystem.open(filename, Base.Filesystem.JL_O_RDONLY) -@test isa(io(), IO) -@test isa(io(), Base.Filesystem.File) +s = io() +@test isa(s, IO) +@test isa(s, Base.Filesystem.File) +close(s) push!(l, ("File", io)) # IOStream io = ()->open(filename) -@test isa(io(), IO) -@test isa(io(), IOStream) +s = io() +@test isa(s, IO) +@test isa(s, IOStream) +close(s) push!(l, ("IOStream", io)) # IOBuffer io = ()->IOBuffer(text) -@test isa(io(), IO) -@test isa(io(), IOBuffer) +s = io() +@test isa(s, IO) +@test isa(s, IOBuffer) +close(s) push!(l, ("IOBuffer", io)) @windows ? nothing : begin @@ -38,31 +44,42 @@ socketname = joinpath(dir, "socket") io = ()-> begin c = Base.Condition() tsk = @async begin - s = listen(socketname) + con = listen(socketname) Base.notify(c) - sock = accept(s) + sock = accept(con) write(sock,text) - close(s) + close(con) close(sock) end push!(tasks, tsk) wait(c) connect(socketname) end -@test isa(io(), IO) -@test isa(io(), Base.PipeEndpoint) +s = io() +@test isa(s, IO) +@test isa(s, Base.PipeEndpoint) +close(s) +for tsk in tasks + wait(tsk) +end push!(l, ("PipeEndpoint", io)) # Pipe io = () -> open(`echo -n $text`)[1] -@test isa(io(), IO) -@test isa(io(), Pipe) +s = io() +@test isa(s, IO) +@test isa(s, Pipe) +close(s) push!(l, ("Pipe", io)) end -for (name, io) in l +open_streams = [] + +for (name, f) in l + + io = ()->(s=f(); push!(open_streams, s); s) #println("$name readall...") @test readall(io()) == text @@ -149,6 +166,10 @@ for (name, io) in l end end +for s in open_streams + try close(s) end +end + for tsk in tasks wait(tsk) end