From f054bae5034d6d6c4ec9fef6f50dbcab35cd0588 Mon Sep 17 00:00:00 2001 From: Jordon Bedwell Date: Fri, 15 May 2015 06:38:31 -0500 Subject: [PATCH] Add support for JRuby, it was easier than assumed. --- .jrubyrc | 6 +++++ .travis.yml | 1 + Gemfile | 22 +++++++++++----- script/cibuild | 15 ++++++----- script/cucumber | 12 ++++++--- script/test | 52 +++++++++++++++++++++++++++++++++----- test/helper.rb | 20 +++++++++++---- test/test_rdiscount.rb | 14 +++++++++- test/test_redcarpet.rb | 15 +++++++++-- test/test_related_posts.rb | 13 ++++++++-- test/test_tags.rb | 28 ++++++++++++++++++-- 11 files changed, 164 insertions(+), 34 deletions(-) create mode 100644 .jrubyrc diff --git a/.jrubyrc b/.jrubyrc new file mode 100644 index 00000000..c4f93701 --- /dev/null +++ b/.jrubyrc @@ -0,0 +1,6 @@ +backtrace.mask=true +compile.invokedynamic=true +objectspace.enabled=true +backtrace.color=true +compat.version=2.2 +backtrace.style=mri diff --git a/.travis.yml b/.travis.yml index d7960ce7..1e187fe2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ rvm: - 2.2 - 2.1 - 2.0 +- jruby-head env: matrix: - TEST_SUITE=test diff --git a/Gemfile b/Gemfile index f1e43a12..1a594a9b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,30 +1,38 @@ source 'https://rubygems.org' gemspec -gem 'pygments.rb', '~> 0.6.0' -gem 'redcarpet', '~> 3.2', '>= 3.2.3' +gem 'pry' gem 'toml', '~> 0.1.0' gem 'jekyll-paginate', '~> 1.0' gem 'jekyll-gist', '~> 1.0' gem 'jekyll-coffeescript', '~> 1.0' -gem 'classifier-reborn', '~> 2.0' + +platform :ruby, :mswin, :mingw do + gem 'pygments.rb', '~> 0.6.0' + gem 'rdiscount', '~> 2.0' + gem 'classifier-reborn', '~> 2.0' + gem 'redcarpet', '~> 3.2', '>= 3.2.3' + gem 'liquid-c', '~> 3.0' +end + +if RUBY_PLATFORM =~ /cygwin/ || RUBY_VERSION.start_with?("2.2") + gem 'test-unit' +end gem 'rake', '~> 10.1' gem 'rdoc', '~> 3.11' gem 'redgreen', '~> 1.2' gem 'shoulda', '~> 3.5' gem 'cucumber', '1.3.18' -gem 'rdiscount', '~> 2.0' gem 'launchy', '~> 2.3' gem 'simplecov', '~> 0.9' gem 'mime-types', '~> 1.5' +gem 'kramdown', '~> 1.7.0' gem 'jekyll_test_plugin' gem 'jekyll_test_plugin_malicious' -gem 'liquid-c', '~> 3.0' -gem 'minitest' gem 'minitest-reporters' gem 'minitest-profile' -gem 'test-unit' if RUBY_PLATFORM =~ /cygwin/ || RUBY_VERSION.start_with?("2.2") +gem 'minitest' gem 'rspec-mocks' if ENV['BENCHMARK'] diff --git a/script/cibuild b/script/cibuild index fdfe0740..dade701b 100755 --- a/script/cibuild +++ b/script/cibuild @@ -1,12 +1,15 @@ -#! /bin/bash +#! /bin/bash -e script/branding -set -e - -if test -z "$TEST_SUITE"; then - script/test +if [[ -z "$TEST_SUITE" ]] +then + script/test ci script/cucumber -else +elif [[ -x "script/$TEST_SUITE" ]] +then script/$TEST_SUITE +else + echo "Unknown test suite." + exit 1 fi diff --git a/script/cucumber b/script/cucumber index c6957356..31a9be63 100755 --- a/script/cucumber +++ b/script/cucumber @@ -1,5 +1,11 @@ #!/bin/bash -time bundle exec cucumber \ - -f Features::Support::Overview \ - "$@" +if ruby --version | grep -q "jruby" +then + echo "Move along, we are not testing features on JRuby right now." + exit 0 +else + time ruby -S bundle exec cucumber \ + -f Features::Support::Overview \ + "$@" +fi diff --git a/script/test b/script/test index 97f0daff..652f89f3 100755 --- a/script/test +++ b/script/test @@ -1,15 +1,55 @@ -#! /bin/bash -set -e +#! /bin/bash -e # Usage: -# script/test # script/test +# script/test [ruby|jruby] +# script/test if [ -d test/dest ] then rm -r test/dest fi -if [[ $# -lt 1 ]] - then time bundle exec rake TESTOPTS='--profile' test - else time bundle exec ruby -Itest "$@" --profile +# ----------------------------------------------------------------------------- +# If you send us a ruby then we use that, if you do not then we test with +# whatever we can detect, this way you can run both suites when you test out +# your source, we expect full coverage now, not just MRI. +# ----------------------------------------------------------------------------- + +if [[ "$1" == "ci" ]] +then + rubies=( + ruby + ) + + shift +elif [[ "$1" == "ruby" ]] || [[ "$1" == "jruby" ]] +then + rubies=( + $1 + ) + + shift +else + rubies=() + for r in jruby ruby; do + if which "$r" + then + rubies+=( + $r + ) + fi + done fi + +for ruby in $rubies; do + if [[ $# -lt 1 ]] + then + set -x + time $ruby -S bundle exec \ + rake TESTOPTS='--profile' test + else + set -x + time $ruby bundle exec ruby -Itest \ + "$@" --profile + fi +done diff --git a/test/helper.rb b/test/helper.rb index f888507d..0b64e5e0 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,3 +1,7 @@ +def jruby? + defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' +end + unless ENV['TRAVIS'] require File.expand_path('../simplecov_custom_profile', __FILE__) SimpleCov.start('gem') do @@ -15,19 +19,25 @@ require 'rspec/mocks' require 'jekyll' -require 'rdiscount' -require 'kramdown' -require 'redcarpet' +unless jruby? + require 'rdiscount' + require 'redcarpet' +end +require 'kramdown' require 'shoulda' include Jekyll -# Send STDERR into the void to suppress program output messages +# FIXME: If we really need this we lost the game. STDERR.reopen(test(?e, '/dev/null') ? '/dev/null' : 'NUL:') # Report with color. -Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(:color => true)] +Minitest::Reporters.use! [ + Minitest::Reporters::DefaultReporter.new( + :color => true + ) +] class JekyllUnitTest < Minitest::Test include ::RSpec::Mocks::ExampleMethods diff --git a/test/test_rdiscount.rb b/test/test_rdiscount.rb index ea1756d7..96446404 100644 --- a/test/test_rdiscount.rb +++ b/test/test_rdiscount.rb @@ -4,10 +4,22 @@ class TestRdiscount < JekyllUnitTest context "rdiscount" do setup do + if jruby? + then skip( + "JRuby does not perform well with CExt, test disabled." + ) + end + config = { 'markdown' => 'rdiscount', - 'rdiscount' => { 'extensions' => ['smart', 'generate_toc'], 'toc_token' => '{:toc}' } + 'rdiscount' => { + 'toc_token' => '{:toc}', + 'extensions' => [ + 'smart', 'generate_toc' + ], + } } + @markdown = Converters::Markdown.new config end diff --git a/test/test_redcarpet.rb b/test/test_redcarpet.rb index 909df7bf..bb2d3214 100644 --- a/test/test_redcarpet.rb +++ b/test/test_redcarpet.rb @@ -3,10 +3,21 @@ require 'helper' class TestRedcarpet < JekyllUnitTest context "redcarpet" do setup do + if jruby? + then skip( + "JRuby does not perform well with CExt, test disabled." + ) + end + @config = { - 'redcarpet' => { 'extensions' => ['smart', 'strikethrough', 'filter_html'] }, - 'markdown' => 'redcarpet' + 'markdown' => 'redcarpet', + 'redcarpet' => { + 'extensions' => [ + 'smart', 'strikethrough', 'filter_html' + ] + } } + @markdown = Converters::Markdown.new @config end diff --git a/test/test_related_posts.rb b/test/test_related_posts.rb index 76dc497c..4c2c6bf9 100644 --- a/test/test_related_posts.rb +++ b/test/test_related_posts.rb @@ -20,8 +20,17 @@ class TestRelatedPosts < JekyllUnitTest context "building related posts with lsi" do setup do + if jruby? + skip( + "JRuby does not perform well with CExt, test disabled." + ) + end + allow_any_instance_of(Jekyll::RelatedPosts).to receive(:display) - @site = fixture_site({"lsi" => true}) + @site = fixture_site({ + "lsi" => true + }) + @site.reset @site.read require 'classifier-reborn' @@ -38,7 +47,7 @@ class TestRelatedPosts < JekyllUnitTest post = @site.posts.last allow_any_instance_of(::ClassifierReborn::LSI).to receive(:build_index) expect_any_instance_of(::ClassifierReborn::LSI).to receive(:find_related).with(post, 11).and_return(@site.posts[-1..-9]) - + Jekyll::RelatedPosts.new(post).build end diff --git a/test/test_tags.rb b/test/test_tags.rb index 30e8394b..ef919ede 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -136,6 +136,14 @@ CONTENT end context "with the pygments highlighter" do + setup do + if jruby? + then skip( + "JRuby does not support Pygments." + ) + end + end + context "post content has highlight tag" do setup do fill_post("test", {'highlighter' => 'pygments'}) @@ -353,7 +361,15 @@ CONTENT context "using RDiscount" do setup do - create_post(@content, 'markdown' => 'rdiscount') + if jruby? + then skip( + "JRuby does not perform well with CExt, test disabled." + ) + end + + create_post(@content, { + 'markdown' => 'rdiscount' + }) end should "parse correctly" do @@ -375,7 +391,15 @@ CONTENT context "using Redcarpet" do setup do - create_post(@content, 'markdown' => 'redcarpet') + if jruby? + skip( + "JRuby does not perform well with CExt, test disabled." + ) + end + + create_post(@content, { + 'markdown' => 'redcarpet' + }) end should "parse correctly" do