Skip to content

Commit 472f091

Browse files
committed
Update readstring(x) to read(x, String)
1 parent 8d4c683 commit 472f091

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

test/import.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Compat: readstring
1+
import Compat: read
22

33
# Patches should allow using imported bindings in the body of the patch
44
@test_throws UndefVarError Minute
@@ -20,15 +20,15 @@ end
2020
@test_throws UndefVarError AbstractCmd
2121
@test isdefined(Base, :AbstractCmd)
2222

23-
patch = @patch readstring(cmd::Base.AbstractCmd) = "bar"
23+
patch = @patch read(cmd::Base.AbstractCmd, ::Type{String}) = "bar"
2424
apply(patch) do
25-
@test (@mock readstring(`foo`)) == "bar"
25+
@test (@mock read(`foo`, String)) == "bar"
2626
end
2727

2828
# Patches should allow using imported bindings syntax in the signature
2929
import Base: AbstractCmd
3030

31-
patch = @patch readstring(cmd::AbstractCmd) = "bar"
31+
patch = @patch read(cmd::AbstractCmd, ::Type{String}) = "bar"
3232
apply(patch) do
33-
@test (@mock readstring(`foo`)) == "bar"
33+
@test (@mock read(`foo`, String)) == "bar"
3434
end

test/real-nested.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Compat: readstring
1+
import Compat: read
22

33
let
4-
readfile(filename) = (@mock isfile(filename)) ? readstring(@mock open(filename)) : ""
4+
readfile(filename) = (@mock isfile(filename)) ? read((@mock open(filename)), String) : ""
55

66
# Testing with both generic and anonymous functions
77
patches = Patch[

test/real-open.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Compat: readstring
1+
import Compat: read
22

33
let
44
# Ensure that open cannot find the file "foo"
@@ -9,19 +9,19 @@ let
99
# will be preferred over the original `open(::AbstractString)` for `open("foo")`
1010
patch = @patch open(name) = IOBuffer("bar")
1111
apply(patch) do
12-
@test readstring(@mock open("foo")) == "bar"
12+
@test read((@mock open("foo")), String) == "bar"
1313

1414
# The `open(::Any)` patch could result in unintended (or intended) consequences
15-
@test readstring(@mock open(`echo helloworld`)) == "bar"
15+
@test read((@mock open(`echo helloworld`)), String) == "bar"
1616
end
1717

1818
# Better to be specific with your patches
1919
patch = @patch open(name::AbstractString) = IOBuffer("bar")
2020
apply(patch) do
21-
@test readstring(@mock open("foo")) == "bar"
21+
@test read((@mock open("foo")), String) == "bar"
2222

2323
# The more specific `open(::AbstractString)` patches only a single method
24-
io, pobj = (@mock open(`echo helloworld`))
25-
@test readstring(io) == "helloworld\n"
24+
io, pobj = @mock open(`echo helloworld`)
25+
@test read(io, String) == "helloworld\n"
2626
end
2727
end

0 commit comments

Comments
 (0)