Add support for JRuby, it was easier than assumed.

This commit is contained in:
Jordon Bedwell 2015-05-15 06:38:31 -05:00
parent 60a811d405
commit f054bae503
11 changed files with 164 additions and 34 deletions

6
.jrubyrc Normal file
View File

@ -0,0 +1,6 @@
backtrace.mask=true
compile.invokedynamic=true
objectspace.enabled=true
backtrace.color=true
compat.version=2.2
backtrace.style=mri

View File

@ -5,6 +5,7 @@ rvm:
- 2.2 - 2.2
- 2.1 - 2.1
- 2.0 - 2.0
- jruby-head
env: env:
matrix: matrix:
- TEST_SUITE=test - TEST_SUITE=test

22
Gemfile
View File

@ -1,30 +1,38 @@
source 'https://rubygems.org' source 'https://rubygems.org'
gemspec gemspec
gem 'pygments.rb', '~> 0.6.0' gem 'pry'
gem 'redcarpet', '~> 3.2', '>= 3.2.3'
gem 'toml', '~> 0.1.0' gem 'toml', '~> 0.1.0'
gem 'jekyll-paginate', '~> 1.0' gem 'jekyll-paginate', '~> 1.0'
gem 'jekyll-gist', '~> 1.0' gem 'jekyll-gist', '~> 1.0'
gem 'jekyll-coffeescript', '~> 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 'rake', '~> 10.1'
gem 'rdoc', '~> 3.11' gem 'rdoc', '~> 3.11'
gem 'redgreen', '~> 1.2' gem 'redgreen', '~> 1.2'
gem 'shoulda', '~> 3.5' gem 'shoulda', '~> 3.5'
gem 'cucumber', '1.3.18' gem 'cucumber', '1.3.18'
gem 'rdiscount', '~> 2.0'
gem 'launchy', '~> 2.3' gem 'launchy', '~> 2.3'
gem 'simplecov', '~> 0.9' gem 'simplecov', '~> 0.9'
gem 'mime-types', '~> 1.5' gem 'mime-types', '~> 1.5'
gem 'kramdown', '~> 1.7.0'
gem 'jekyll_test_plugin' gem 'jekyll_test_plugin'
gem 'jekyll_test_plugin_malicious' gem 'jekyll_test_plugin_malicious'
gem 'liquid-c', '~> 3.0'
gem 'minitest'
gem 'minitest-reporters' gem 'minitest-reporters'
gem 'minitest-profile' gem 'minitest-profile'
gem 'test-unit' if RUBY_PLATFORM =~ /cygwin/ || RUBY_VERSION.start_with?("2.2") gem 'minitest'
gem 'rspec-mocks' gem 'rspec-mocks'
if ENV['BENCHMARK'] if ENV['BENCHMARK']

View File

@ -1,12 +1,15 @@
#! /bin/bash #! /bin/bash -e
script/branding script/branding
set -e if [[ -z "$TEST_SUITE" ]]
then
if test -z "$TEST_SUITE"; then script/test ci
script/test
script/cucumber script/cucumber
else elif [[ -x "script/$TEST_SUITE" ]]
then
script/$TEST_SUITE script/$TEST_SUITE
else
echo "Unknown test suite."
exit 1
fi fi

View File

@ -1,5 +1,11 @@
#!/bin/bash #!/bin/bash
time bundle exec cucumber \ if ruby --version | grep -q "jruby"
-f Features::Support::Overview \ 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

View File

