diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 016b288c19..d6340e489d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,10 +12,8 @@ jobs: fail-fast: false matrix: os: - - ubuntu-20.04 - - ubuntu-18.04 - - macos-11.0 - - macos-10.15 + - ubuntu-latest + - macos-latest - windows-latest ruby: - '2.4' @@ -26,11 +24,15 @@ jobs: - '3.1' - debug - jruby-head + - truffleruby + - truffleruby-head include: - { os: windows-latest , ruby: mingw } - { os: windows-latest , ruby: mswin } exclude: - { os: windows-latest , ruby: debug } + - { os: windows-latest , ruby: truffleruby } + - { os: windows-latest , ruby: truffleruby-head } steps: - uses: actions/checkout@v2 @@ -73,3 +75,7 @@ jobs: - run: bundle exec rake test - run: gem install --verbose --backtrace pkg/*.gem + + - name: Run tests on the installed gem + run: ruby run-test.rb + if: matrix.ruby != '2.4' # strscan is a default gem from 2.5 diff --git a/Rakefile b/Rakefile index b886d9a78d..dfd1a008ad 100644 --- a/Rakefile +++ b/Rakefile @@ -23,14 +23,17 @@ if RUBY_ENGINE == "jruby" ext.target_version = '1.8' ext.ext_dir = 'ext/java' end -else +elsif RUBY_ENGINE == "ruby" require 'rake/extensiontask' Rake::ExtensionTask.new("strscan") +else + task :compile end desc "Run test" task :test do - ENV["RUBYOPT"] = "-Ilib -Itest/lib -rbundler/setup -rhelper" + require_path = RUBY_ENGINE == 'jruby' ? "lib/jruby" : "lib" + ENV["RUBYOPT"] = "-I#{require_path} -rbundler/setup" ruby("run-test.rb") end diff --git a/ext/strscan/extconf.rb b/ext/strscan/extconf.rb index f0ecbf85d8..b53b63e455 100644 --- a/ext/strscan/extconf.rb +++ b/ext/strscan/extconf.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true require 'mkmf' -$INCFLAGS << " -I$(top_srcdir)" if $extmk -have_func("onig_region_memsize", "ruby.h") -create_makefile 'strscan' +if RUBY_ENGINE == 'ruby' + $INCFLAGS << " -I$(top_srcdir)" if $extmk + have_func("onig_region_memsize", "ruby.h") + create_makefile 'strscan' +else + File.write('Makefile', dummy_makefile("").join) +end diff --git a/lib/jruby/strscan.rb b/lib/jruby/strscan.rb new file mode 100644 index 0000000000..4f796c25cd --- /dev/null +++ b/lib/jruby/strscan.rb @@ -0,0 +1,2 @@ +require 'strscan.jar' +JRuby::Util.load_ext("org.jruby.ext.strscan.StringScannerLibrary") diff --git a/lib/strscan.rb b/lib/strscan.rb deleted file mode 100644 index 19baccff26..0000000000 --- a/lib/strscan.rb +++ /dev/null @@ -1,6 +0,0 @@ -if RUBY_ENGINE == 'jruby' - require 'strscan.jar' - JRuby::Util.load_ext("org.jruby.ext.strscan.StringScannerLibrary") -else - require 'strscan.so' -end diff --git a/run-test.rb b/run-test.rb index 4ccb024a6b..b4390272ad 100755 --- a/run-test.rb +++ b/run-test.rb @@ -1,8 +1,10 @@ #!/usr/bin/env ruby -$LOAD_PATH.unshift("test") -$LOAD_PATH.unshift("test/lib") -$LOAD_PATH.unshift("lib") +require 'strscan' +puts "Loaded strscan from #{$".grep(/\/strscan\./).join(', ')}" +puts "Gem from #{Gem.loaded_specs["strscan"]&.full_gem_path}" + +require_relative 'test/lib/helper' Dir.glob("test/strscan/**/*test_*.rb") do |test_rb| require File.expand_path(test_rb) diff --git a/strscan.gemspec b/strscan.gemspec index 871636d86c..d59e645695 100644 --- a/strscan.gemspec +++ b/strscan.gemspec @@ -16,14 +16,13 @@ Gem::Specification.new do |s| s.summary = "Provides lexical scanning operations on a String." s.description = "Provides lexical scanning operations on a String." - s.require_path = %w{lib} - jruby = true if Gem::Platform.new('java') =~ s.platform or RUBY_ENGINE == 'jruby' - if jruby - s.files = %w{lib/strscan.jar lib/strscan.rb} + s.require_paths = %w{lib/jruby lib} + s.files = %w{lib/strscan.jar lib/jruby/strscan.rb} s.platform = "java" else + s.require_paths = %w{lib} s.files = %w{ext/strscan/extconf.rb ext/strscan/strscan.c} s.extensions = %w{ext/strscan/extconf.rb} end diff --git a/test/strscan/test_ractor.rb b/test/strscan/test_ractor.rb index 480c1ae8a6..a5de7e56ed 100644 --- a/test/strscan/test_ractor.rb +++ b/test/strscan/test_ractor.rb @@ -3,7 +3,7 @@ class TestStringScannerRactor < Test::Unit::TestCase def setup - pend unless defined? Ractor + omit "Ractor not defined" unless defined? Ractor end def test_ractor diff --git a/test/strscan/test_stringscanner.rb b/test/strscan/test_stringscanner.rb index 6e30be1f7d..b46b47bedd 100644 --- a/test/strscan/test_stringscanner.rb +++ b/test/strscan/test_stringscanner.rb @@ -207,6 +207,8 @@ def test_pos_unicode end def test_charpos_not_use_string_methods + omit "not supported on TruffleRuby" if RUBY_ENGINE == "truffleruby" + string = +'abcädeföghi' scanner = create_string_scanner(string) @@ -567,6 +569,8 @@ def test_encoding_string end def test_invalid_encoding_string + omit "no encoding check on TruffleRuby for scan(String)" if RUBY_ENGINE == "truffleruby" + str = "\xA1\xA2".dup.force_encoding("euc-jp") ss = create_string_scanner(str) assert_raise(Encoding::CompatibilityError) do @@ -712,6 +716,8 @@ def test_inspect2 end def test_aref_without_regex + omit "#[:missing] always raises on TruffleRuby if matched" if RUBY_ENGINE == "truffleruby" + s = create_string_scanner('abc') s.get_byte assert_nil(s[:c])