From 0c234c90a90e3799bd237c3391d1c58c6ad8cdb4 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Wed, 2 Nov 2016 12:18:05 +0530 Subject: [PATCH 1/6] TestGeneratedSite: add "|" to preserve newline adding a pipe character ('|') preserves the formatting of 'expected_output' with a trailing newline bit, in windows. --- test/test_generated_site.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 31784054..112cf9d3 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -50,11 +50,13 @@ class TestGeneratedSite < JekyllUnitTest should "print a nice list of static files" do time_regexp = "\\d+:\\d+" + # + # adding a pipe character at the beginning preserves formatting with newlines expected_output = Regexp.new <<-OUTPUT -- /css/screen.css last edited at #{time_regexp} with extname .css -- /pgp.key last edited at #{time_regexp} with extname .key -- /products.yml last edited at #{time_regexp} with extname .yml -- /symlink-test/symlinked-dir/screen.css last edited at #{time_regexp} with extname .css +| - /css/screen.css last edited at #{time_regexp} with extname .css + - /pgp.key last edited at #{time_regexp} with extname .key + - /products.yml last edited at #{time_regexp} with extname .yml + - /symlink-test/symlinked-dir/screen.css last edited at #{time_regexp} with extname .css OUTPUT assert_match expected_output, File.read(dest_dir("static_files.html")) end From 257e60b9a7629d04c244c22673fe4f4ffc1c3970 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Wed, 2 Nov 2016 12:25:50 +0530 Subject: [PATCH 2/6] TestSite: add symlinked files only if not Windows add symlinked files to "sorted_pages" array only when testing on non-windows platforms. --- test/test_site.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/test_site.rb b/test/test_site.rb index 4f527281..efe7076a 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -175,7 +175,8 @@ class TestSite < JekyllUnitTest method.call(*args, &block).reverse end @site.process - # files in symlinked directories may appear twice + # exclude files in symlinked directories here and insert them in the + # following step when not on Windows. sorted_pages = %w( %#\ +.md .htaccess @@ -194,12 +195,14 @@ class TestSite < JekyllUnitTest index.html info.md main.scss - main.scss properties.html sitemap.xml static_files.html - symlinked-file ) + unless Utils::Platforms.really_windows? + # files in symlinked directories may appear twice + sorted_pages.push("main.scss", "symlinked-file").sort! + end assert_equal sorted_pages, @site.pages.map(&:name) end From e6b9dd1cc147a881ef39b36977c705ef2b76c63c Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Wed, 2 Nov 2016 12:54:47 +0530 Subject: [PATCH 3/6] TestFilters: adjust array size to ignore symlinks Adjust the size of grouped-items array as it won't include symlinked pages in Windows. --- test/test_filters.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/test_filters.rb b/test/test_filters.rb index 9a0f87d4..20587610 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -575,7 +575,9 @@ class TestFilters < JekyllUnitTest g["items"].is_a?(Array), "The list of grouped items for 'default' is not an Array." ) - assert_equal 5, g["items"].size + # adjust array.size to ignore symlinked page in Windows + qty = Utils::Platforms.really_windows? ? 4 : 5 + assert_equal qty, g["items"].size when "nil" assert( g["items"].is_a?(Array), @@ -587,7 +589,9 @@ class TestFilters < JekyllUnitTest g["items"].is_a?(Array), "The list of grouped items for '' is not an Array." ) - assert_equal 15, g["items"].size + # adjust array.size to ignore symlinked page in Windows + qty = Utils::Platforms.really_windows? ? 14 : 15 + assert_equal qty, g["items"].size end end end From 1852e54d102f3877ebad04134db3296178458a74 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Wed, 2 Nov 2016 14:18:07 +0530 Subject: [PATCH 4/6] add and use 'skip_if_windows' helper method - add a new helper method to skip tests if on Windows platform - skip those tests that fail due to lack of support for symlinked files on Windows. --- test/helper.rb | 7 +++++++ test/test_collections.rb | 3 +++ test/test_entry_filter.rb | 6 ++++++ test/test_theme.rb | 3 +++ 4 files changed, 19 insertions(+) diff --git a/test/helper.rb b/test/helper.rb index 8fc43d67..ad88b5d0 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -158,4 +158,11 @@ class JekyllUnitTest < Minitest::Test str ) end + + def skip_if_windows(msg = nil) + if Utils::Platforms.really_windows? + msg ||= "Jekyll does not currently support this feature on Windows." + skip msg.to_s.magenta + end + end end diff --git a/test/test_collections.rb b/test/test_collections.rb index 3ae1ab12..45e2a511 100644 --- a/test/test_collections.rb +++ b/test/test_collections.rb @@ -186,6 +186,9 @@ class TestCollections < JekyllUnitTest end should "include the symlinked file from site.source in the list of docs" do + # no support for including symlinked file on Windows + skip_if_windows "Jekyll does not currently support symlinks on Windows." + assert_includes @collection.docs.map(&:relative_path), "_methods/um_hi.md" end end diff --git a/test/test_entry_filter.rb b/test/test_entry_filter.rb index eed24567..f65badc6 100644 --- a/test/test_entry_filter.rb +++ b/test/test_entry_filter.rb @@ -82,6 +82,9 @@ class TestEntryFilter < JekyllUnitTest # rubocop:disable Performance/FixedSize should "include only safe symlinks in safe mode" do + # no support for symlinks on Windows + skip_if_windows "Jekyll does not currently support symlinks on Windows." + site = Site.new(site_configuration("safe" => true)) site.reader.read_directories("symlink-test") @@ -91,6 +94,9 @@ class TestEntryFilter < JekyllUnitTest # rubocop:enable Performance/FixedSize should "include symlinks in unsafe mode" do + # no support for symlinks on Windows + skip_if_windows "Jekyll does not currently support symlinks on Windows." + site = Site.new(site_configuration) site.reader.read_directories("symlink-test") diff --git a/test/test_theme.rb b/test/test_theme.rb index fd380d95..918d01f6 100644 --- a/test/test_theme.rb +++ b/test/test_theme.rb @@ -55,6 +55,9 @@ class TestTheme < JekyllUnitTest end should "return the resolved path when a symlink & resolved path exists" do + # no support for symlinks on Windows + skip_if_windows "Jekyll does not currently support symlinks on Windows." + expected = File.expand_path("./_layouts", @expected_root) assert_equal expected, @theme.send(:path_for, :_symlink) end From 2c68069a4151d4dc08e0b46e0f24a5e4c49c80b6 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Thu, 3 Nov 2016 23:10:22 +0530 Subject: [PATCH 5/6] TestSite: consider dive-letter in Windows The array of plugins will contain current drive-letter in Windows --- test/test_site.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/test_site.rb b/test/test_site.rb index efe7076a..105e086a 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -14,14 +14,20 @@ class TestSite < JekyllUnitTest should "have an array for plugins if passed as a string" do site = Site.new(site_configuration({ "plugins_dir" => "/tmp/plugins" })) - assert_equal ["/tmp/plugins"], site.plugins + array = Utils::Platforms.windows? ? ["C:/tmp/plugins"] : ["/tmp/plugins"] + assert_equal array, site.plugins end should "have an array for plugins if passed as an array" do site = Site.new(site_configuration({ "plugins_dir" => ["/tmp/plugins", "/tmp/otherplugins"] })) - assert_equal ["/tmp/plugins", "/tmp/otherplugins"], site.plugins + array = if Utils::Platforms.windows? + ["C:/tmp/plugins", "C:/tmp/otherplugins"] + else + ["/tmp/plugins", "/tmp/otherplugins"] + end + assert_equal array, site.plugins end should "have an empty array for plugins if nothing is passed" do From 1bafbd91fadad9ddcebea43fc5cb352ffb9f1111 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sat, 5 Nov 2016 15:00:40 +0530 Subject: [PATCH 6/6] create orphan files with touch method --- test/test_site.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_site.rb b/test/test_site.rb index 105e086a..81da363d 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -277,19 +277,19 @@ class TestSite < JekyllUnitTest @site.process # generate some orphaned files: # single file - File.open(dest_dir("obsolete.html"), "w") + FileUtils.touch(dest_dir("obsolete.html")) # single file in sub directory FileUtils.mkdir(dest_dir("qux")) - File.open(dest_dir("qux/obsolete.html"), "w") + FileUtils.touch(dest_dir("qux/obsolete.html")) # empty directory FileUtils.mkdir(dest_dir("quux")) FileUtils.mkdir(dest_dir(".git")) FileUtils.mkdir(dest_dir(".svn")) FileUtils.mkdir(dest_dir(".hg")) # single file in repository - File.open(dest_dir(".git/HEAD"), "w") - File.open(dest_dir(".svn/HEAD"), "w") - File.open(dest_dir(".hg/HEAD"), "w") + FileUtils.touch(dest_dir(".git/HEAD")) + FileUtils.touch(dest_dir(".svn/HEAD")) + FileUtils.touch(dest_dir(".hg/HEAD")) end teardown do