@ -1,15 +1,55 @@
#! /bin/bash #! /bin/bash -e
set -e
# Usage: # Usage:
# script/test
# script/test <test_file> # script/test <test_file>
# script/test [ruby|jruby]
# script/test
if [ -d test/dest ] if [ -d test/dest ]
then rm -r test/dest then rm -r test/dest
fi fi
if [[ $# -lt 1 ]] # -----------------------------------------------------------------------------
then time bundle exec rake TESTOPTS='--profile' test # If you send us a ruby then we use that, if you do not then we test with
else time bundle exec ruby -Itest "$@" --profile # 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 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

View File

@ -1,3 +1,7 @@
def jruby?
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
end
unless ENV['TRAVIS'] unless ENV['TRAVIS']
require File.expand_path('../simplecov_custom_profile', __FILE__) require File.expand_path('../simplecov_custom_profile', __FILE__)
SimpleCov.start('gem') do SimpleCov.start('gem') do
@ -15,19 +19,25 @@ require 'rspec/mocks'
require 'jekyll' require 'jekyll'
require 'rdiscount' unless jruby?
require 'kramdown' require 'rdiscount'
require 'redcarpet' require 'redcarpet'
end
require 'kramdown'
require 'shoulda' require 'shoulda'
include Jekyll 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:') STDERR.reopen(test(?e, '/dev/null') ? '/dev/null' : 'NUL:')
# Report with color. # 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 class JekyllUnitTest < Minitest::Test
include ::RSpec::Mocks::ExampleMethods include ::RSpec::Mocks::ExampleMethods

View File

@ -4,10 +4,22 @@ class TestRdiscount < JekyllUnitTest
context "rdiscount" do context "rdiscount" do
setup do setup do
if jruby?
then skip(
"JRuby does not perform well with CExt, test disabled."
)
end
config = { config = {
'markdown' => 'rdiscount', 'markdown' => 'rdiscount',
'rdiscount' => { 'extensions' => ['smart', 'generate_toc'], 'toc_token' => '{:toc}' } 'rdiscount' => {
'toc_token' => '{:toc}',
'extensions' => [
'smart', 'generate_toc'
],
}
} }
@markdown = Converters::Markdown.new config @markdown = Converters::Markdown.new config
end end

View File

@ -3,10 +3,21 @@ require 'helper'
class TestRedcarpet < JekyllUnitTest class TestRedcarpet < JekyllUnitTest
context "redcarpet" do context "redcarpet" do
setup do setup do
if jruby?
then skip(
"JRuby does not perform well with CExt, test disabled."
)
end
@config = { @config = {
'redcarpet' => { 'extensions' => ['smart', 'strikethrough', 'filter_html'] }, 'markdown' => 'redcarpet',
'markdown' => 'redcarpet' 'redcarpet' => {
'extensions' => [
'smart', 'strikethrough', 'filter_html'
]
}
} }
@markdown = Converters::Markdown.new @config @markdown = Converters::Markdown.new @config
end end

View File

@ -20,8 +20,17 @@ class TestRelatedPosts < JekyllUnitTest
context "building related posts with lsi" do context "building related posts with lsi" do
setup 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) allow_any_instance_of(Jekyll::RelatedPosts).to receive(:display)
@site = fixture_site({"lsi" => true}) @site = fixture_site({
"lsi" => true
})
@site.reset @site.reset
@site.read @site.read
require 'classifier-reborn' require 'classifier-reborn'
@ -38,7 +47,7 @@ class TestRelatedPosts < JekyllUnitTest
post = @site.posts.last post = @site.posts.last
allow_any_instance_of(::ClassifierReborn::LSI).to receive(:build_index) 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]) expect_any_instance_of(::ClassifierReborn::LSI).to receive(:find_related).with(post, 11).and_return(@site.posts[-1..-9])
Jekyll::RelatedPosts.new(post).build Jekyll::RelatedPosts.new(post).build
end end

View File

@ -136,6 +136,14 @@ CONTENT
end end
context "with the pygments highlighter" do 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 context "post content has highlight tag" do
setup do setup do
fill_post("test", {'highlighter' => 'pygments'}) fill_post("test", {'highlighter' => 'pygments'})
@ -353,7 +361,15 @@ CONTENT
context "using RDiscount" do context "using RDiscount" do
setup 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 end
should "parse correctly" do should "parse correctly" do
@ -375,7 +391,15 @@ CONTENT
context "using Redcarpet" do context "using Redcarpet" do
setup 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 end
should "parse correctly" do should "parse correctly" do