diff --git a/base/LineEdit.jl b/base/LineEdit.jl
index 72833ea4204a3..b594427d920a9 100644
--- a/base/LineEdit.jl
+++ b/base/LineEdit.jl
@@ -990,7 +990,7 @@ function write_response_buffer(s::PromptState, data)
offset = s.input_buffer.ptr
ptr = data.response_buffer.ptr
seek(data.response_buffer, 0)
- write(s.input_buffer, readall(data.response_buffer))
+ write(s.input_buffer, readstring(data.response_buffer))
s.input_buffer.ptr = offset + ptr - 2
data.response_buffer.ptr = ptr
refresh_line(s)
@@ -1129,7 +1129,7 @@ function refresh_multi_line(termbuf::TerminalBuffer, s::SearchState)
offset = buf.ptr
ptr = s.response_buffer.ptr
seek(s.response_buffer, 0)
- write(buf, readall(s.response_buffer))
+ write(buf, readstring(s.response_buffer))
buf.ptr = offset + ptr - 1
s.response_buffer.ptr = ptr
s.ias = refresh_multi_line(termbuf, s.terminal, buf, s.ias, s.backward ? "(reverse-i-search)`" : "(forward-i-search)`")
diff --git a/base/base64.jl b/base/base64.jl
index fa99370691423..90f0cde3514be 100644
--- a/base/base64.jl
+++ b/base/base64.jl
@@ -200,7 +200,7 @@ close(b::Base64DecodePipe) = nothing
function base64decode(s)
b = IOBuffer(s)
try
- return readbytes(Base64DecodePipe(b))
+ return read(Base64DecodePipe(b))
finally
close(b)
end
diff --git a/base/client.jl b/base/client.jl
index 70aacb8610913..7864124718b14 100644
--- a/base/client.jl
+++ b/base/client.jl
@@ -263,7 +263,7 @@ end
function load_machine_file(path::AbstractString)
machines = []
- for line in split(readall(path),'\n'; keep=false)
+ for line in split(readstring(path),'\n'; keep=false)
s = map!(strip, split(line,'*'; keep=false))
if length(s) > 1
cnt = isnumber(s[1]) ? parse(Int,s[1]) : symbol(s[1])
@@ -331,7 +331,7 @@ function _start()
# note: currently IOStream is used for file STDIN
if isa(STDIN,File) || isa(STDIN,IOStream)
# reading from a file, behave like include
- eval(Main,parse_input_line(readall(STDIN)))
+ eval(Main,parse_input_line(readstring(STDIN)))
else
# otherwise behave repl-like
while !eof(STDIN)
diff --git a/base/datafmt.jl b/base/datafmt.jl
index 7d1448ccf9ed1..deda884281ce7 100644
--- a/base/datafmt.jl
+++ b/base/datafmt.jl
@@ -46,11 +46,11 @@ function readdlm_auto(input, dlm::Char, T::Type, eol::Char, auto::Bool; opts...)
if use_mmap && fsz > 0 && fsz < typemax(Int)
input = as_mmap(input, fsz)
else
- input = readall(input)
+ input = readstring(input)
end
end
sinp = isa(input, Vector{UInt8}) ? bytestring(input) :
- isa(input, IO) ? readall(input) :
+ isa(input, IO) ? readstring(input) :
input
readdlm_string(sinp, dlm, T, eol, auto, optsd)
end
diff --git a/base/deprecated.jl b/base/deprecated.jl
index ab5528f265ded..13cab4b5a14c5 100644
--- a/base/deprecated.jl
+++ b/base/deprecated.jl
@@ -961,4 +961,9 @@ macro boundscheck(yesno,blk)
end
end
+
@deprecate parseip(str::AbstractString) parse(IPAddr, str)
+
+#https://github.com/JuliaLang/julia/issues/14608
+@deprecate readall readstring
+@deprecate readbytes read
diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl
index a2a826c3a1a4d..3cc849c04f792 100644
--- a/base/docs/helpdb/Base.jl
+++ b/base/docs/helpdb/Base.jl
@@ -48,9 +48,9 @@ the same object. `fill!(A, Foo())` will return `A` filled with the result of eva
fill!
"""
- read!(stream, array::Array)
+ read!(stream or filename, array::Array)
-Read binary data from a stream, filling in the argument `array`.
+Read binary data from a stream or file, filling in the argument `array`.
"""
read!
@@ -452,7 +452,7 @@ the mantissa.
precision
"""
- readlines(stream)
+ readlines(stream or filename)
Read all lines as an array.
"""
@@ -1018,7 +1018,7 @@ See `rounding` for available rounding modes.
Float32
"""
- readuntil(stream, delim)
+ readuntil(stream or filename, delim)
Read a string, up to and including the given delimiter byte.
"""
@@ -2054,7 +2054,7 @@ open(file_name, mode="r")
Apply the function `f` to the result of `open(args...)` and close the resulting file
descriptor upon completion.
-**Example**: `open(readall, "file.txt")`
+**Example**: `open(readstring, "file.txt")`
"""
open(f::Function, args...)
@@ -2438,19 +2438,11 @@ the process.
triu!(M, k)
"""
- readall(stream::IO)
+ readstring(stream or filename)
-Read the entire contents of an I/O stream as a string.
+Read the entire contents of an I/O stream or a file as a string.
"""
-readall(stream::IO)
-
-"""
- readall(filename::AbstractString)
-
-Open `filename`, read the entire contents as a string, then close the file. Equivalent to
-`open(readall, filename)`.
-"""
-readall(filename::AbstractString)
+readstring
"""
poll_file(path, interval_s::Real, timeout_s::Real) -> (previous::StatStruct, current::StatStruct)
@@ -2468,9 +2460,9 @@ it is more reliable and efficient, although in some situations it may not be ava
poll_file
"""
- eachline(stream)
+ eachline(stream or filename)
-Create an iterable object that will yield each line from a stream.
+Create an iterable object that will yield each line.
"""
eachline
@@ -4244,9 +4236,9 @@ Squared absolute value of `x`.
abs2
"""
- write(stream, x)
+ write(stream or filename, x)
-Write the canonical binary representation of a value to the given stream. Returns the number
+Write the canonical binary representation of a value to the given stream or file. Returns the number
of bytes written into the stream.
You can write multiple values with the same :func:`write` call. i.e. the following are
@@ -6391,7 +6383,7 @@ besselk
"""
readchomp(x)
-Read the entirety of `x` as a string but remove trailing newlines. Equivalent to `chomp(readall(x))`.
+Read the entirety of `x` as a string but remove trailing newlines. Equivalent to `chomp(readstring(x))`.
"""
readchomp
@@ -6436,7 +6428,7 @@ asecd
Read at most `nb` bytes from the stream into `b`, returning the number of bytes read
(increasing the size of `b` as needed).
-See `readbytes` for a description of the `all` option.
+See `read` for a description of the `all` option.
"""
readbytes!
@@ -7416,10 +7408,10 @@ Return the supertype of DataType `T`.
supertype
"""
- readline(stream=STDIN)
+ readline(stream=STDIN or filename)
Read a single line of text, including a trailing newline character (if one is reached before
-the end of the input), from the given `stream` (defaults to `STDIN`),
+the end of the input), from the given stream or file (defaults to `STDIN`),
"""
readline
@@ -10253,7 +10245,7 @@ a series of integer arguments.
cell
"""
- readbytes(stream, nb=typemax(Int); all=true)
+ read(stream, nb=typemax(Int); all=true)
Read at most `nb` bytes from the stream, returning a `Vector{UInt8}` of the bytes read.
@@ -10262,7 +10254,7 @@ requested bytes, until an error or end-of-file occurs. If `all` is `false`, at m
`read` call is performed, and the amount of data returned is device-dependent. Note that not
all stream types support the `all` option.
"""
-readbytes
+read
"""
eig(A,[irange,][vl,][vu,][permute=true,][scale=true]) -> D, V
diff --git a/base/exports.jl b/base/exports.jl
index b3d9b5ab285b9..0ac0b168b6583 100644
--- a/base/exports.jl
+++ b/base/exports.jl
@@ -1165,10 +1165,9 @@ export
RawFD,
read,
read!,
- readall,
+ readstring,
readavailable,
readbytes!,
- readbytes,
readchomp,
readcsv,
readdir,
diff --git a/base/filesystem.jl b/base/filesystem.jl
index 118a0211a5242..a6f032ee95844 100644
--- a/base/filesystem.jl
+++ b/base/filesystem.jl
@@ -39,7 +39,7 @@ export File,
S_IROTH, S_IWOTH, S_IXOTH, S_IRWXO
import Base: uvtype, uvhandle, eventloop, fd, position, stat, close,
- write, read, read!, readbytes, isopen, show,
+ write, read, read!, isopen, show,
check_open, _sizeof_uv_fs, uv_error, UVError
include("path.jl")
@@ -172,14 +172,8 @@ function readbytes!(f::File, b::Array{UInt8}, nb=length(b))
read!(f, b, nr)
return nr
end
-readbytes(io::File) = read!(io, Array(UInt8, nb_available(io)))
-readbytes(io::File, nb) = read!(io, Array(UInt8, min(nb, nb_available(io))))
-
-function readbytes(f::File)
- a = Array(UInt8, nb_available(f))
- read!(f,a)
- return a
-end
+read(io::File) = read!(io, Array(UInt8, nb_available(io)))
+read(io::File, nb::Integer) = read!(io, Array(UInt8, min(nb, nb_available(io))))
const SEEK_SET = Int32(0)
const SEEK_CUR = Int32(1)
diff --git a/base/interactiveutil.jl b/base/interactiveutil.jl
index e64939813e3b8..857dbd9552648 100644
--- a/base/interactiveutil.jl
+++ b/base/interactiveutil.jl
@@ -93,7 +93,7 @@ less(file, line::Integer) = error("could not find source file for function")
print(io, x)
end
end
- clipboard() = readall(`pbpaste`)
+ clipboard() = readstring(`pbpaste`)
end
@linux_only begin
@@ -120,7 +120,7 @@ end
cmd = c == :xsel ? `xsel --nodetach --output --clipboard` :
c == :xclip ? `xclip -quiet -out -selection clipboard` :
error("unexpected clipboard command: $c")
- readall(pipeline(cmd, stderr=STDERR))
+ readstring(pipeline(cmd, stderr=STDERR))
end
end
@@ -181,7 +181,7 @@ function versioninfo(io::IO=STDOUT, verbose::Bool=false)
if verbose
lsb = ""
@linux_only try lsb = readchomp(pipeline(`lsb_release -ds`, stderr=DevNull)) end
- @windows_only try lsb = strip(readall(`$(ENV["COMSPEC"]) /c ver`)) end
+ @windows_only try lsb = strip(readstring(`$(ENV["COMSPEC"]) /c ver`)) end
if lsb != ""
println(io, " ", lsb)
end
@@ -416,7 +416,7 @@ function runtests(tests = ["all"], numcores = ceil(Int,CPU_CORES/2))
buf = PipeBuffer()
versioninfo(buf)
error("A test has failed. Please submit a bug report (https://github.com/JuliaLang/julia/issues)\n" *
- "including error messages above and the output of versioninfo():\n$(readall(buf))")
+ "including error messages above and the output of versioninfo():\n$(readstring(buf))")
end
end
diff --git a/base/io.jl b/base/io.jl
index a5db9f90595f8..e98ded17ffafb 100644
--- a/base/io.jl
+++ b/base/io.jl
@@ -45,7 +45,7 @@ read!(io::AbstractPipe, bytes::Vector{UInt8}) = read!(pipe_reader(io), bytes)
read{T<:AbstractPipe}(io::T, args...) = read(pipe_reader(io), args...)
read!{T<:AbstractPipe}(io::T, args...) = read!(pipe_reader(io), args...)
readuntil{T<:AbstractPipe}(io::T, args...) = readuntil(pipe_reader(io), args...)
-readbytes(io::AbstractPipe) = readbytes(pipe_reader(io))
+read(io::AbstractPipe) = read(pipe_reader(io))
readavailable(io::AbstractPipe) = readavailable(pipe_reader(io))
isreadable(io::AbstractPipe) = isreadable(pipe_reader(io))
@@ -60,6 +60,18 @@ eof(io::AbstractPipe) = eof(pipe_reader(io))
reseteof(io::AbstractPipe) = reseteof(pipe_reader(io))
+# Exception-safe wrappers (io = open(); try f(io) finally close(io))
+
+write(filename::AbstractString, args...) = open(io->write(io, args...), filename, "w")
+
+read(filename::AbstractString, args...) = open(io->read(io, args...), filename)
+read!(filename::AbstractString, a) = open(io->read!(io, a), filename)
+readstring(filename::AbstractString) = open(readstring, filename)
+readuntil(filename::AbstractString, args...) = open(io->readuntil(io, args...), filename)
+readline(filename::AbstractString) = open(readline, filename)
+readlines(filename::AbstractString) = open(readlines, filename)
+
+
## byte-order mark, ntoh & hton ##
const ENDIAN_BOM = reinterpret(UInt32,UInt8[1:4;])[1]
@@ -160,6 +172,13 @@ function write(io::IO, s::Symbol)
return write(io, pname, Int(ccall(:strlen, Csize_t, (Cstring,), pname)))
end
+function write(to::IO, from::IO)
+ while !eof(from)
+ write(to, readavailable(from))
+ end
+end
+
+
read(s::IO, ::Type{Int8}) = reinterpret(Int8, read(s,UInt8))
function read{T <: Union{Int16,UInt16,Int32,UInt32,Int64,UInt64,Int128,UInt128}}(s::IO, ::Type{T})
@@ -285,7 +304,7 @@ end
readline() = readline(STDIN)
readline(s::IO) = readuntil(s, '\n')
-readchomp(x) = chomp!(readall(x))
+readchomp(x) = chomp!(readstring(x))
# read up to nb bytes into nb, returning # bytes read
function readbytes!(s::IO, b::AbstractArray{UInt8}, nb=length(b))
@@ -307,7 +326,7 @@ function readbytes!(s::IO, b::AbstractArray{UInt8}, nb=length(b))
end
# read up to nb bytes from s, returning a Vector{UInt8} of bytes read.
-function readbytes(s::IO, nb=typemax(Int))
+function read(s::IO, nb=typemax(Int))
# Let readbytes! grow the array progressively by default
# instead of taking of risk of over-allocating
b = Array(UInt8, nb == typemax(Int) ? 1024 : nb)
@@ -315,11 +334,10 @@ function readbytes(s::IO, nb=typemax(Int))
resize!(b, nr)
end
-function readall(s::IO)
- b = readbytes(s)
+function readstring(s::IO)
+ b = read(s)
return isvalid(ASCIIString, b) ? ASCIIString(b) : UTF8String(b)
end
-readall(filename::AbstractString) = open(readall, filename)
## high-level iterator interfaces ##
@@ -330,6 +348,7 @@ type EachLine
EachLine(stream, ondone) = new(stream, ondone)
end
eachline(stream::IO) = EachLine(stream)
+eachline(filename::AbstractString) = EachLine(open(filename), close)
start(itr::EachLine) = nothing
function done(itr::EachLine, nada)
diff --git a/base/iobuffer.jl b/base/iobuffer.jl
index 3c66c7c018453..cd748862bb949 100644
--- a/base/iobuffer.jl
+++ b/base/iobuffer.jl
@@ -336,8 +336,8 @@ function readbytes!(io::AbstractIOBuffer, b::Array{UInt8}, nb=length(b))
read_sub(io, b, 1, nr)
return nr
end
-readbytes(io::AbstractIOBuffer) = read!(io, Array(UInt8, nb_available(io)))
-readbytes(io::AbstractIOBuffer, nb) = read!(io, Array(UInt8, min(nb, nb_available(io))))
+read(io::AbstractIOBuffer) = read!(io, Array(UInt8, nb_available(io)))
+read(io::AbstractIOBuffer, nb::Integer) = read!(io, Array(UInt8, min(nb, nb_available(io))))
function search(buf::IOBuffer, delim::UInt8)
p = pointer(buf.data, buf.ptr)
diff --git a/base/iostream.jl b/base/iostream.jl
index c942b5987c47a..3e3aa61ca003a 100644
--- a/base/iostream.jl
+++ b/base/iostream.jl
@@ -241,7 +241,7 @@ function readbytes!(s::IOStream, b::Array{UInt8}, nb=length(b); all::Bool=true)
return all ? readbytes_all!(s, b, nb) : readbytes_some!(s, b, nb)
end
-function readbytes(s::IOStream)
+function read(s::IOStream)
sz = 0
try # filesize is just a hint, so ignore if it fails
sz = filesize(s)
@@ -255,7 +255,7 @@ function readbytes(s::IOStream)
resize!(b, nr)
end
-function readbytes(s::IOStream, nb::Integer; all::Bool=true)
+function read(s::IOStream, nb::Integer; all::Bool=true)
b = Array(UInt8, nb)
nr = readbytes!(s, b, nb, all=all)
resize!(b, nr)
diff --git a/base/loading.jl b/base/loading.jl
index 766f2babce7e6..2529993e9e995 100644
--- a/base/loading.jl
+++ b/base/loading.jl
@@ -146,9 +146,9 @@ function _require_from_serialized(node::Int, mod::Symbol, path_to_try::ByteStrin
recompile_stale(mod, path_to_try)
# broadcast top-level import/using from node 1 (only)
if node == myid()
- content = open(readbytes, path_to_try)
+ content = open(read, path_to_try)
else
- content = remotecall_fetch(open, node, readbytes, path_to_try)
+ content = remotecall_fetch(open, node, read, path_to_try)
end
restored = _include_from_serialized(content)
if restored !== nothing
@@ -164,7 +164,7 @@ function _require_from_serialized(node::Int, mod::Symbol, path_to_try::ByteStrin
myid() == 1 && recompile_stale(mod, path_to_try)
restored = ccall(:jl_restore_incremental, Any, (Ptr{UInt8},), path_to_try)
else
- content = remotecall_fetch(open, node, readbytes, path_to_try)
+ content = remotecall_fetch(open, node, read, path_to_try)
restored = _include_from_serialized(content)
end
# otherwise, continue search
@@ -401,7 +401,7 @@ function include_from_node1(_path::AbstractString)
result = Core.include(path)
nprocs()>1 && sleep(0.005)
else
- result = include_string(remotecall_fetch(readall, 1, path), path)
+ result = include_string(remotecall_fetch(readstring, 1, path), path)
end
finally
if prev === nothing
@@ -493,14 +493,14 @@ function cache_dependencies(f::IO)
n = ntoh(read(f, Int32))
n == 0 && break
push!(modules,
- (symbol(readbytes(f, n)), # module symbol
+ (symbol(read(f, n)), # module symbol
ntoh(read(f, UInt64)))) # module UUID (timestamp)
end
read(f, Int64) # total bytes for file dependencies
while true
n = ntoh(read(f, Int32))
n == 0 && break
- push!(files, (bytestring(readbytes(f, n)), ntoh(read(f, Float64))))
+ push!(files, (bytestring(read(f, n)), ntoh(read(f, Float64))))
end
return modules, files
end
diff --git a/base/markdown/Julia/interp.jl b/base/markdown/Julia/interp.jl
index 1147a705aeb19..eecfcb09b9487 100644
--- a/base/markdown/Julia/interp.jl
+++ b/base/markdown/Julia/interp.jl
@@ -2,7 +2,7 @@
function Base.parse(stream::IO; greedy::Bool = true, raise::Bool = true)
pos = position(stream)
- ex, Δ = Base.parse(readall(stream), 1, greedy = greedy, raise = raise)
+ ex, Δ = Base.parse(readstring(stream), 1, greedy = greedy, raise = raise)
seek(stream, pos + Δ - 1)
return ex
end
diff --git a/base/markdown/Markdown.jl b/base/markdown/Markdown.jl
index 53f1824eb4b70..1ee18b218d308 100644
--- a/base/markdown/Markdown.jl
+++ b/base/markdown/Markdown.jl
@@ -23,7 +23,7 @@ include("render/terminal/render.jl")
export readme, license, @md_str, @doc_str
parse(markdown::AbstractString; flavor = julia) = parse(IOBuffer(markdown), flavor = flavor)
-parse_file(file::AbstractString; flavor = julia) = parse(readall(file), flavor = flavor)
+parse_file(file::AbstractString; flavor = julia) = parse(readstring(file), flavor = flavor)
readme(pkg::AbstractString; flavor = github) = parse_file(Pkg.dir(pkg, "README.md"), flavor = flavor)
readme(pkg::Module; flavor = github) = readme(string(pkg), flavor = flavor)
diff --git a/base/markdown/parse/util.jl b/base/markdown/parse/util.jl
index f6e43217bdc94..3eca2c9f9f794 100644
--- a/base/markdown/parse/util.jl
+++ b/base/markdown/parse/util.jl
@@ -199,7 +199,7 @@ end
function showrest(io::IO)
start = position(io)
- show(readall(io))
+ show(readstring(io))
println()
seek(io, start)
end
diff --git a/base/pkg/dir.jl b/base/pkg/dir.jl
index 9abad6c37abbf..ef38251c99f88 100644
--- a/base/pkg/dir.jl
+++ b/base/pkg/dir.jl
@@ -51,10 +51,7 @@ function init(meta::AbstractString=DEFAULT_META, branch::AbstractString=META_BRA
end
touch("REQUIRE")
touch("META_BRANCH")
- open("META_BRANCH", "w") do io
- write(io, branch)
- close(io)
- end
+ write("META_BRANCH", branch)
end
#Move TEMP to METADATA
Base.mv(joinpath(temp_dir,"METADATA"), metadata_dir)
@@ -70,9 +67,7 @@ end
function getmetabranch()
try
- open(joinpath(path(),"META_BRANCH")) do io
- chomp(readuntil(io, "/n"))
- end
+ chomp(readline(joinpath(path(),"META_BRANCH")))
catch err
META_BRANCH
end
diff --git a/base/pkg/git.jl b/base/pkg/git.jl
index 32e492f074dc1..56252125ce7bc 100644
--- a/base/pkg/git.jl
+++ b/base/pkg/git.jl
@@ -22,7 +22,7 @@ end
cmd(args::Cmd; dir="") = `$(git(dir)) $args`
run(args::Cmd; dir="", out=STDOUT) = Base.run(pipeline(cmd(args,dir=dir), out))
-readall(args::Cmd; dir="") = Base.readall(cmd(args,dir=dir))
+readstring(args::Cmd; dir="") = Base.readstring(cmd(args,dir=dir))
readchomp(args::Cmd; dir="") = Base.readchomp(cmd(args,dir=dir))
function success(args::Cmd; dir="")
diff --git a/base/pkg/read.jl b/base/pkg/read.jl
index b8a555989edb3..1a6149578438c 100644
--- a/base/pkg/read.jl
+++ b/base/pkg/read.jl
@@ -5,7 +5,7 @@ module Read
import ...LibGit2, ..Cache, ..Reqs, ...Pkg.PkgError
using ..Types
-readstrip(path...) = strip(readall(joinpath(path...)))
+readstrip(path...) = strip(readstring(joinpath(path...)))
url(pkg::AbstractString) = readstrip("METADATA", pkg, "url")
sha1(pkg::AbstractString, ver::VersionNumber) = readstrip("METADATA", pkg, "versions", string(ver), "sha1")
diff --git a/base/process.jl b/base/process.jl
index cd1858995cd8c..b145dfed2ce42 100644
--- a/base/process.jl
+++ b/base/process.jl
@@ -579,15 +579,15 @@ function readandwrite(cmds::AbstractCmd)
(out, in, processes)
end
-function readbytes(cmd::AbstractCmd, stdin::Redirectable=DevNull)
+function read(cmd::AbstractCmd, stdin::Redirectable=DevNull)
out, procs = open(cmd, "r", stdin)
- bytes = readbytes(out)
+ bytes = read(out)
!success(procs) && pipeline_error(procs)
return bytes
end
-function readall(cmd::AbstractCmd, stdin::Redirectable=DevNull)
- return bytestring(readbytes(cmd, stdin))
+function readstring(cmd::AbstractCmd, stdin::Redirectable=DevNull)
+ return bytestring(read(cmd, stdin))
end
function writeall(cmd::AbstractCmd, stdin::AbstractString, stdout::Redirectable=DevNull)
diff --git a/base/random.jl b/base/random.jl
index d3386aa4ba48d..256a2ef69a8fa 100644
--- a/base/random.jl
+++ b/base/random.jl
@@ -149,7 +149,7 @@ function make_seed()
seed = reinterpret(UInt64, time())
seed = hash(seed, UInt64(getpid()))
try
- seed = hash(seed, parse(UInt64, readall(pipeline(`ifconfig`, `sha1sum`))[1:40], 16))
+ seed = hash(seed, parse(UInt64, readstring(pipeline(`ifconfig`, `sha1sum`))[1:40], 16))
end
return make_seed(seed)
end
@@ -168,11 +168,7 @@ function make_seed(n::Integer)
end
function make_seed(filename::AbstractString, n::Integer)
- open(filename) do io
- a = Array(UInt32, Int(n))
- read!(io, a)
- a
- end
+ read!(filename, Array(UInt32, Int(n)))
end
## srand()
diff --git a/base/require.jl b/base/require.jl
index 517b175ea085e..25dcaf13993ff 100644
--- a/base/require.jl
+++ b/base/require.jl
@@ -94,7 +94,7 @@ function include_from_node1(path::AbstractString)
result = Core.include(path)
nprocs()>1 && sleep(0.005)
else
- result = include_string(remotecall_fetch(readall, 1, path), path)
+ result = include_string(remotecall_fetch(readstring, 1, path), path)
end
finally
if prev == nothing
diff --git a/base/sharedarray.jl b/base/sharedarray.jl
index 15ce1e9c23d4d..90ea1df817615 100644
--- a/base/sharedarray.jl
+++ b/base/sharedarray.jl
@@ -479,9 +479,9 @@ function print_shmem_limits(slen)
@linux_only pfx = "kernel"
@osx_only pfx = "kern.sysv"
- shmmax_MB = div(parse(Int, split(readall(`sysctl $(pfx).shmmax`))[end]), 1024*1024)
- page_size = parse(Int, split(readall(`getconf PAGE_SIZE`))[end])
- shmall_MB = div(parse(Int, split(readall(`sysctl $(pfx).shmall`))[end]) * page_size, 1024*1024)
+ shmmax_MB = div(parse(Int, split(readstring(`sysctl $(pfx).shmmax`))[end]), 1024*1024)
+ page_size = parse(Int, split(readstring(`getconf PAGE_SIZE`))[end])
+ shmall_MB = div(parse(Int, split(readstring(`sysctl $(pfx).shmall`))[end]) * page_size, 1024*1024)
println("System max size of single shmem segment(MB) : ", shmmax_MB,
"\nSystem max size of all shmem segments(MB) : ", shmall_MB,
diff --git a/base/stream.jl b/base/stream.jl
index 53d4f724b1f9f..859f48f6dec3a 100644
--- a/base/stream.jl
+++ b/base/stream.jl
@@ -414,7 +414,7 @@ function displaysize(io::TTY)
@windows_only if ispty(io)
# io is actually a libuv pipe but a cygwin/msys2 pty
try
- h, w = map(x -> parse(Int, x), split(readall(open(Base.Cmd(ByteString["stty", "size"]), "r", io)[1])))
+ h, w = map(x -> parse(Int, x), split(readstring(open(Base.Cmd(ByteString["stty", "size"]), "r", io)[1])))
h > 0 || (h = default_size[1])
w > 0 || (w = default_size[2])
return h, w
@@ -902,7 +902,7 @@ function readbytes!(s::LibuvStream, b::AbstractArray{UInt8}, nb=length(b))
return nr
end
-function readbytes(stream::LibuvStream)
+function read(stream::LibuvStream)
wait_readnb(stream, typemax(Int))
return takebuf_array(stream.buffer)
end
diff --git a/contrib/BBEditTextWrangler-julia.plist b/contrib/BBEditTextWrangler-julia.plist
index bea156bb51cdc..09cbaea8f518e 100644
--- a/contrib/BBEditTextWrangler-julia.plist
+++ b/contrib/BBEditTextWrangler-julia.plist
@@ -842,10 +842,9 @@
rationalize
read
read!
- readall
+ readstring
readandwrite
readavailable
- readbytes
readbytes!
readchomp
readcsv
diff --git a/doc/DocCheck.jl b/doc/DocCheck.jl
index 59be92428a7ab..ca737f5c1f55c 100644
--- a/doc/DocCheck.jl
+++ b/doc/DocCheck.jl
@@ -91,7 +91,7 @@ function _undocumented_rst()
depdoc = havecount = total = 0
out = AbstractString["The following exports are not documented:"]
undoc_exports = Set()
- exports=[strip(x) for x in split(replace(open(readall, "$JULIA_HOME/../../base/exports.jl"),",",""),"\n")]
+ exports=[strip(x) for x in split(replace(readstring("$JULIA_HOME/../../base/exports.jl"),",",""),"\n")]
for line in exports
if search(line, "deprecated")!=0:-1; continue end
if haskey(MODULE_DICT, line); havecount+=1; total+=1; continue end
@@ -117,7 +117,7 @@ function _undocumented_rst()
append!(out, AbstractString["", "Documented and deprecated functions/exports (please update docs)", ""])
- deprecated=[strip(x) for x in split(replace(open(readall, "$JULIA_HOME/../../base/deprecated.jl"),",",""),"\n")]
+ deprecated=[strip(x) for x in split(replace(readstring("$JULIA_HOME/../../base/deprecated.jl"),",",""),"\n")]
for line in deprecated
if startswith(line, "@deprecated")
fn = split(line, r" +")[2]
@@ -141,7 +141,7 @@ function gen_undocumented_template(outfile = "$JULIA_HOME/../../doc/UNDOCUMENTED
init_help()
println(out, ".. currentmodule:: Base")
println(out)
- exports=[strip(x) for x in split(replace(open(readall, "$JULIA_HOME/../../base/exports.jl"),",",""),"\n")]
+ exports=[strip(x) for x in split(replace(readstring("$JULIA_HOME/../../base/exports.jl"),",",""),"\n")]
for line in exports
if search(line, "deprecated")!=0:-1; continue end
if haskey(MODULE_DICT, line); continue end
diff --git a/doc/NEWS-update.jl b/doc/NEWS-update.jl
index f39cc295d909e..ebfda62c4de3b 100644
--- a/doc/NEWS-update.jl
+++ b/doc/NEWS-update.jl
@@ -3,7 +3,7 @@
NEWS = get(ARGS, 1, "NEWS.md")
-s = readall(NEWS)
+s = readstring(NEWS)
s = s[1:match(r"\[#[0-9]+\]:", s).offset-1];
diff --git a/doc/genstdlib.jl b/doc/genstdlib.jl
index d6e3fb841324e..78f912b201d73 100644
--- a/doc/genstdlib.jl
+++ b/doc/genstdlib.jl
@@ -182,7 +182,7 @@ const warn_doc_between_func = "JULIA_WARN_DOC_BETWEEN_FUNC" in keys(ENV)
function translate(file)
@assert(isfile(file))
- ls = split(readall(file), "\n")[1:end-1]
+ ls = split(readstring(file), "\n")[1:end-1]
doccing = false
func = nothing
mod = "Base"
diff --git a/doc/manual/networking-and-streams.rst b/doc/manual/networking-and-streams.rst
index f19598688da48..31eb0ba56c905 100644
--- a/doc/manual/networking-and-streams.rst
+++ b/doc/manual/networking-and-streams.rst
@@ -53,7 +53,7 @@ For example, to read a simple byte array, we could do::
However, since this is slightly cumbersome, there are several convenience methods provided. For example, we could have written the
above as::
- julia> readbytes(STDIN,4)
+ julia> read(STDIN,4)
abcd
4-element Array{UInt8,1}:
0x61
@@ -142,7 +142,7 @@ as its first argument and filename as its second, opens the file, calls the func
an argument, and then closes it again. For example, given a function::
function read_and_capitalize(f::IOStream)
- return uppercase(readall(f))
+ return uppercase(readstring(f))
end
You can call::
@@ -156,7 +156,7 @@ To avoid even having to define a named function, you can use the ``do`` syntax,
function on the fly::
julia> open("hello.txt") do f
- uppercase(readall(f))
+ uppercase(readstring(f))
end
"HELLO AGAIN."
diff --git a/doc/manual/running-external-programs.rst b/doc/manual/running-external-programs.rst
index 56d436a72cf2c..ea72d8992310f 100644
--- a/doc/manual/running-external-programs.rst
+++ b/doc/manual/running-external-programs.rst
@@ -42,12 +42,12 @@ The ``hello`` is the output of the ``echo`` command, sent to :const:`STDOUT`.
The run method itself returns ``nothing``, and throws an :exc:`ErrorException`
if the external command fails to run successfully.
-If you want to read the output of the external command, :func:`readall`
+If you want to read the output of the external command, :func:`readstring`
can be used instead:
.. doctest::
- julia> a=readall(`echo hello`)
+ julia> a=readstring(`echo hello`)
"hello\n"
julia> (chomp(a)) == "hello"
@@ -314,7 +314,7 @@ When reading and writing to both ends of a pipeline from a single process,
it is important to avoid forcing the kernel to buffer all of the data.
For example, when reading all of the output from a command,
-call ``readall(out)``, not ``wait(process)``, since the former
+call ``read(out)``, not ``wait(process)``, since the former
will actively consume all of the data written by the process,
whereas the latter will attempt to store the data in the kernel's
buffers while waiting for a reader to be connected.
@@ -323,7 +323,7 @@ Another common solution is to separate the reader and writer
of the pipeline into separate Tasks::
writer = @async writeall(process, "data")
- reader = @async do_compute(readall(process))
+ reader = @async do_compute(read(process))
wait(process)
fetch(reader)
diff --git a/doc/stdlib/io-network.rst b/doc/stdlib/io-network.rst
index c11c070788aef..6d2b33657e643 100644
--- a/doc/stdlib/io-network.rst
+++ b/doc/stdlib/io-network.rst
@@ -65,7 +65,7 @@ General I/O
Apply the function ``f`` to the result of ``open(args...)`` and close the resulting file descriptor upon completion.
- **Example**: ``open(readall, "file.txt")``
+ **Example**: ``open(readstring, "file.txt")``
.. function:: IOBuffer() -> IOBuffer
@@ -121,11 +121,11 @@ General I/O
Close an I/O stream. Performs a ``flush`` first.
-.. function:: write(stream, x)
+.. function:: write(stream or filename, x)
.. Docstring generated from Julia source
- Write the canonical binary representation of a value to the given stream. Returns the number of bytes written into the stream.
+ Write the canonical binary representation of a value to the given stream or file. Returns the number of bytes written into the stream.
You can write multiple values with the same :func:``write`` call. i.e. the following are equivalent:
@@ -146,7 +146,7 @@ General I/O
Read a series of values of the given type from a stream, in canonical binary representation. ``dims`` is either a tuple or a series of integer arguments specifying the size of ``Array`` to return.
-.. function:: read!(stream, array::Array)
+.. function:: read!(stream or filename, array::Array)
.. Docstring generated from Julia source
@@ -158,9 +158,9 @@ General I/O
Read at most ``nb`` bytes from the stream into ``b``\ , returning the number of bytes read (increasing the size of ``b`` as needed).
- See ``readbytes`` for a description of the ``all`` option.
+ See ``read`` for a description of the ``all`` option.
-.. function:: readbytes(stream, nb=typemax(Int); all=true)
+.. function:: read(stream, nb=typemax(Int); all=true)
.. Docstring generated from Julia source
@@ -330,7 +330,7 @@ General I/O
.. Docstring generated from Julia source
- Read the entirety of ``x`` as a string but remove trailing newlines. Equivalent to ``chomp(readall(x))``\ .
+ Read the entirety of ``x`` as a string but remove trailing newlines. Equivalent to ``chomp(readstring(x))``\ .
.. function:: truncate(file,n)
@@ -493,41 +493,35 @@ Text I/O
Show all structure of a value, including all fields of objects.
-.. function:: readall(stream::IO)
+.. function:: readstring(stream or filename)
.. Docstring generated from Julia source
- Read the entire contents of an I/O stream as a string.
+ Read the entire contents of an I/O stream or a file as a string.
-.. function:: readall(filename::AbstractString)
+.. function:: readline(stream=STDIN or filename)
.. Docstring generated from Julia source
- Open ``filename``\ , read the entire contents as a string, then close the file. Equivalent to ``open(readall, filename)``\ .
+ Read a single line of text, including a trailing newline character (if one is reached before the end of the input), from the given stream or file (defaults to ``STDIN``\ ),
-.. function:: readline(stream=STDIN)
-
- .. Docstring generated from Julia source
-
- Read a single line of text, including a trailing newline character (if one is reached before the end of the input), from the given ``stream`` (defaults to ``STDIN``\ ),
-
-.. function:: readuntil(stream, delim)
+.. function:: readuntil(stream or filename, delim)
.. Docstring generated from Julia source
Read a string, up to and including the given delimiter byte.
-.. function:: readlines(stream)
+.. function:: readlines(stream or filename)
.. Docstring generated from Julia source
Read all lines as an array.
-.. function:: eachline(stream)
+.. function:: eachline(stream or filename)
.. Docstring generated from Julia source
- Create an iterable object that will yield each line from a stream.
+ Create an iterable object that will yield each line.
.. function:: readdlm(source, delim::Char, T::Type, eol::Char; header=false, skipstart=0, skipblanks=true, use_mmap, ignore_invalid_chars=false, quotes=true, dims, comments=true, comment_char='#')
diff --git a/examples/wordcount.jl b/examples/wordcount.jl
index c2f0e9d2a775e..601ffc3321a60 100644
--- a/examples/wordcount.jl
+++ b/examples/wordcount.jl
@@ -75,9 +75,7 @@ end
function wordcount_files(result_file,inputs...)
text = ""
for file in inputs
- open(file) do f
- text *= readall(f)
- end
+ text *= readstring(file)
end
wc = parallel_wordcount(text)
open(result_file,"w") do f
diff --git a/test/base64.jl b/test/base64.jl
index 76f31dee69881..5cc6ea2025663 100644
--- a/test/base64.jl
+++ b/test/base64.jl
@@ -18,7 +18,7 @@ end
open(fname, "r") do f
ipipe = Base64DecodePipe(f)
- @test readall(ipipe) == inputText
+ @test readstring(ipipe) == inputText
close(ipipe)
end
rm(fname)
@@ -28,16 +28,16 @@ rm(fname)
# Decode with max line chars = 76 and padding
ipipe = Base64DecodePipe(IOBuffer(encodedMaxLine76))
-@test readall(ipipe) == inputText
+@test readstring(ipipe) == inputText
# Decode with max line chars = 76 and no padding
ipipe = Base64DecodePipe(IOBuffer(encodedMaxLine76[1:end-1]))
-@test readall(ipipe) == inputText
+@test readstring(ipipe) == inputText
# Decode with two padding characters ("==")
ipipe = Base64DecodePipe(IOBuffer(string(encodedMaxLine76[1:end-2],"==")))
-@test readall(ipipe) == inputText[1:end-1]
+@test readstring(ipipe) == inputText[1:end-1]
# Test incorrect format
ipipe = Base64DecodePipe(IOBuffer(encodedMaxLine76[1:end-3]))
-@test_throws ArgumentError readall(ipipe)
+@test_throws ArgumentError readstring(ipipe)
diff --git a/test/cmdlineargs.jl b/test/cmdlineargs.jl
index 13bf36386be2d..98615fa24ddcd 100644
--- a/test/cmdlineargs.jl
+++ b/test/cmdlineargs.jl
@@ -2,15 +2,15 @@
let exename = `$(joinpath(JULIA_HOME, Base.julia_exename())) --precompiled=yes`
# --version
- let v = split(readall(`$exename -v`), "julia version ")[end]
+ let v = split(readstring(`$exename -v`), "julia version ")[end]
@test Base.VERSION_STRING == chomp(v)
end
- @test readall(`$exename -v`) == readall(`$exename --version`)
+ @test readstring(`$exename -v`) == readstring(`$exename --version`)
# --help
let header = "julia [switches] -- [programfile] [args...]"
- @test startswith(readall(`$exename -h`), header)
- @test startswith(readall(`$exename --help`), header)
+ @test startswith(readstring(`$exename -h`), header)
+ @test startswith(readstring(`$exename --help`), header)
end
# --quiet
@@ -29,8 +29,8 @@ let exename = `$(joinpath(JULIA_HOME, Base.julia_exename())) --precompiled=yes`
@test !success(`$exename --eval`)
# --print
- @test readall(`$exename -E "1+1"`) == "2\n"
- @test readall(`$exename --print="1+1"`) == "2\n"
+ @test readstring(`$exename -E "1+1"`) == "2\n"
+ @test readstring(`$exename --print="1+1"`) == "2\n"
@test !success(`$exename -E`)
@test !success(`$exename --print`)
@@ -45,9 +45,7 @@ let exename = `$(joinpath(JULIA_HOME, Base.julia_exename())) --precompiled=yes`
# --load
let testfile = tempname()
try
- open(testfile, "w") do io
- println(io, "testvar = :test")
- end
+ write(testfile, "testvar = :test\n")
@test split(readchomp(`$exename --load=$testfile -P "println(testvar)"`), '\n')[end] == "test"
@test split(readchomp(`$exename -P "println(testvar)" -L $testfile`), '\n')[end] == "test"
finally
@@ -182,7 +180,7 @@ let exename = `$(joinpath(JULIA_HOME, Base.julia_exename())) --precompiled=yes`
wait(proc)
close(out.in)
@test success(proc)
- @test isempty(readall(out))
+ @test isempty(readstring(out))
end
end
@@ -210,10 +208,10 @@ let exename = `$(joinpath(JULIA_HOME, Base.julia_exename())) --precompiled=yes`
let testfile = tempname()
try
# write a julia source file that just prints ARGS to STDOUT and exits
- open(testfile, "w") do io
- println(io, "println(ARGS)")
- println(io, "exit(0)")
- end
+ write(testfile, """
+ println(ARGS)
+ exit(0)
+ """)
@test readchomp(`$exename $testfile foo -bar --baz`) == "UTF8String[\"foo\",\"-bar\",\"--baz\"]"
@test readchomp(`$exename $testfile -- foo -bar --baz`) == "UTF8String[\"foo\",\"-bar\",\"--baz\"]"
@test readchomp(`$exename -L $testfile -- foo -bar --baz`) == "UTF8String[\"foo\",\"-bar\",\"--baz\"]"
diff --git a/test/compile.jl b/test/compile.jl
index dfb8ccb9753c7..18eade8c73134 100644
--- a/test/compile.jl
+++ b/test/compile.jl
@@ -10,20 +10,19 @@ Foo_module = :Foo4b3a94a1a081a8cb
try
Foo_file = joinpath(dir, "$Foo_module.jl")
- open(Foo_file, "w") do f
- print(f, """
- __precompile__(true)
- module $Foo_module
- @doc "foo function" foo(x) = x + 1
- include_dependency("foo.jl")
- include_dependency("foo.jl")
- module Bar
- @doc "bar function" bar(x) = x + 2
- include_dependency("bar.jl")
- end
- end
- """)
- end
+ write(Foo_file,
+ """
+ __precompile__(true)
+ module $Foo_module
+ @doc "foo function" foo(x) = x + 1
+ include_dependency("foo.jl")
+ include_dependency("foo.jl")
+ module Bar
+ @doc "bar function" bar(x) = x + 2
+ include_dependency("bar.jl")
+ end
+ end
+ """)
# Issue #12623
@test __precompile__(true) === nothing
@@ -51,25 +50,25 @@ try
end
Baz_file = joinpath(dir, "Baz.jl")
- open(Baz_file, "w") do f
- print(f, """
- __precompile__(false)
- module Baz
- end
- """)
- end
+ write(Baz_file,
+ """
+ __precompile__(false)
+ module Baz
+ end
+ """)
+
println(STDERR, "\nNOTE: The following 'LoadError: __precompile__(false)' indicates normal operation")
@test_throws ErrorException Base.compilecache("Baz") # from __precompile__(false)
# Issue #12720
FooBar_file = joinpath(dir, "FooBar.jl")
- open(FooBar_file, "w") do f
- print(f, """
- __precompile__(true)
- module FooBar
- end
- """)
- end
+ write(FooBar_file,
+ """
+ __precompile__(true)
+ module FooBar
+ end
+ """)
+
Base.compilecache("FooBar")
sleep(2)
@test isfile(joinpath(dir, "FooBar.ji"))
@@ -82,14 +81,14 @@ try
@test Base.stale_cachefile(FooBar_file, joinpath(dir, "FooBar.ji"))
@test !Base.stale_cachefile(FooBar_file, joinpath(dir2, "FooBar.ji"))
- open(FooBar_file, "w") do f
- print(f, """
- __precompile__(true)
- module FooBar
- error("break me")
- end
- """)
- end
+ write(FooBar_file,
+ """
+ __precompile__(true)
+ module FooBar
+ error("break me")
+ end
+ """)
+
println(STDERR, "\nNOTE: The following 'LoadError: break me' indicates normal operation")
@test_throws ErrorException Base.require(:FooBar)
@@ -106,14 +105,13 @@ let dir = mktempdir(),
Time_module = :Time4b3a94a1a081a8cb
try
- open(joinpath(dir, "$Time_module.jl"), "w") do io
- write(io, """
- module $Time_module
- __precompile__(true)
- time = Base.time()
- end
- """)
- end
+ write(joinpath(dir, "$Time_module.jl"),
+ """
+ module $Time_module
+ __precompile__(true)
+ time = Base.time()
+ end
+ """)
eval(quote
insert!(LOAD_PATH, 1, $(dir))
@@ -151,9 +149,7 @@ let module_name = string("a",randstring())
file_name = string(module_name, ".jl")
touch(file_name)
code = """module $(module_name)\nend\n"""
- open(file_name, "w") do file
- write(file, code)
- end
+ write(file_name, code)
reload(module_name)
@test typeof(eval(symbol(module_name))) == Module
deleteat!(LOAD_PATH,1)
diff --git a/test/datafmt.jl b/test/datafmt.jl
index 126a439f5abef..8e7cba730e8ce 100644
--- a/test/datafmt.jl
+++ b/test/datafmt.jl
@@ -7,9 +7,7 @@
@test countlines(IOBuffer("\n \n \n \n \n \n \n \n \n \n")) == 10
@test countlines(IOBuffer("\r\n \r\n \r\n \r\n \r\n")) == 5
file = tempname()
-open(file,"w") do f
- write(f,"Spiffy header\nspectacular first row\neven better 2nd row\nalmost done\n")
-end
+write(file,"Spiffy header\nspectacular first row\neven better 2nd row\nalmost done\n")
@test countlines(file) == 4
@test countlines(file,'\r') == 0
@test countlines(file,'\n') == 4
@@ -96,7 +94,7 @@ end
let x = [0.1 0.3 0.5], io = IOBuffer()
writedlm(io, x, ", ")
seek(io, 0)
- @test readall(io) == "0.1, 0.3, 0.5\n"
+ @test readstring(io) == "0.1, 0.3, 0.5\n"
end
let x = [0.1 0.3 0.5], io = IOBuffer()
diff --git a/test/file.jl b/test/file.jl
index 7b480da3a014e..2a6345eb2ae06 100644
--- a/test/file.jl
+++ b/test/file.jl
@@ -231,7 +231,7 @@ path = tempname()
print(f, "Here is some text")
close(f)
@test isfile(p) == true
-@test readall(p) == "Here is some text"
+@test readstring(p) == "Here is some text"
rm(p)
let
@@ -299,7 +299,7 @@ function check_cp(orig_path::AbstractString, copied_path::AbstractString, follow
# copied_path must also be a file.
@test isfile(copied_path)
# copied_path must have same content
- @test readall(orig_path) == readall(copied_path)
+ @test readstring(orig_path) == readstring(copied_path)
end
end
elseif isdir(orig_path)
@@ -308,7 +308,7 @@ function check_cp(orig_path::AbstractString, copied_path::AbstractString, follow
# copied_path must also be a file.
@test isfile(copied_path)
# copied_path must have same content
- @test readall(orig_path) == readall(copied_path)
+ @test readstring(orig_path) == readstring(copied_path)
end
end
@@ -337,9 +337,7 @@ bfile = joinpath(dir, "b.txt")
cp(afile, bfile)
cfile = joinpath(dir, "c.txt")
-open(cfile, "w") do cf
- write(cf, "This is longer than the contents of afile")
-end
+write(cfile, "This is longer than the contents of afile")
cp(afile, cfile; remove_destination=true)
a_stat = stat(afile)
@@ -410,13 +408,9 @@ if @unix? true : (Base.windows_version() >= Base.WINDOWS_VISTA_VER)
cfile = joinpath(srcdir, "c.txt")
file_txt = "This is some text with unicode - 这是一个文件"
- open(cfile, "w") do cf
- write(cf, file_txt)
- end
+ write(cfile, file_txt)
hidden_cfile = joinpath(hidden_srcsubdir, "c.txt")
- open(hidden_cfile, "w") do cf
- write(cf, file_txt)
- end
+ write(hidden_cfile, file_txt)
abs_dirlink_cp = joinpath(tmpdir, "abs_dirlink_cp")
hidden_srcsubdir_cp = joinpath(tmpdir, ".hidden_srcsubdir_cp")
@@ -543,12 +537,9 @@ if @unix? true : (Base.windows_version() >= Base.WINDOWS_VISTA_VER)
mkdir(subdir1)
cfile = abspath(joinpath(maindir, "c.txt"))
- open(cfile, "w") do cf
- write(cf, "This is c.txt - 这是一个文件")
- end
- open(abspath(joinpath(targetdir, "file1.txt")), "w") do cf
- write(cf, "This is file1.txt - 这是一个文件")
- end
+ write(cfile, "This is c.txt - 这是一个文件")
+ write(abspath(joinpath(targetdir, "file1.txt")),
+ "This is file1.txt - 这是一个文件")
abs_dl = joinpath(maindir, "abs_linkto_targetdir")
symlink(targetdir, abs_dl)
@@ -616,12 +607,8 @@ end
srcfile_new = joinpath(tmpdir, "srcfile_new.txt")
hidden_srcfile_new = joinpath(tmpdir, ".hidden_srcfile_new.txt")
file_txt = "This is some text with unicode - 这是一个文件"
- open(srcfile, "w") do f
- write(f, file_txt)
- end
- open(hidden_srcfile, "w") do f
- write(f, file_txt)
- end
+ write(srcfile, file_txt)
+ write(hidden_srcfile, file_txt)
abs_filelink = joinpath(tmpdir, "abs_filelink")
symlink(abspath(srcfile), abs_filelink)
cd(tmpdir)
@@ -645,7 +632,7 @@ end
islink(s) && @test readlink(s) == readlink(d)
islink(s) && @test isabspath(readlink(s)) == isabspath(readlink(d))
# all should contain the same
- @test readall(s) == readall(d) == file_txt
+ @test readstring(s) == readstring(d) == file_txt
end
function mv_check(s, d, d_mv, file_txt; remove_destination=true)
@@ -663,7 +650,7 @@ end
islink(s) && @test readlink(s) == readlink(d_mv)
islink(s) && @test isabspath(readlink(s)) == isabspath(readlink(d_mv))
# all should contain the same
- @test readall(s) == readall(d_mv) == file_txt
+ @test readstring(s) == readstring(d_mv) == file_txt
# d => d_mv same file/dir
@test Base.samefile(stat_d, stat_d_mv)
end
@@ -701,15 +688,13 @@ end
# Test remove the existing path first and copy an other file
otherfile = joinpath(tmpdir, "otherfile.txt")
otherfile_content = "This is otherfile.txt with unicode - 这是一个文件"
- open(otherfile, "w") do f
- write(f, otherfile_content)
- end
+ write(otherfile, otherfile_content)
for d in test_new_paths1
cp(otherfile, d; remove_destination=true, follow_symlinks=false)
# Expect no link because a file is copied (follow_symlinks=false does not effect this)
@test isfile(d) && !islink(d)
# all should contain otherfile_content
- @test readall(d) == otherfile_content
+ @test readstring(d) == otherfile_content
end
end
# mv ----------------------------------------------------
@@ -753,12 +738,9 @@ end
mkdir(subdir1)
cfile = abspath(joinpath(maindir, "c.txt"))
- open(cfile, "w") do cf
- write(cf, "This is c.txt - 这是一个文件")
- end
- open(abspath(joinpath(targetdir, "file1.txt")), "w") do cf
- write(cf, "This is file1.txt - 这是一个文件")
- end
+ write(cfile, "This is c.txt - 这是一个文件")
+ write(abspath(joinpath(targetdir, "file1.txt")),
+ "This is file1.txt - 这是一个文件")
abs_fl = joinpath(maindir, "abs_linkto_c.txt")
symlink(cfile, abs_fl)
@@ -772,7 +754,7 @@ end
rel_dl = "rel_linkto_targetdir"
rel_dir = joinpath("..", "targetdir")
symlink(rel_dir, rel_dl)
- rel_file_read_txt = readall(rel_file)
+ rel_file_read_txt = readstring(rel_file)
cd(pwd_)
# Setup copytodir
copytodir = joinpath(tmpdir, "copytodir")
@@ -996,10 +978,10 @@ let n = tempname()
w = open(n, "a")
io = open(n)
write(w, "A"); flush(w)
- @test readbytes(io) == UInt8[0x41]
- @test readbytes(io) == UInt8[]
+ @test read(io) == UInt8[0x41]
+ @test read(io) == UInt8[]
write(w, "A"); flush(w)
- @test readbytes(io) == UInt8[0x41]
+ @test read(io) == UInt8[0x41]
close(io); close(w)
rm(n)
end
@@ -1108,9 +1090,9 @@ end
test_read_nbyte()
let s = "qwerty"
- @test readbytes(IOBuffer(s)) == s.data
- @test readbytes(IOBuffer(s), 10) == s.data
- @test readbytes(IOBuffer(s), 1) == s.data[1:1]
+ @test read(IOBuffer(s)) == s.data
+ @test read(IOBuffer(s), 10) == s.data
+ @test read(IOBuffer(s), 1) == s.data[1:1]
# Test growing output array
x = UInt8[]
diff --git a/test/iobuffer.jl b/test/iobuffer.jl
index f18ebc5e647b4..9935c02cdaca5 100644
--- a/test/iobuffer.jl
+++ b/test/iobuffer.jl
@@ -50,7 +50,7 @@ end
let io = IOBuffer("hamster\nguinea pig\nturtle")
@test position(io) == 0
@test readline(io) == "hamster\n"
-@test readall(io) == "guinea pig\nturtle"
+@test readstring(io) == "guinea pig\nturtle"
@test_throws EOFError read(io,UInt8)
seek(io,0)
@test read(io,UInt8) == convert(UInt8, 'h')
@@ -106,7 +106,7 @@ skip(io,3)
@test write(io,"apples".data) == 3
skip(io,71)
@test write(io,'y') == 1
-@test readall(io) == "happy"
+@test readstring(io) == "happy"
@test eof(io)
write(io,zeros(UInt8,73))
write(io,'a')
@@ -163,22 +163,22 @@ let io=IOBuffer(SubString("***αhelloworldω***",4,16)), io2 = IOBuffer(b"goodni
@test read(io, Char) == 'ω'
@test_throws EOFError read(io,UInt8)
skip(io, -3)
- @test readall(io) == "dω"
+ @test readstring(io) == "dω"
@test bytestring(io) == "αhelloworldω"
@test_throws ArgumentError write(io,"!")
@test takebuf_array(io) == b"αhelloworldω"
seek(io, 2)
seekend(io2)
write(io2, io)
- @test readall(io) == ""
- @test readall(io2) == ""
+ @test readstring(io) == ""
+ @test readstring(io2) == ""
@test takebuf_string(io) == "αhelloworldω"
seek(io2, 0)
truncate(io2, io2.size - 2)
- @test readall(io2) == "goodnightmoonhelloworld"
+ @test readstring(io2) == "goodnightmoonhelloworld"
seek(io2, 0)
write(io2, io2)
- @test readall(io2) == ""
+ @test readstring(io2) == ""
@test bytestring(io2) == "goodnightmoonhelloworld"
end
diff --git a/test/libgit2.jl b/test/libgit2.jl
index a3c05a863f846..276a3289947c5 100644
--- a/test/libgit2.jl
+++ b/test/libgit2.jl
@@ -129,7 +129,7 @@ temp_dir() do dir
LibGit2.GitRemote(repo, branch, repo_url) |> finalize
config = joinpath(cache_repo, ".git", "config")
- lines = split(open(readall, config, "r"), "\n")
+ lines = split(open(readstring, config, "r"), "\n")
@test any(map(x->x == "[remote \"upstream\"]", lines))
remote = LibGit2.get(LibGit2.GitRemote, repo, branch)
@@ -330,7 +330,7 @@ temp_dir() do dir
@testset "Examine test repository" begin
@testset "files" begin
- @test readall(joinpath(test_repo, test_file)) == readall(joinpath(cache_repo, test_file))
+ @test readstring(joinpath(test_repo, test_file)) == readstring(joinpath(cache_repo, test_file))
end
@testset "tags & branches" begin
diff --git a/test/misc.jl b/test/misc.jl
index 15bdcde94db41..e8f55e8f78ffa 100644
--- a/test/misc.jl
+++ b/test/misc.jl
@@ -131,13 +131,13 @@ let
redir_err = "redirect_stderr(STDOUT)"
exename = joinpath(JULIA_HOME, Base.julia_exename())
script = "$redir_err; f(a::Number, b...) = 1;f(a, b::Number) = 1"
- warning_str = readall(`$exename -f -e $script`)
+ warning_str = readstring(`$exename -f -e $script`)
@test contains(warning_str, "f(Any, Number)")
@test contains(warning_str, "f(Number, Any...)")
@test contains(warning_str, "f(Number, Number)")
script = "$redir_err; module A; f() = 1; end; A.f() = 1"
- warning_str = readall(`$exename -f -e $script`)
+ warning_str = readstring(`$exename -f -e $script`)
@test contains(warning_str, "f()")
end
diff --git a/test/mmap.jl b/test/mmap.jl
index d298bd2478e44..0cbb56d3dad33 100644
--- a/test/mmap.jl
+++ b/test/mmap.jl
@@ -1,9 +1,7 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license
file = tempname()
-s = open(file, "w") do f
- write(f, "Hello World\n")
-end
+write(file, "Hello World\n")
t = "Hello World".data
@test Mmap.mmap(file, Array{UInt8,3}, (11,1,1)) == reshape(t,(11,1,1))
gc(); gc()
@@ -54,7 +52,7 @@ m = Mmap.mmap(file,Vector{UInt8},12)
m[:] = "Hello World\n".data
Mmap.sync!(m)
finalize(m); m=nothing; gc()
-@test open(readall,file) == "Hello World\n"
+@test open(readstring,file) == "Hello World\n"
s = open(file, "r")
close(s)
@@ -94,9 +92,7 @@ m = Mmap.mmap(s)
@test_throws ReadOnlyMemoryError m[5] = UInt8('x') # tries to setindex! on read-only array
finalize(m); m=nothing; gc()
-s = open(file, "w") do f
- write(f, "Hello World\n")
-end
+write(file, "Hello World\n")
s = open(file, "r")
m = Mmap.mmap(s)
@@ -114,9 +110,7 @@ close(s)
finalize(m); finalize(c); finalize(d)
m=nothing; c=nothing; d=nothing; gc()
-s = open(file, "w") do f
- write(f, "Hello World\n")
-end
+write(file, "Hello World\n")
s = open(file, "r")
@test isreadonly(s) == true
diff --git a/test/parallel_exec.jl b/test/parallel_exec.jl
index 81226e4fb11d6..05ba5b49a439f 100644
--- a/test/parallel_exec.jl
+++ b/test/parallel_exec.jl
@@ -248,9 +248,7 @@ d = SharedArray(Float64, (2,3))
# Mapping an existing file
fn = tempname()
-open(fn, "w") do io
- write(io, 1:30)
-end
+write(fn, 1:30)
sz = (6,5)
Atrue = reshape(1:30, sz)
@@ -267,9 +265,7 @@ end
check_pids_all(S)
filedata = similar(Atrue)
-open(fn, "r") do io
- read!(io, filedata)
-end
+read!(fn, filedata)
@test filedata == sdata(S)
# Error for write-only files
@@ -283,23 +279,17 @@ fn2 = tempname()
S = SharedArray(fn2, Int, sz, init=D->D[localindexes(D)] = myid())
@test S == filedata
filedata2 = similar(Atrue)
-open(fn2, "r") do io
- read!(io, filedata2)
-end
+read!(fn2, filedata2)
@test filedata == filedata2
# Appending to a file
fn3 = tempname()
-open(fn3, "w") do io
- write(io, ones(UInt8, 4))
-end
+write(fn3, ones(UInt8, 4))
S = SharedArray(fn3, UInt8, sz, 4, mode="a+", init=D->D[localindexes(D)]=0x02)
len = prod(sz)+4
@test filesize(fn3) == len
filedata = Array(UInt8, len)
-open(fn3, "r") do io
- read!(io, filedata)
-end
+read!(fn3, filedata)
@test all(filedata[1:4] .== 0x01)
@test all(filedata[5:end] .== 0x02)
@@ -594,7 +584,7 @@ if DoFullTest
(strm, proc) = open(pipeline(cmd, stderr=STDERR))
wait(proc)
if !success(proc) && ccall(:jl_running_on_valgrind,Cint,()) == 0
- println(readall(strm))
+ println(readstring(strm))
error("Topology tests failed : $cmd")
end
diff --git a/test/perf/kernel/perf.jl b/test/perf/kernel/perf.jl
index b29acd7498e1a..9977ac1383fcf 100644
--- a/test/perf/kernel/perf.jl
+++ b/test/perf/kernel/perf.jl
@@ -102,9 +102,7 @@ d = randn(len)
@timeit (for n in 1:10; a = arith_vectorized(b,c,d); end) "vectorize" "Vectorized arithmetic"
-open("random.csv","w") do io
- writecsv(io, rand(100000,4))
-end
+writecsv("random.csv", rand(100000,4))
function parsecsv()
for line in EachLine(open("random.csv"))
diff --git a/test/perf/perfutil.jl b/test/perf/perfutil.jl
index 1c9123cc10ab1..1974c337c96b2 100644
--- a/test/perf/perfutil.jl
+++ b/test/perf/perfutil.jl
@@ -21,7 +21,7 @@ if codespeed
csdata["project"] = "Julia"
csdata["branch"] = Base.GIT_VERSION_INFO.branch
csdata["executable"] = ENV["JULIA_FLAVOR"]
- csdata["environment"] = chomp(readall(`hostname`))
+ csdata["environment"] = chomp(readstring(`hostname`))
csdata["result_date"] = join( split(Base.GIT_VERSION_INFO.date_string)[1:2], " " ) #Cut the timezone out
end
diff --git a/test/perf/report.jl b/test/perf/report.jl
index 49750ea06dd94..34513c53d0a8a 100644
--- a/test/perf/report.jl
+++ b/test/perf/report.jl
@@ -2,7 +2,7 @@
using HTTPClient.HTTPC
-env_name = chomp(readall(`hostname`))
+env_name = chomp(readstring(`hostname`))
commit = Base.GIT_VERSION_INFO.commit
flavor = ENV["JULIA_FLAVOR"]
json = "{\"env\": \"$env_name\", \"blas\":\"$flavor\", \"commit\":\"$commit\"}"
diff --git a/test/perf/shootout/k_nucleotide.jl b/test/perf/shootout/k_nucleotide.jl
index 79535e4c07f1d..e81a3e44e2401 100644
--- a/test/perf/shootout/k_nucleotide.jl
+++ b/test/perf/shootout/k_nucleotide.jl
@@ -69,7 +69,7 @@ function k_nucleotide(infile="knucleotide-input.txt")
break
end
end
- data = collect(readall(input))
+ data = collect(readstring(input))
# delete the newlines and convert to upper case
i, j = 1, 1
while i <= length(data)
diff --git a/test/perf/shootout/regex_dna.jl b/test/perf/shootout/regex_dna.jl
index 0c3c24bc6663c..348c14187ccd5 100644
--- a/test/perf/shootout/regex_dna.jl
+++ b/test/perf/shootout/regex_dna.jl
@@ -33,7 +33,7 @@ const subs = [
]
function regex_dna(infile="regexdna-input.txt")
- seq = readall(infile)
+ seq = readstring(infile)
l1 = length(seq)
seq = replace(seq, r">.*\n|\n", "")
diff --git a/test/perf/spell/perf.jl b/test/perf/spell/perf.jl
index b65fc9352e906..e6ee7bb4bf373 100644
--- a/test/perf/spell/perf.jl
+++ b/test/perf/spell/perf.jl
@@ -28,7 +28,7 @@ end
if !isfile("big.txt")
download("http://norvig.com/big.txt", "big.txt")
end
-const NWORDS = train(words(readall("big.txt")))
+const NWORDS = train(words(readstring("big.txt")))
const alphabet = "abcdefghijklmnopqrstuvwxyz"
diff --git a/test/pkg.jl b/test/pkg.jl
index 048eda6e092ed..0fa9988b426d5 100644
--- a/test/pkg.jl
+++ b/test/pkg.jl
@@ -30,7 +30,7 @@ temp_pkg_dir() do
# (done here since it calls Pkg.status which might error or clone metadata)
buf = PipeBuffer()
versioninfo(buf, true)
- ver = readall(buf)
+ ver = readstring(buf)
@test startswith(ver, "Julia Version $VERSION")
@test contains(ver, "Environment:")
diff --git a/test/regex.jl b/test/regex.jl
index 601f0b4189ec1..e3a90abb1c591 100644
--- a/test/regex.jl
+++ b/test/regex.jl
@@ -29,7 +29,7 @@ match(pat, target)
# Issue 9545 (32 bit)
buf = PipeBuffer()
show(buf, r"")
-@test readall(buf) == "r\"\""
+@test readstring(buf) == "r\"\""
# see #10994, #11447: PCRE2 allows NUL chars in the pattern
@test ismatch(Regex("^a\0b\$"), "a\0b")
diff --git a/test/repl.jl b/test/repl.jl
index 62e2573170bb4..bfb5b5f85debc 100644
--- a/test/repl.jl
+++ b/test/repl.jl
@@ -131,7 +131,7 @@ end
function buffercontents(buf::IOBuffer)
p = position(buf)
seek(buf,0)
- c = readall(buf)
+ c = readstring(buf)
seek(buf,p)
c
end
@@ -388,6 +388,6 @@ end
if @unix? true : (Base.windows_version() >= Base.WINDOWS_VISTA_VER)
outs, ins, p = readandwrite(`$exename --startup-file=no --quiet`)
write(ins,"1\nquit()\n")
- @test readall(outs) == "1\n"
+ @test readstring(outs) == "1\n"
end
end
diff --git a/test/replutil.jl b/test/replutil.jl
index dc054ad9787b7..1ed2bb2216073 100644
--- a/test/replutil.jl
+++ b/test/replutil.jl
@@ -52,7 +52,7 @@ test_have_color(buf, color, no_color)
# Test for the method error in issue #8651
Base.show_method_candidates(buf, MethodError(readline,("",)))
-test_have_color(buf, "", "")
+test_have_color(buf, "\e[0m\nClosest candidates are:\n readline(::AbstractString)\e[0m", "\nClosest candidates are:\n readline(::AbstractString)")
method_c4(::Type{Float64}) = true
Base.show_method_candidates(buf, MethodError(method_c4,(Float64,)))
@@ -171,4 +171,4 @@ withenv("JULIA_EDITOR" => nothing, "VISUAL" => nothing, "EDITOR" => nothing) do
ENV["JULIA_EDITOR"] = "\"/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl\" -w"
@test Base.editor() == ["/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl", "-w"]
-end
\ No newline at end of file
+end
diff --git a/test/socket.jl b/test/socket.jl
index 145cee302bd39..70bbabf70de65 100644
--- a/test/socket.jl
+++ b/test/socket.jl
@@ -86,7 +86,7 @@ tsk = @async begin
close(sock)
end
wait(port)
-@test readall(connect(fetch(port))) == "Hello World\n" * ("a1\n"^100)
+@test readstring(connect(fetch(port))) == "Hello World\n" * ("a1\n"^100)
wait(tsk)
mktempdir() do tmpdir
@@ -102,7 +102,7 @@ mktempdir() do tmpdir
close(sock)
end
wait(c)
- @test readall(connect(socketname)) == "Hello World\n"
+ @test readstring(connect(socketname)) == "Hello World\n"
wait(tsk)
end
end
diff --git a/test/spawn.jl b/test/spawn.jl
index f3fc1abad3b4e..4b70c975f8f2a 100644
--- a/test/spawn.jl
+++ b/test/spawn.jl
@@ -20,14 +20,14 @@ yes = `perl -le 'while (1) {print STDOUT "y"}'`
#### Examples used in the manual ####
-@test readall(`echo hello | sort`) == "hello | sort\n"
-@test readall(pipeline(`echo hello`, `sort`)) == "hello\n"
+@test readstring(`echo hello | sort`) == "hello | sort\n"
+@test readstring(pipeline(`echo hello`, `sort`)) == "hello\n"
@test length(spawn(pipeline(`echo hello`, `sort`)).processes) == 2
-out = readall(`echo hello` & `echo world`)
+out = readstring(`echo hello` & `echo world`)
@test search(out,"world") != 0:-1
@test search(out,"hello") != 0:-1
-@test readall(pipeline(`echo hello` & `echo world`, `sort`)) == "hello\nworld\n"
+@test readstring(pipeline(`echo hello` & `echo world`, `sort`)) == "hello\nworld\n"
@test (run(`printf " \033[34m[stdio passthrough ok]\033[0m\n"`); true)
@@ -75,8 +75,8 @@ end
# STDIN Redirection
file = tempname()
run(pipeline(`echo hello world`, file))
-@test readall(pipeline(file, `cat`)) == "hello world\n"
-@test open(readall, pipeline(file, `cat`), "r") == "hello world\n"
+@test readstring(pipeline(file, `cat`)) == "hello world\n"
+@test open(readstring, pipeline(file, `cat`), "r") == "hello world\n"
rm(file)
# Stream Redirection
@@ -86,7 +86,7 @@ rm(file)
port, server = listenany(2326)
put!(r,port)
client = accept(server)
- @test readall(pipeline(client, `cat`)) == "hello world\n"
+ @test readstring(pipeline(client, `cat`)) == "hello world\n"
close(server)
end
@async begin
@@ -96,11 +96,11 @@ rm(file)
end
end
-@test readall(setenv(`sh -c "echo \$TEST"`,["TEST=Hello World"])) == "Hello World\n"
-@test readall(setenv(`sh -c "echo \$TEST"`,Dict("TEST"=>"Hello World"))) == "Hello World\n"
-@test readall(setenv(`sh -c "echo \$TEST"`,"TEST"=>"Hello World")) == "Hello World\n"
+@test readstring(setenv(`sh -c "echo \$TEST"`,["TEST=Hello World"])) == "Hello World\n"
+@test readstring(setenv(`sh -c "echo \$TEST"`,Dict("TEST"=>"Hello World"))) == "Hello World\n"
+@test readstring(setenv(`sh -c "echo \$TEST"`,"TEST"=>"Hello World")) == "Hello World\n"
@test (withenv("TEST"=>"Hello World") do
- readall(`sh -c "echo \$TEST"`); end) == "Hello World\n"
+ readstring(`sh -c "echo \$TEST"`); end) == "Hello World\n"
pathA = readchomp(setenv(`sh -c "pwd -P"`;dir=".."))
pathB = readchomp(setenv(`sh -c "cd .. && pwd -P"`))
@unix_only @test Base.samefile(pathA, pathB)
@@ -115,7 +115,7 @@ end
stdout, stdin, proc = readandwrite(`cat -`)
write(stdin, str)
close(stdin)
-str2 = readall(stdout)
+str2 = readstring(stdout)
@test str2 == str
# This test hangs if the end of run walk across uv streams calls shutdown on a stream that is shutting down.
@@ -175,16 +175,16 @@ exename = Base.julia_cmd()
if valgrind_off
# If --trace-children=yes is passed to valgrind, we will get a
# valgrind banner here, not "Hello World\n".
- @test readall(pipeline(`$exename -f -e 'println(STDERR,"Hello World")'`, stderr=`cat`)) == "Hello World\n"
+ @test readstring(pipeline(`$exename -f -e 'println(STDERR,"Hello World")'`, stderr=`cat`)) == "Hello World\n"
out = Pipe()
proc = spawn(pipeline(`$exename -f -e 'println(STDERR,"Hello World")'`, stderr = out))
close(out.in)
- @test readall(out) == "Hello World\n"
+ @test readstring(out) == "Hello World\n"
@test success(proc)
end
# issue #6310
-@test readall(pipeline(`echo "2+2"`, `$exename -f`)) == "4\n"
+@test readstring(pipeline(`echo "2+2"`, `$exename -f`)) == "4\n"
# issue #5904
@test run(pipeline(ignorestatus(`false`), `true`)) === nothing
@@ -205,7 +205,7 @@ redirect_stdout(f)
println("Hello World")
redirect_stdout(OLD_STDOUT)
close(f)
-@test "Hello World\n" == readall(fname)
+@test "Hello World\n" == readstring(fname)
@test is(OLD_STDOUT,STDOUT)
rm(fname)
@@ -238,7 +238,7 @@ try
close(in)
wait(p)
catch
- error("IOStream redirect failed. Child stderr was \n$(readall(fname))\n")
+ error("IOStream redirect failed. Child stderr was \n$(readstring(fname))\n")
end
rm(fname)
@@ -251,7 +251,7 @@ let bad = "bad\0name"
end
# issue #12829
-let out = Pipe(), echo = `$exename -f -e 'print(STDOUT, " 1\t", readall(STDIN))'`, ready = Condition()
+let out = Pipe(), echo = `$exename -f -e 'print(STDOUT, " 1\t", readstring(STDIN))'`, ready = Condition()
@test_throws ArgumentError write(out, "not open error")
@async begin # spawn writer task
open(echo, "w", out) do in1
@@ -283,7 +283,7 @@ let out = Pipe(), echo = `$exename -f -e 'print(STDOUT, " 1\t", readall(STDIN))'
@test nb_available(out) > 0
ln1 = readline(out)
ln2 = readline(out)
- desc = readall(out)
+ desc = readstring(out)
@test !isreadable(out)
@test !iswritable(out)
@test !isopen(out)
@@ -291,16 +291,14 @@ let out = Pipe(), echo = `$exename -f -e 'print(STDOUT, " 1\t", readall(STDIN))'
@test c == ['w']
@test lstrip(ln2) == "1\thello\n"
@test ln1 == "orld\n"
- @test isempty(readbytes(out))
+ @test isempty(read(out))
@test eof(out)
@test desc == "Pipe(open => active, 0 bytes waiting)"
end
# issue #8529
let fname = tempname()
- open(fname, "w") do f
- println(f, "test")
- end
+ write(fname, "test\n")
code = """
for line in eachline(STDIN)
run(pipeline(`echo asdf`,`cat`))
@@ -338,7 +336,7 @@ end
@test_throws ErrorException collect(eachline(`cat _doesnt_exist__111_`))
# make sure windows_verbatim strips quotes
-@windows_only readall(`cmd.exe /c dir /b spawn.jl`) == readall(Cmd(`cmd.exe /c dir /b "\"spawn.jl\""`, windows_verbatim=true))
+@windows_only readstring(`cmd.exe /c dir /b spawn.jl`) == readstring(Cmd(`cmd.exe /c dir /b "\"spawn.jl\""`, windows_verbatim=true))
# make sure Cmd is nestable
@test string(Cmd(Cmd(`ls`, detach=true))) == "`ls`"
diff --git a/test/strings/io.jl b/test/strings/io.jl
index 3ad734d290744..4b73b926bc267 100644
--- a/test/strings/io.jl
+++ b/test/strings/io.jl
@@ -172,23 +172,22 @@ else
close(f)
@test str1 == str2
- @test str1 == open(joinpath(unicodedir,"UTF-16LE.unicode")) do f
- utf16(read(f, UInt16, 2160641)[2:end])
- end
+ @test str1 == utf16(read(joinpath(unicodedir,"UTF-16LE.unicode"),
+ UInt16, 2160641)[2:end])
- @test str1 == open(joinpath(unicodedir,"UTF-16LE.unicode")) do f
- utf16(read(f, UInt8, 2160641*2))
- end
- @test str1 == open(joinpath(unicodedir,"UTF-16BE.unicode")) do f
- utf16(read(f, UInt8, 2160641*2))
- end
+ @test str1 == utf16(read(joinpath(unicodedir,"UTF-16LE.unicode"),
+ UInt8, 2160641*2))
+
+ @test str1 == utf16(read(joinpath(unicodedir,"UTF-16BE.unicode"),
+ UInt8, 2160641*2))
+
+
+ @test str1 == utf32(read(joinpath(unicodedir,"UTF-32LE.unicode"),
+ UInt8, 1112065*4))
+
+ @test str1 == utf32(read(joinpath(unicodedir,"UTF-32BE.unicode"),
+ UInt8, 1112065*4))
- @test str1 == open(joinpath(unicodedir,"UTF-32LE.unicode")) do f
- utf32(read(f, UInt8, 1112065*4))
- end
- @test str1 == open(joinpath(unicodedir,"UTF-32BE.unicode")) do f
- utf32(read(f, UInt8, 1112065*4))
- end
str1 = "∀ ε > 0, ∃ δ > 0: |x-y| < δ ⇒ |f(x)-f(y)| < ε"
str2 = UTF32String(UInt32[