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.1
- 2.0
- jruby-head
env:
matrix:
- TEST_SUITE=test

22
Gemfile
View File

@ -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']

View File

@ -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

View File

@ -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

View File

@ -1,15 +1,55 @@
#! /bin/bash
set -e
#! /bin/bash -e
# Usage:
# script/test
# script/test <test_file>
# 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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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