@@ -855,6 +855,107 @@ end
855855@test_throws ArgumentError download (" good" , " ba\0 d" )
856856@test_throws ArgumentError download (" ba\0 d" , " good" )
857857
858+ # ##################
859+ # walkdir #
860+ # ##################
861+
862+ dirwalk = mktempdir ()
863+ cd (dirwalk) do
864+ for i= 1 : 2
865+ mkdir (" sub_dir$i " )
866+ open (" file$i " , " w" ) do f end
867+
868+ mkdir (joinpath (" sub_dir1" , " subsub_dir$i " ))
869+ touch (joinpath (" sub_dir1" , " file$i " ))
870+ end
871+ touch (joinpath (" sub_dir2" , " file_dir2" ))
872+ has_symlinks = @unix ? true : (Base. windows_version () >= Base. WINDOWS_VISTA_VER)
873+ follow_symlink_vec = has_symlinks ? [true , false ] : [false ]
874+ has_symlinks && symlink (abspath (" sub_dir2" ), joinpath (" sub_dir1" , " link" ))
875+ for follow_symlinks in follow_symlink_vec
876+ task = walkdir (" ." , follow_symlinks= follow_symlinks)
877+ root, dirs, files = consume (task)
878+ @test root == " ."
879+ @test dirs == [" sub_dir1" , " sub_dir2" ]
880+ @test files == [" file1" , " file2" ]
881+
882+ root, dirs, files = consume (task)
883+ @test root == joinpath (" ." , " sub_dir1" )
884+ @test dirs == (has_symlinks ? [" link" , " subsub_dir1" , " subsub_dir2" ] : [" subsub_dir1" , " subsub_dir2" ])
885+ @test files == [" file1" , " file2" ]
886+
887+ root, dirs, files = consume (task)
888+ if follow_symlinks
889+ @test root == joinpath (" ." , " sub_dir1" , " link" )
890+ @test dirs == []
891+ @test files == [" file_dir2" ]
892+ root, dirs, files = consume (task)
893+ end
894+ for i= 1 : 2
895+ @test root == joinpath (" ." , " sub_dir1" , " subsub_dir$i " )
896+ @test dirs == []
897+ @test files == []
898+ root, dirs, files = consume (task)
899+ end
900+
901+ @test root == joinpath (" ." , " sub_dir2" )
902+ @test dirs == []
903+ @test files == [" file_dir2" ]
904+ end
905+
906+ for follow_symlinks in follow_symlink_vec
907+ task = walkdir (" ." , follow_symlinks= follow_symlinks, topdown= false )
908+ root, dirs, files = consume (task)
909+ if follow_symlinks
910+ @test root == joinpath (" ." , " sub_dir1" , " link" )
911+ @test dirs == []
912+ @test files == [" file_dir2" ]
913+ root, dirs, files = consume (task)
914+ end
915+ for i= 1 : 2
916+ @test root == joinpath (" ." , " sub_dir1" , " subsub_dir$i " )
917+ @test dirs == []
918+ @test files == []
919+ root, dirs, files = consume (task)
920+ end
921+ @test root == joinpath (" ." , " sub_dir1" )
922+ @test dirs == (has_symlinks ? [" link" , " subsub_dir1" , " subsub_dir2" ] : [" subsub_dir1" , " subsub_dir2" ])
923+ @test files == [" file1" , " file2" ]
924+
925+ root, dirs, files = consume (task)
926+ @test root == joinpath (" ." , " sub_dir2" )
927+ @test dirs == []
928+ @test files == [" file_dir2" ]
929+
930+ root, dirs, files = consume (task)
931+ @test root == " ."
932+ @test dirs == [" sub_dir1" , " sub_dir2" ]
933+ @test files == [" file1" , " file2" ]
934+ end
935+ # test of error handling
936+ task_error = walkdir (" ." )
937+ task_noerror = walkdir (" ." , onerror= x-> x)
938+ root, dirs, files = consume (task_error)
939+ @test root == " ."
940+ @test dirs == [" sub_dir1" , " sub_dir2" ]
941+ @test files == [" file1" , " file2" ]
942+
943+ rm (joinpath (" sub_dir1" ), recursive= true )
944+ @test_throws SystemError consume (task_error) # throws an error because sub_dir1 do not exist
945+
946+ root, dirs, files = consume (task_noerror)
947+ @test root == " ."
948+ @test dirs == [" sub_dir1" , " sub_dir2" ]
949+ @test files == [" file1" , " file2" ]
950+
951+ root, dirs, files = consume (task_noerror) # skips sub_dir1 as it no longer exist
952+ @test root == joinpath (" ." , " sub_dir2" )
953+ @test dirs == []
954+ @test files == [" file_dir2" ]
955+
956+ end
957+ rm (dirwalk, recursive= true )
958+
858959# ###########
859960# Clean up #
860961# ###########
0 commit comments