test/extra/test_filesystem_tools.rb in nanoc-3.7.4 vs test/extra/test_filesystem_tools.rb in nanoc-3.7.5

- old
+ new

@@ -11,11 +11,11 @@ (0..15).each do |i| FileUtils.mkdir_p("dir#{i}") File.open("dir#{i}/foo.md", 'w') { |io| io.write('o hai') } end (1..10).each do |i| - File.symlink("../dir#{i}", "dir#{i-1}/sub") + File.symlink("../dir#{i}", "dir#{i - 1}/sub") end # Check # 11 expected files (follow symlink 10 times) # sort required because 10 comes before 2 @@ -30,26 +30,26 @@ 'dir0/sub/sub/sub/sub/sub/sub/sub/foo.md', 'dir0/sub/sub/sub/sub/sub/sub/sub/sub/foo.md', 'dir0/sub/sub/sub/sub/sub/sub/sub/sub/sub/foo.md', 'dir0/sub/sub/sub/sub/sub/sub/sub/sub/sub/sub/foo.md' ] - actual_files = Nanoc::Extra::FilesystemTools.all_files_in('dir0').sort + actual_files = Nanoc::Extra::FilesystemTools.all_files_in('dir0', nil).sort assert_equal expected_files, actual_files end def test_all_files_in_follows_symlinks_to_dirs_too_many # Write sample files (0..15).each do |i| FileUtils.mkdir_p("dir#{i}") File.open("dir#{i}/foo.md", 'w') { |io| io.write('o hai') } end (1..15).each do |i| - File.symlink("../dir#{i}", "dir#{i-1}/sub") + File.symlink("../dir#{i}", "dir#{i - 1}/sub") end assert_raises Nanoc::Extra::FilesystemTools::MaxSymlinkDepthExceededError do - Nanoc::Extra::FilesystemTools.all_files_in('dir0') + Nanoc::Extra::FilesystemTools.all_files_in('dir0', nil) end end def test_all_files_in_relativizes_directory_names FileUtils.mkdir('foo') @@ -59,11 +59,11 @@ File.open('bar/y.md', 'w') { |io| io.write('o hai from bar/y') } File.symlink('../bar', 'foo/barlink') expected_files = ['foo/barlink/y.md', 'foo/x.md'] - actual_files = Nanoc::Extra::FilesystemTools.all_files_in('foo').sort + actual_files = Nanoc::Extra::FilesystemTools.all_files_in('foo', nil).sort assert_equal expected_files, actual_files end def test_all_files_in_follows_symlinks_to_files # Write sample files @@ -72,11 +72,11 @@ File.open('dir/foo', 'w') { |io| io.write('o hai from foo') } File.symlink('../bar', 'dir/bar-link') # Check expected_files = ['dir/bar-link', 'dir/foo'] - actual_files = Nanoc::Extra::FilesystemTools.all_files_in('dir').sort + actual_files = Nanoc::Extra::FilesystemTools.all_files_in('dir', nil).sort assert_equal expected_files, actual_files end def test_resolve_symlink File.open('foo', 'w') { |io| io.write('o hai') } @@ -91,14 +91,54 @@ def test_resolve_symlink_too_many File.open('foo', 'w') { |io| io.write('o hai') } File.symlink('foo', 'symlin-0') (1..7).each do |i| - File.symlink("symlink-#{i-1}", "symlink-#{i}") + File.symlink("symlink-#{i - 1}", "symlink-#{i}") end assert_raises Nanoc::Extra::FilesystemTools::MaxSymlinkDepthExceededError do Nanoc::Extra::FilesystemTools.resolve_symlink('symlink-7') end end + def test_unwanted_dotfiles_not_found + # Write sample files + FileUtils.mkdir_p('dir') + File.open('dir/.DS_Store', 'w') { |io| io.write('o hai') } + File.open('dir/.htaccess', 'w') { |io| io.write('o hai') } + + actual_files = Nanoc::Extra::FilesystemTools.all_files_in('dir', nil).sort + assert_equal [], actual_files + end + + def test_user_dotfiles_are_valid_items + # Write sample files + FileUtils.mkdir_p('dir') + File.open('dir/.other', 'w') { |io| io.write('o hai') } + + actual_files = Nanoc::Extra::FilesystemTools.all_files_in('dir', '**/.other').sort + assert_equal ['dir/.other'], actual_files + end + + def test_multiple_user_dotfiles_are_valid_items + # Write sample files + FileUtils.mkdir_p('dir') + File.open('dir/.other', 'w') { |io| io.write('o hai') } + File.open('dir/.DS_Store', 'w') { |io| io.write('o hai') } + + actual_files = Nanoc::Extra::FilesystemTools.all_files_in('dir', ['**/.other', '**/.DS_Store']).sort + assert_equal ['dir/.other', 'dir/.DS_Store'].sort, actual_files.sort + end + + def test_unknown_pattern + # Write sample files + FileUtils.mkdir_p('dir') + File.open('dir/.other', 'w') { |io| io.write('o hai') } + + pattern = { dotfiles: '**/.other' } + + assert_raises Nanoc::Errors::GenericTrivial, "Do not know how to handle extra_files: #{pattern.inspect}" do + Nanoc::Extra::FilesystemTools.all_files_in('dir0', pattern) + end + end end