Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/truffleruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: TruffleRuby

on:
push:
branches:
- master
pull_request: {}
merge_group: {}

permissions:
contents: read

jobs:
test:
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
ruby: ['truffleruby']
job:
- test
env:
RANDOMIZE_STDLIB_TEST_ORDER: "true"
# TruffleRuby warns and falls back to US-ASCII unless the locale is UTF-8.
LANG: "en_US.UTF-8"
steps:
- uses: actions/checkout@v6
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler: none
- name: Set working directory as safe
run: git config --global --add safe.directory $(pwd)
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libdb-dev curl autoconf automake m4 libtool python3
- name: Update rubygems & bundler
run: |
ruby -v
gem update --system
- name: install erb
run: gem install erb
- name: bundle config
run: |
# Profilers and the typecheck tooling are not needed for the smoke test,
# and some of them do not support TruffleRuby.
bundle config set --local without 'profilers typecheck_test'
- name: bin/setup
run: |
bin/setup
- name: Run test
run: |
bundle exec rake ${{ matrix.job }}
6 changes: 6 additions & 0 deletions test/rbs/ast/ruby/comment_block_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def test__buffer__multi_line_prefix_header_line
end

def test_build
omit_on_truffle_ruby! "`Prism::Location#start_line_slice` returns `nil` on TruffleRuby's prism"

buffer, comments = parse_comments(<<~RUBY)
# Comment1
# Comment2
Expand Down Expand Up @@ -188,6 +190,8 @@ def test_each_paragraph_colon
end

def test_trailing_annotation
omit_on_truffle_ruby! "`Prism::Location#start_line_slice` returns `nil` on TruffleRuby's prism"

buffer, comments = parse_comments(<<~RUBY)
foo #: String

Expand Down Expand Up @@ -218,6 +222,8 @@ def test_trailing_annotation
end

def test_trailing_annotation_type_application
omit_on_truffle_ruby! "`Prism::Location#start_line_slice` returns `nil` on TruffleRuby's prism"

buffer, comments = parse_comments(<<~RUBY)
foo #[String]

Expand Down
10 changes: 10 additions & 0 deletions test/rbs/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ def test_parse_method_type
end

def test_prototype_no_parser
omit_on_truffle_ruby! "`rbs prototype` requires `RubyVM::AbstractSyntaxTree`, which is not available on TruffleRuby"

Dir.mktmpdir do |dir|
with_cli do |cli|
def cli.has_parser?
Expand All @@ -907,6 +909,8 @@ def cli.has_parser?
end

def test_prototype_batch
omit_on_truffle_ruby! "`rbs prototype` requires `RubyVM::AbstractSyntaxTree`, which is not available on TruffleRuby"

Dir.mktmpdir do |dir|
dir = Pathname(dir)

Expand Down Expand Up @@ -968,6 +972,8 @@ module C
end

def test_prototype_batch_outer
omit_on_truffle_ruby! "`rbs prototype` requires `RubyVM::AbstractSyntaxTree`, which is not available on TruffleRuby"

Dir.mktmpdir do |dir|
dir = Pathname(dir)

Expand All @@ -994,6 +1000,8 @@ module A
end

def test_prototype_batch_syntax_error
omit_on_truffle_ruby! "`rbs prototype` requires `RubyVM::AbstractSyntaxTree`, which is not available on TruffleRuby"

Dir.mktmpdir do |dir|
dir = Pathname(dir)

Expand Down Expand Up @@ -1042,6 +1050,8 @@ def test_prototype__runtime__todo


def test_test
omit_on_truffle_ruby! "`rbs test` relies on `TracePoint` `:end` event, which is not supported on TruffleRuby"

Dir.mktmpdir do |dir|
dir = Pathname(dir)
dir.join('foo.rbs').write(<<~RBS)
Expand Down
2 changes: 2 additions & 0 deletions test/rbs/location_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ def test_sub_buffer_local_location
end

def test_gc_compaction
omit_on_truffle_ruby! "`GC.compact` is not implemented on TruffleRuby"

GC.disable
buffer = buffer()
locations = 10.times.map do |i|
Expand Down
2 changes: 2 additions & 0 deletions test/rbs/node_usage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def parse(string)
end

