@@ -612,34 +612,93 @@ module TestPaths
612612
613613 function test_sync (ps:: PathSet )
614614 @testset " sync" begin
615- # Base cp case
616- sync (ps. foo, ps. qux / " foo" )
617- @test exists (ps. qux / " foo" / " baz.txt" )
615+ @testset " empty destination " begin
616+ sync (ps. foo, ps. qux / " foo" )
617+ @test exists (ps. qux / " foo" / " baz.txt" )
618618
619- # Test that the copied baz file has a newer modified time
620- baz_t = modified (ps. qux / " foo" / " baz.txt" )
621- @test modified (ps. baz) < baz_t
622-
623- # Don't cp unchanged files when a new file is added
624- # NOTE: sleep before we make a new file, so it's clear tha the
625- # modified time has changed.
626- sleep (1 )
627- write (ps. foo / " test.txt" , " New File" )
628- sync (ps. foo, ps. qux / " foo" )
629- @test exists (ps. qux / " foo" / " test.txt" )
630- @test read (ps. qux / " foo" / " test.txt" , String) == " New File"
631- @test modified (ps. qux / " foo" / " baz.txt" ) == baz_t
632- @test modified (ps. qux / " foo" / " test.txt" ) > baz_t
633-
634- # Test not deleting a file on sync
635- rm (ps. foo / " test.txt" )
636- sync (ps. foo, ps. qux / " foo" )
637- @test exists (ps. qux / " foo" / " test.txt" )
638-
639- # Test passing delete flag
640- sync (ps. foo, ps. qux / " foo" ; delete= true )
641- @test ! exists (ps. qux / " foo" / " test.txt" )
642- rm (ps. qux / " foo" ; recursive= true )
619+ # Test that the copied baz file has a newer modified time
620+ baz_t = modified (ps. qux / " foo" / " baz.txt" )
621+ @test modified (ps. baz) < baz_t
622+ end
623+
624+ @testset " empty source" begin
625+ @test_throws ArgumentError sync (ps. root / " quux" , ps. foo)
626+ end
627+
628+ @testset " new source" begin
629+ # Don't cp unchanged files when a new file is added
630+ # NOTE: sleep before we make a new file, so it's clear that the
631+ # modified time has changed.
632+ baz_t = modified (ps. qux / " foo" / " baz.txt" )
633+ sleep (1 )
634+ write (ps. foo / " test.txt" , " New src" )
635+ sync (ps. foo, ps. qux / " foo" )
636+ @test exists (ps. qux / " foo" / " test.txt" )
637+ @test read (ps. qux / " foo" / " test.txt" , String) == " New src"
638+ @test modified (ps. qux / " foo" / " baz.txt" ) == baz_t
639+ @test modified (ps. qux / " foo" / " test.txt" ) > baz_t
640+ end
641+
642+ @testset " new destination" begin
643+ # Newer file of the same size is likely the result of an upload which
644+ # will always have a newer last modified time.
645+ test_t = modified (ps. foo / " test.txt" )
646+ sleep (1 )
647+ write (ps. qux / " foo" / " test.txt" , " New dst" )
648+ @test modified (ps. qux / " foo" / " test.txt" ) > test_t
649+ sync (ps. foo, ps. qux / " foo" )
650+ @test read (ps. qux / " foo" / " test.txt" , String) == " New dst"
651+ @test modified (ps. qux / " foo" / " test.txt" ) > test_t
652+ end
653+
654+ @testset " no delete" begin
655+ # Test not deleting a file on sync
656+ rm (ps. foo / " test.txt" )
657+ sync (ps. foo, ps. qux / " foo" )
658+ @test exists (ps. qux / " foo" / " test.txt" )
659+ end
660+
661+ @testset " delete" begin
662+ # Test passing delete flag
663+ sync (ps. foo, ps. qux / " foo" ; delete= true )
664+ @test ! exists (ps. qux / " foo" / " test.txt" )
665+ rm (ps. qux / " foo" ; recursive= true )
666+ end
667+
668+ @testset " mixed types" begin
669+ @testset " directory -> file" begin
670+ @test_throws ArgumentError sync (ps. foo, ps. quux)
671+ end
672+
673+ @testset " file -> directory" begin
674+ @test_throws ArgumentError sync (ps. quux, ps. foo)
675+ end
676+ end
677+
678+ @testset " walkpath order" begin
679+ # Test a condtion where the index could reorder the walkpath order.
680+ tmp_src = ps. root / " tmp-src"
681+ mkdir (tmp_src)
682+ src_file = tmp_src / " file1"
683+ write (src_file, " Hello World!" )
684+
685+ src_folder = tmp_src / " folder1"
686+ mkdir (src_folder)
687+ src_folder_file = src_folder / " file2"
688+ write (src_folder_file, " " ) # empty file
689+
690+ src_folder2 = src_folder / " folder2" # nested folders
691+ mkdir (src_folder2)
692+ src_folder2_file = src_folder2 / " file3"
693+ write (src_folder2_file, " Test" )
694+
695+ tmp_dst = ps. root / " tmp_dst"
696+ mkdir (tmp_dst)
697+ sync (tmp_src, tmp_dst)
698+ @test exists (tmp_dst / " folder1" / " folder2" / " file3" )
699+ rm (tmp_src; recursive= true )
700+ rm (tmp_dst; recursive= true )
701+ end
643702 end
644703 end
645704
0 commit comments