From 0f4aed9ccfa0776d7ca8e1548a3202b7d80d1019 Mon Sep 17 00:00:00 2001 From: Jordon Bedwell Date: Thu, 29 Oct 2015 13:36:05 -0500 Subject: [PATCH 1/2] Fix #4066: Move Convertible#render_liquid to using render! --- lib/jekyll/convertible.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index 57abb7d1..12151395 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -109,7 +109,7 @@ module Jekyll # # Returns the converted content def render_liquid(content, payload, info, path) - site.liquid_renderer.file(path).parse(content).render(payload, info) + site.liquid_renderer.file(path).parse(content).render!(payload, info) rescue Tags::IncludeTagError => e Jekyll.logger.error "Liquid Exception:", "#{e.message} in #{e.path}, included in #{path || self.path}" raise e From 1c4b4ae2717d38d7c0c1b406557e9982c59a1330 Mon Sep 17 00:00:00 2001 From: Jordon Bedwell Date: Thu, 29 Oct 2015 17:19:03 -0500 Subject: [PATCH 2/2] Add regression tests to Cucumber. --- features/rendering.feature | 7 ++++++ features/step_definitions/jekyll_steps.rb | 5 +++++ features/support/env.rb | 26 +++++++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/features/rendering.feature b/features/rendering.feature index 55a9d3d2..01507cb0 100644 --- a/features/rendering.feature +++ b/features/rendering.feature @@ -5,6 +5,13 @@ Feature: Rendering But I want to make it as simply as possible So render with Liquid and place in Layouts + Scenario: When receiving bad Liquid + Given I have a "index.html" page with layout "simple" that contains "{% include invalid.html %}" + And I have a simple layout that contains "{{ content }}" + When I run jekyll build + Then I should get a non-zero exit-status + And I should see "Liquid Exception" in the build output + Scenario: Render Liquid and place in layout Given I have a "index.html" page with layout "simple" that contains "Hi there, Jekyll {{ jekyll.environment }}!" And I have a simple layout that contains "{{ content }}Ahoy, indeed!" diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 27c8692d..9164d549 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -24,6 +24,7 @@ end After do FileUtils.rm_rf(TEST_DIR) if File.exist?(TEST_DIR) FileUtils.rm(JEKYLL_COMMAND_OUTPUT_FILE) if File.exist?(JEKYLL_COMMAND_OUTPUT_FILE) + FileUtils.rm(JEKYLL_COMMAND_STATUS_FILE) if File.exist?(JEKYLL_COMMAND_STATUS_FILE) Dir.chdir(File.dirname(TEST_DIR)) end @@ -227,3 +228,7 @@ end Then /^I should see "(.*)" in the build output$/ do |text| assert_match Regexp.new(text), jekyll_run_output end + +Then /^I should get a non-zero exit(?:\-| )status$/ do + assert jekyll_run_status > 0 +end diff --git a/features/support/env.rb b/features/support/env.rb index 9e9f47fd..76a3e707 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -16,6 +16,7 @@ JEKYLL_SOURCE_DIR = File.dirname(File.dirname(File.dirname(__FILE__))) TEST_DIR = File.expand_path(File.join('..', '..', 'tmp', 'jekyll'), File.dirname(__FILE__)) JEKYLL_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'jekyll')) JEKYLL_COMMAND_OUTPUT_FILE = File.join(File.dirname(TEST_DIR), 'jekyll_output.txt') +JEKYLL_COMMAND_STATUS_FILE = File.join(File.dirname(TEST_DIR), 'jekyll_status.txt') def source_dir(*files) File.join(TEST_DIR, *files) @@ -36,12 +37,20 @@ def jekyll_output_file JEKYLL_COMMAND_OUTPUT_FILE end +def jekyll_status_file + JEKYLL_COMMAND_STATUS_FILE +end + def jekyll_run_output File.read(jekyll_output_file) if File.file?(jekyll_output_file) end +def jekyll_run_status + (File.read(jekyll_status_file) rescue 0).to_i +end + def run_bundle(args) - child = run_in_shell('bundle', *args.strip.split(' ')) + run_in_shell('bundle', *args.strip.split(' ')) end def run_jekyll(args) @@ -49,8 +58,21 @@ def run_jekyll(args) child.status.exitstatus == 0 end +# ----------------------------------------------------------------------------- +# XXX: POSIX::Spawn::Child does not write output when the exit status is > 0 +# for example when doing [:out, :err] => [file, "w"] it will skip +# writing the file entirely, we sould switch to Open. +# ----------------------------------------------------------------------------- + def run_in_shell(*args) - POSIX::Spawn::Child.new *args, :out => [JEKYLL_COMMAND_OUTPUT_FILE, "w"] + spawned = POSIX::Spawn::Child.new(*args) + status = spawned.status.exitstatus + File.write(JEKYLL_COMMAND_STATUS_FILE, status) + File.open(JEKYLL_COMMAND_OUTPUT_FILE, "w+") do |file| + status == 0 ? file.write(spawned.out) : file.write(spawned.err) + end + + spawned end def slug(title)