Skip to content

Commit

Permalink
test/read/jl: close temporary test streams
Browse files Browse the repository at this point in the history
  • Loading branch information
samoconnor committed Jan 17, 2016
1 parent 69f1587 commit 680573e
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions test/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 680573e

Please sign in to comment.