From a7aed246dd95959db6fc3939154a7bd6d1de0174 Mon Sep 17 00:00:00 2001 From: Sam O'Connor Date: Tue, 12 Jan 2016 21:17:48 +1100 Subject: [PATCH] Consistency of read() and write() functions. #14608 replace readall() with readstring() replace readbytes() with read() readbytes! returns nb whereas read! returns array, so they can't trivially be merged. Fix test/replutil.jl test that matches output of method error message that has changed due to introduction of readbytes(::AbstractString). add: +eachline(filename::AbstractString) = EachLine(open(stream), close) --- base/LineEdit.jl | 4 +-- base/base64.jl | 2 +- base/client.jl | 4 +-- base/datafmt.jl | 4 +-- base/deprecated.jl | 5 ++++ base/docs/helpdb/Base.jl | 22 ++++++++-------- base/exports.jl | 3 +-- base/filesystem.jl | 12 +++------ base/interactiveutil.jl | 8 +++--- base/io.jl | 31 +++++++++++++++++----- base/iobuffer.jl | 4 +-- base/iostream.jl | 4 +-- base/loading.jl | 12 ++++----- base/markdown/Julia/interp.jl | 2 +- base/markdown/Markdown.jl | 2 +- base/markdown/parse/util.jl | 2 +- base/pkg/git.jl | 2 +- base/pkg/read.jl | 2 +- base/process.jl | 8 +++--- base/random.jl | 2 +- base/require.jl | 2 +- base/sharedarray.jl | 6 ++--- base/stream.jl | 4 +-- doc/DocCheck.jl | 6 ++--- doc/NEWS-update.jl | 2 +- doc/genstdlib.jl | 2 +- examples/wordcount.jl | 2 +- test/base64.jl | 10 +++---- test/cmdlineargs.jl | 14 +++++----- test/datafmt.jl | 2 +- test/file.jl | 26 +++++++++--------- test/iobuffer.jl | 14 +++++----- test/libgit2.jl | 4 +-- test/misc.jl | 4 +-- test/mmap.jl | 2 +- test/parallel_exec.jl | 2 +- test/perf/perfutil.jl | 2 +- test/perf/report.jl | 2 +- test/perf/shootout/k_nucleotide.jl | 2 +- test/perf/shootout/regex_dna.jl | 2 +- test/perf/spell/perf.jl | 2 +- test/pkg.jl | 2 +- test/regex.jl | 2 +- test/repl.jl | 4 +-- test/replutil.jl | 4 +-- test/socket.jl | 4 +-- test/spawn.jl | 42 +++++++++++++++--------------- 47 files changed, 161 insertions(+), 144 deletions(-) diff --git a/base/LineEdit.jl b/base/LineEdit.jl index 72833ea4204a35..b594427d920a9b 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 fa993706914238..90f0cde3514be6 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 70aacb8610913a..7864124718b14f 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 7d1448ccf9ed15..deda884281ce73 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 e510542a6ed63f..2ad64e4be9cad6 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -952,3 +952,8 @@ end #14555 @deprecate_binding Coff_t Int64 @deprecate_binding FileOffset Int64 + + +#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 ad6ae33e34b933..af7091436b9ead 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -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,19 @@ the process. triu!(M, k) """ - readall(stream::IO) + readstring(stream::IO) Read the entire contents of an I/O stream as a string. """ -readall(stream::IO) +readstring(stream::IO) """ - readall(filename::AbstractString) + readstring(filename::AbstractString) Open `filename`, read the entire contents as a string, then close the file. Equivalent to -`open(readall, filename)`. +`open(readstring, filename)`. """ -readall(filename::AbstractString) +readstring(filename::AbstractString) """ poll_file(path, interval_s::Real, timeout_s::Real) -> (previous::StatStruct, current::StatStruct) @@ -6398,7 +6398,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 @@ -6443,9 +6443,9 @@ 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! +read! """ basename(path::AbstractString) -> AbstractString @@ -10260,7 +10260,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. @@ -10269,7 +10269,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 f227287be56c85..6ba532042a927a 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 118a0211a52426..a6f032ee958440 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 e64939813e3b89..857dbd95526482 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 a5db9f90595f84..a1f0f4a2bf8f48 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 wrappes. (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 3c66c7c0184531..cd748862bb949e 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 c942b5987c47a7..3e3aa61ca003af 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 766f2babce7e6c..2529993e9e9959 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 1147a705aeb192..eecfcb09b9487c 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 53f1824eb4b706..1ee18b218d3081 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 f6e43217bdc945..3eca2c9f9f7948 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/git.jl b/base/pkg/git.jl index 32e492f074dc1d..56252125ce7bc1 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 b8a555989edb38..1a6149578438c4 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 cd1858995cd8ca..b145dfed2ce421 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 d3386aa4ba48d0..cce1cc3e2528f2 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 diff --git a/base/require.jl b/base/require.jl index 517b175ea085e8..25dcaf13993ff2 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 15ce1e9c23d4d2..90ea1df817615e 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 01d5c7c15c3a28..c9f05b19db7828 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -396,7 +396,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 @@ -876,7 +876,7 @@ function stop_reading(stream::LibuvStream) end end -function readbytes(stream::LibuvStream) +function read(stream::LibuvStream) wait_readnb(stream, typemax(Int)) return takebuf_array(stream.buffer) end diff --git a/doc/DocCheck.jl b/doc/DocCheck.jl index 59be92428a7ab6..502fbe3293283e 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(open(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(open(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(open(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 f39cc295d909ee..ebfda62c4de3b5 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 de1d09f87aa21f..6cd565c8ed5b35 100644 --- a/doc/genstdlib.jl +++ b/doc/genstdlib.jl @@ -176,7 +176,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/examples/wordcount.jl b/examples/wordcount.jl index c2f0e9d2a775e3..ab892e1922c410 100644 --- a/examples/wordcount.jl +++ b/examples/wordcount.jl @@ -76,7 +76,7 @@ function wordcount_files(result_file,inputs...) text = "" for file in inputs open(file) do f - text *= readall(f) + text *= readstring(f) end end wc = parallel_wordcount(text) diff --git a/test/base64.jl b/test/base64.jl index 76f31dee698818..5cc6ea20256631 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 13bf36386be2d5..707b7a14c2dcc9 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`) @@ -182,7 +182,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 diff --git a/test/datafmt.jl b/test/datafmt.jl index 126a439f5abef0..2bc4b8e74b6337 100644 --- a/test/datafmt.jl +++ b/test/datafmt.jl @@ -96,7 +96,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 7b480da3a014eb..f538f150b53ce4 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 @@ -645,7 +645,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 +663,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 @@ -709,7 +709,7 @@ end # 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 ---------------------------------------------------- @@ -772,7 +772,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 +996,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 +1108,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 991d244676e225..27d3c5a2eaa0c0 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 a3c05a863f846c..276a3289947c5a 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 15bdcde94db41a..e8f55e8f78ffa0 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 d298bd2478e44f..f8cfc0aee00807 100644 --- a/test/mmap.jl +++ b/test/mmap.jl @@ -54,7 +54,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) diff --git a/test/parallel_exec.jl b/test/parallel_exec.jl index 81226e4fb11d60..b1249bef6414f8 100644 --- a/test/parallel_exec.jl +++ b/test/parallel_exec.jl @@ -594,7 +594,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/perfutil.jl b/test/perf/perfutil.jl index 1c9123cc10ab1d..1974c337c96b25 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 49750ea06dd94d..34513c53d0a8a5 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 79535e4c07f1d0..e81a3e44e24015 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 0c3c24bc6663cc..348c14187ccd51 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 b65fc9352e906a..e6ee7bb4bf373f 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 048eda6e092ed8..0fa9988b426d54 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 601f0b4189ec1c..e3a90abb1c5912 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 62e2573170bb4a..bfb5b5f85debc5 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 dc054ad9787b76..1ed2bb22160732 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 bec98602da26d4..b6216d60f5af09 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 f3fc1abad3b4e6..bbc940c6c34641 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,7 +291,7 @@ 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 @@ -338,7 +338,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`"