diff --git a/.github/workflows/jruby.yml b/.github/workflows/jruby.yml new file mode 100644 index 0000000..2c51c22 --- /dev/null +++ b/.github/workflows/jruby.yml @@ -0,0 +1,30 @@ +name: build + +on: + push: + pull_request: + schedule: + - cron: '12 3 * * *' + +jobs: + build: + name: build (${{ matrix.ruby }} / ${{ matrix.os }}) + strategy: + matrix: + ruby: [ 'jruby-9.3' ] + os: [ ubuntu-latest ] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # 'bundle install' and enable caching + - name: Build + run: bundle exec rake build + - name: Run test + run: bundle exec rake test +# Temporarily skipped until a released version of JRuby support 2.7+ +# - name: Installation test +# run: gem install pkg/*.gem diff --git a/Gemfile b/Gemfile index eb86192..0ab3dc1 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,4 @@ source "https://rubygems.org" gem "rake" gem "test-unit" +gem "ruby2_keywords", group: :test \ No newline at end of file diff --git a/lib/pp.rb b/lib/pp.rb index 72480e5..253aecb 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -424,7 +424,7 @@ def pretty_print(q) # :nodoc: class File < IO # :nodoc: class Stat # :nodoc: def pretty_print(q) # :nodoc: - require 'etc.so' + require 'etc' q.object_group(self) { q.breakable q.text sprintf("dev=0x%x", self.dev); q.comma_breakable @@ -530,37 +530,39 @@ def pretty_print(q) # :nodoc: end end -class RubyVM::AbstractSyntaxTree::Node - def pretty_print_children(q, names = []) - children.zip(names) do |c, n| - if n - q.breakable - q.text "#{n}:" - end - q.group(2) do - q.breakable - q.pp c +if defined?(RubyVM::AbstractSyntaxTree) + class RubyVM::AbstractSyntaxTree::Node + def pretty_print_children(q, names = []) + children.zip(names) do |c, n| + if n + q.breakable + q.text "#{n}:" + end + q.group(2) do + q.breakable + q.pp c + end end end - end - def pretty_print(q) - q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") { - case type - when :SCOPE - pretty_print_children(q, %w"tbl args body") - when :ARGS - pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block]) - when :DEFN - pretty_print_children(q, %w[mid body]) - when :ARYPTN - pretty_print_children(q, %w[const pre rest post]) - when :HSHPTN - pretty_print_children(q, %w[const kw kwrest]) - else - pretty_print_children(q) - end - } + def pretty_print(q) + q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") { + case type + when :SCOPE + pretty_print_children(q, %w"tbl args body") + when :ARGS + pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block]) + when :DEFN + pretty_print_children(q, %w[mid body]) + when :ARYPTN + pretty_print_children(q, %w[const pre rest post]) + when :HSHPTN + pretty_print_children(q, %w[const kw kwrest]) + else + pretty_print_children(q) + end + } + end end end diff --git a/test/test_pp.rb b/test/test_pp.rb index 4aa3195..9cef555 100644 --- a/test/test_pp.rb +++ b/test/test_pp.rb @@ -3,6 +3,16 @@ require 'pp' require 'delegate' require 'test/unit' +require 'ruby2_keywords' + +# Define bind_call for Ruby 2.6 and earlier, to allow testing on JRuby 9.3 +class UnboundMethod + unless public_method_defined?(:bind_call) + def bind_call(obj, *args, &block) + bind(obj).call(*args, &block) + end + end +end module PPTestModule @@ -158,7 +168,7 @@ def test_withinspect a << HasInspect.new(a) assert_equal("[]\n", PP.pp(a, ''.dup)) assert_equal("#{a.inspect}\n", PP.pp(a, ''.dup)) - end + end unless RUBY_VERSION < "2.7" # temporary mask to test on JRuby 9.3 (2.6 equivalent) def test_share_nil begin