Skip to content

Commit be9255a

Browse files
authored
Merge pull request #4 from headius/no_rubyvm
Only do RubyVM patches if class exists
2 parents 3c6e8e8 + d27e9da commit be9255a

File tree

4 files changed

+73
-30
lines changed

4 files changed

+73
-30
lines changed

.github/workflows/jruby.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: build
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '12 3 * * *'
8+
9+
jobs:
10+
build:
11+
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
12+
strategy:
13+
matrix:
14+
ruby: [ 'jruby-9.3' ]
15+
os: [ ubuntu-latest ]
16+
runs-on: ${{ matrix.os }}
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Set up Ruby
20+
uses: ruby/setup-ruby@v1
21+
with:
22+
ruby-version: ${{ matrix.ruby }}
23+
bundler-cache: true # 'bundle install' and enable caching
24+
- name: Build
25+
run: bundle exec rake build
26+
- name: Run test
27+
run: bundle exec rake test
28+
# Temporarily skipped until a released version of JRuby support 2.7+
29+
# - name: Installation test
30+
# run: gem install pkg/*.gem

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ source "https://rubygems.org"
22

33
gem "rake"
44
gem "test-unit"
5+
gem "ruby2_keywords", group: :test

lib/pp.rb

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def pretty_print(q) # :nodoc:
433433
class File < IO # :nodoc:
434434
class Stat # :nodoc:
435435
def pretty_print(q) # :nodoc:
436-
require 'etc.so'
436+
require 'etc'
437437
q.object_group(self) {
438438
q.breakable
439439
q.text sprintf("dev=0x%x", self.dev); q.comma_breakable
@@ -539,37 +539,39 @@ def pretty_print(q) # :nodoc:
539539
end
540540
end
541541

542-
class RubyVM::AbstractSyntaxTree::Node
543-
def pretty_print_children(q, names = [])
544-
children.zip(names) do |c, n|
545-
if n
546-
q.breakable
547-
q.text "#{n}:"
548-
end
549-
q.group(2) do
550-
q.breakable
551-
q.pp c
542+
if defined?(RubyVM::AbstractSyntaxTree)
543+
class RubyVM::AbstractSyntaxTree::Node
544+
def pretty_print_children(q, names = [])
545+
children.zip(names) do |c, n|
546+
if n
547+
q.breakable
548+
q.text "#{n}:"
549+
end
550+
q.group(2) do
551+
q.breakable
552+
q.pp c
553+
end
552554
end
553555
end
554-
end
555556

556-
def pretty_print(q)
557-
q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
558-
case type
559-
when :SCOPE
560-
pretty_print_children(q, %w"tbl args body")
561-
when :ARGS
562-
pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
563-
when :DEFN
564-
pretty_print_children(q, %w[mid body])
565-
when :ARYPTN
566-
pretty_print_children(q, %w[const pre rest post])
567-
when :HSHPTN
568-
pretty_print_children(q, %w[const kw kwrest])
569-
else
570-
pretty_print_children(q)
571-
end
572-
}
557+
def pretty_print(q)
558+
q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
559+
case type
560+
when :SCOPE
561+
pretty_print_children(q, %w"tbl args body")
562+
when :ARGS
563+
pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
564+
when :DEFN
565+
pretty_print_children(q, %w[mid body])
566+
when :ARYPTN
567+
pretty_print_children(q, %w[const pre rest post])
568+
when :HSHPTN
569+
pretty_print_children(q, %w[const kw kwrest])
570+
else
571+
pretty_print_children(q)
572+
end
573+
}
574+
end
573575
end
574576
end
575577

test/test_pp.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
require 'pp'
44
require 'delegate'
55
require 'test/unit'
6+
require 'ruby2_keywords'
7+
8+
# Define bind_call for Ruby 2.6 and earlier, to allow testing on JRuby 9.3
9+
class UnboundMethod
10+
unless public_method_defined?(:bind_call)
11+
def bind_call(obj, *args, &block)
12+
bind(obj).call(*args, &block)
13+
end
14+
end
15+
end
616

717
module PPTestModule
818

@@ -158,7 +168,7 @@ def test_withinspect
158168
a << HasInspect.new(a)
159169
assert_equal("[<inspect:[...]>]\n", PP.pp(a, ''.dup))
160170
assert_equal("#{a.inspect}\n", PP.pp(a, ''.dup))
161-
end
171+
end unless RUBY_VERSION < "2.7" # temporary mask to test on JRuby 9.3 (2.6 equivalent)
162172

163173
def test_share_nil
164174
begin

0 commit comments

Comments
 (0)