diff --git a/base/file.jl b/base/file.jl index ccfb5783bc8bc..702a9c8cf87cc 100644 --- a/base/file.jl +++ b/base/file.jl @@ -737,7 +737,7 @@ julia> readdir(abspath("base"), join=true) "/home/JuliaUser/dev/julia/base/weakkeydict.jl" ``` """ -function readdir(dir::AbstractString=pwd(); join::Bool=false) +function readdir(dir::AbstractString; join::Bool=false) # Allocate space for uv_fs_t struct uv_readdir_req = zeros(UInt8, ccall(:jl_sizeof_uv_fs_t, Int32, ())) @@ -759,6 +759,7 @@ function readdir(dir::AbstractString=pwd(); join::Bool=false) return entries end +readdir(; join::Bool=false) = readdir(join ? pwd() : ".", join=join) """ walkdir(dir; topdown=true, follow_symlinks=false, onerror=throw) diff --git a/test/file.jl b/test/file.jl index b07b37ad1571d..9e0289fda7dab 100644 --- a/test/file.jl +++ b/test/file.jl @@ -1405,7 +1405,7 @@ end end end -@testset "readir tests" begin +@testset "readdir tests" begin ≛(a, b) = sort(a) == sort(b) mktempdir() do dir d = cd(pwd, dir) # might resolve symlinks @@ -1431,4 +1431,21 @@ end @test readdir(b, join=true) ≛ [joinpath(b, x) for x in names] end end + if !Sys.iswindows() + mktempdir() do dir + cd(dir) do + d = pwd() # might resolve symlinks + @test isdir(d) + @test Base.Filesystem.samefile(d, ".") + @test isempty(readdir()) + @test isempty(readdir(d)) + @test isempty(readdir(join=true)) + rm(d, recursive=true) + @test !ispath(d) + @test isempty(readdir()) + @test_throws SystemError readdir(d) + @test_throws Base.IOError readdir(join=true) + end + end + end end