def test_conditional
omit_on_truffle_ruby! "`RubyVM::AbstractSyntaxTree` is not available on TruffleRuby"

NodeUsage.new(parse(<<~RB))
def block
yield
Expand Down
2 changes: 2 additions & 0 deletions test/rbs/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,8 @@ def test_invalid_utf8_byte_in_comment_does_not_hang
end

def test_invalid_utf8_byte_at_top_level_raises
omit_on_truffle_ruby! "The C extension does not raise `RBS::ParsingError` for an invalid UTF-8 byte on TruffleRuby"

# Regression: invalid UTF-8 byte at top level used to trip RBS_ASSERT in the C extension.
source = "\xFF".dup.force_encoding(Encoding::UTF_8)
Timeout.timeout(5) do
Expand Down
2 changes: 2 additions & 0 deletions test/rbs/rb_prototype_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "test_helper"

class RBS::RbPrototypeTest < Test::Unit::TestCase
omit_on_truffle_ruby! "`RubyVM::AbstractSyntaxTree` is not available on TruffleRuby"

RB = RBS::Prototype::RB

include TestHelper
Expand Down
2 changes: 2 additions & 0 deletions test/rbs/rbi_prototype_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "test_helper"

class RBS::RbiPrototypeTest < Test::Unit::TestCase
omit_on_truffle_ruby! "`RubyVM::AbstractSyntaxTree` is not available on TruffleRuby"

RBI = RBS::Prototype::RBI

include TestHelper
Expand Down
2 changes: 2 additions & 0 deletions test/rbs/runtime_prototype_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "test_helper"

class RBS::RuntimePrototypeTest < Test::Unit::TestCase
omit_on_truffle_ruby! "`RubyVM::AbstractSyntaxTree` is not available on TruffleRuby"

Runtime = RBS::Prototype::Runtime
DefinitionBuilder = RBS::DefinitionBuilder

Expand Down
2 changes: 2 additions & 0 deletions test/rbs/test/runtime_test_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
return unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')

class RBS::Test::RuntimeTestTest < Test::Unit::TestCase
omit_on_truffle_ruby! "`rbs test` relies on `TracePoint` `:end` event, which is not supported on TruffleRuby"

include TestHelper

def test_runtime_success
Expand Down
4 changes: 4 additions & 0 deletions test/rbs/test/type_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class RBS::Test::TypeCheckTest < Test::Unit::TestCase
include RBS

def test_type_check
omit_on_truffle_ruby! "Type checking a block-less `loop` Enumerator behaves differently on TruffleRuby"

SignatureManager.new do |manager|
manager.files[Pathname("foo.rbs")] = <<EOF
class Array[Elem]
Expand Down Expand Up @@ -334,6 +336,8 @@ def test_type_check_hash_sampling
end

def test_type_check_enumerator_sampling
omit_on_truffle_ruby! "Type checking a block-less `loop` Enumerator behaves differently on TruffleRuby"

SignatureManager.new do |manager|
manager.build do |env|
builder = DefinitionBuilder.new(env: env)
Expand Down
29 changes: 29 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,35 @@

class Test::Unit::TestCase
prepend TestSkip

# Omit *all* test cases defined in this class when running on TruffleRuby.
#
# Call it at the class body level for features that are known not to work on
# TruffleRuby (e.g. those relying on `RubyVM::AbstractSyntaxTree` or
# `TracePoint` events that TruffleRuby does not implement):
#
# class RBS::RuntimePrototypeTest < Test::Unit::TestCase
# omit_on_truffle_ruby! "RubyVM::AbstractSyntaxTree is not available"
# # ...
# end
def self.omit_on_truffle_ruby!(reason = "Not supported on TruffleRuby")
return unless RUBY_ENGINE == "truffleruby"

setup { omit(reason) }
end

# Omit the running test case when running on TruffleRuby.
#
# Use it inside a test method when only a few cases of an otherwise supported
# class fail on TruffleRuby:
#
# def test_something
# omit_on_truffle_ruby!
# # ...
# end
def omit_on_truffle_ruby!(reason = "Not supported on TruffleRuby")
omit(reason) if RUBY_ENGINE == "truffleruby"
end
end

module TestHelper
Expand Down
Loading