File tree Expand file tree Collapse file tree 3 files changed +13
-13
lines changed Expand file tree Collapse file tree 3 files changed +13
-13
lines changed Original file line number Diff line number Diff line change 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
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"
2424apply (patch) do
25- @test (@mock readstring (` foo` )) == " bar"
25+ @test (@mock read (` foo` , String )) == " bar"
2626end
2727
2828# Patches should allow using imported bindings syntax in the signature
2929import Base: AbstractCmd
3030
31- patch = @patch readstring (cmd:: AbstractCmd ) = " bar"
31+ patch = @patch read (cmd:: AbstractCmd , :: Type{String} ) = " bar"
3232apply (patch) do
33- @test (@mock readstring (` foo` )) == " bar"
33+ @test (@mock read (` foo` , String )) == " bar"
3434end
Original file line number Diff line number Diff line change 1- import Compat: readstring
1+ import Compat: read
22
33let
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[
Original file line number Diff line number Diff line change 1- import Compat: readstring
1+ import Compat: read
22
33let
44 # Ensure that open cannot find the file "foo"
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
2727end
You can’t perform that action at this time.
0 commit comments