From e770a080a7af3f379014dde1436e150edc967e44 Mon Sep 17 00:00:00 2001 From: Nicholas Burlett Date: Thu, 19 Mar 2015 09:41:05 -0700 Subject: [PATCH] Regenerator cache clearing tests Two tests for the regenerator cache clearing changes: 1. Intrusively test that the regnerator.clear_cache actually clears the cache ( in test/test_regenerator.rb ) 2. Test that incremental building regenerates files that have changed that previously were unchanged ( in test/test_site.rb ) --- test/test_regenerator.rb | 9 +++++++++ test/test_site.rb | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/test/test_regenerator.rb b/test/test_regenerator.rb index 15819487..87312333 100644 --- a/test/test_regenerator.rb +++ b/test/test_regenerator.rb @@ -75,6 +75,15 @@ class TestRegenerator < JekyllUnitTest assert @regenerator.cache[@path] end + should "clear the cache on clear_cache" do + # @path will be in the cache because the + # site will have processed it + assert @regenerator.cache[@path] + + @regenerator.clear_cache + assert_equal @regenerator.cache, {} + end + should "write to the metadata file" do @regenerator.clear @regenerator.add(@path) diff --git a/test/test_site.rb b/test/test_site.rb index 4bc7ddb2..7888f330 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -459,5 +459,43 @@ class TestSite < JekyllUnitTest end end + context "incremental build" do + setup do + @site = Site.new(site_configuration({ + 'full_rebuild' => false + })) + @site.read + end + + should "build incrementally" do + contacts_html = @site.pages.find { |p| p.name == "contacts.html" } + @site.process + + source = @site.in_source_dir(contacts_html.path) + dest = File.expand_path(contacts_html.destination(@site.dest)) + mtime1 = File.stat(dest).mtime.to_i # first run must generate dest file + + # need to sleep because filesystem timestamps have best resolution in seconds + sleep 1 + @site.process + mtime2 = File.stat(dest).mtime.to_i + assert_equal mtime1, mtime2 # no modifications, so remain the same + + # simulate file modification by user + FileUtils.touch source + + sleep 1 + @site.process + mtime3 = File.stat(dest).mtime.to_i + refute_equal mtime2, mtime3 # must be regenerated + + sleep 1 + @site.process + mtime4 = File.stat(dest).mtime.to_i + assert_equal mtime3, mtime4 # no modifications, so remain the same + end + + end + end end