summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/spec_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/optional/capi/spec_helper.rb')
-rw-r--r--spec/ruby/optional/capi/spec_helper.rb23
1 files changed, 12 insertions, 11 deletions
diff --git a/spec/ruby/optional/capi/spec_helper.rb b/spec/ruby/optional/capi/spec_helper.rb
index d5ac1408a1d..e5d1d54daad 100644
--- a/spec/ruby/optional/capi/spec_helper.rb
+++ b/spec/ruby/optional/capi/spec_helper.rb
@@ -1,4 +1,4 @@
-require_relative '../../spec_helper'
+# Require the main spec_helper.rb at the end to let `ruby ...spec.rb` work
# MRI magic to use built but not installed ruby
$extmk = false
@@ -6,13 +6,9 @@ $extmk = false
require 'rbconfig'
OBJDIR ||= File.expand_path("../../../ext/#{RUBY_ENGINE}/#{RUBY_VERSION}", __FILE__)
-mkdir_p(OBJDIR)
-
-def extension_path
- File.expand_path("../ext", __FILE__)
-end
def object_path
+ mkdir_p(OBJDIR)
OBJDIR
end
@@ -20,6 +16,7 @@ def compile_extension(name)
debug = false
run_mkmf_in_process = RUBY_ENGINE == 'truffleruby'
+ ext_dir = File.expand_path("../ext", __FILE__)
ext = "#{name}_spec"
lib = "#{object_path}/#{ext}.#{RbConfig::CONFIG['DLEXT']}"
ruby_header = "#{RbConfig::CONFIG['rubyhdrdir']}/ruby.h"
@@ -31,8 +28,8 @@ def compile_extension(name)
# not found, then compile
else
case # if lib is older than headers, source or libruby, then recompile
- when mtime <= File.mtime("#{extension_path}/rubyspec.h")
- when mtime <= File.mtime("#{extension_path}/#{ext}.c")
+ when mtime <= File.mtime("#{ext_dir}/rubyspec.h")
+ when mtime <= File.mtime("#{ext_dir}/#{ext}.c")
when mtime <= File.mtime(ruby_header)
when libruby_so && mtime <= File.mtime("#{RbConfig::CONFIG['libdir']}/#{libruby_so}")
else
@@ -45,7 +42,7 @@ def compile_extension(name)
Dir.mkdir(tmpdir)
begin
["rubyspec.h", "#{ext}.c"].each do |file|
- cp "#{extension_path}/#{file}", "#{tmpdir}/#{file}"
+ cp "#{ext_dir}/#{file}", "#{tmpdir}/#{file}"
end
Dir.chdir(tmpdir) do
@@ -108,8 +105,8 @@ end
def load_extension(name)
require compile_extension(name)
-rescue LoadError
- if %r{/usr/sbin/execerror ruby "\(ld 3 1 main ([/a-zA-Z0-9_\-.]+_spec\.so)"} =~ $!.message
+rescue LoadError => e
+ if %r{/usr/sbin/execerror ruby "\(ld 3 1 main ([/a-zA-Z0-9_\-.]+_spec\.so)"} =~ e.message
system('/usr/sbin/execerror', "#{RbConfig::CONFIG["bindir"]}/ruby", "(ld 3 1 main #{$1}")
end
raise
@@ -117,3 +114,7 @@ end
# Constants
CAPI_SIZEOF_LONG = [0].pack('l!').size
+
+# Require the main spec_helper.rb only here so load_extension() is defined
+# when running specs with `ruby ...spec.rb`
+require_relative '../../spec_helper'