diff options
author | Lars Kanis <lars@greiz-reinsdorf.de> | 2020-07-17 23:59:29 +0200 |
---|---|---|
committer | Lars Kanis <lars@greiz-reinsdorf.de> | 2020-07-18 00:03:05 +0200 |
commit | 78500eaaa383d8ffb2694b10c8fe8bafb8a476cb (patch) | |
tree | c1be7b62a59cc2478135e3f923e69436615e0a19 /spec | |
parent | 64ac023d6ebce811aa51e06357abf6f803b563a6 (diff) | |
download | ffi-78500eaaa383d8ffb2694b10c8fe8bafb8a476cb.tar.gz |
Move external process execution to spec_helpers
... so that it can be reused in other specs.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ffi/callback_spec.rb | 15 | ||||
-rw-r--r-- | spec/ffi/spec_helper.rb | 18 |
2 files changed, 20 insertions, 13 deletions
diff --git a/spec/ffi/callback_spec.rb b/spec/ffi/callback_spec.rb index c8b9166..2779b26 100644 --- a/spec/ffi/callback_spec.rb +++ b/spec/ffi/callback_spec.rb @@ -878,20 +878,9 @@ module CallbackInteropSpecs if RUBY_ENGINE == 'ruby' it "C outside ffi call stack does not deadlock [#527]" do skip "not yet supported on TruffleRuby" if RUBY_ENGINE == "truffleruby" - path = File.join(File.dirname(__FILE__), "embed-test/embed-test.rb") - pid = spawn(RbConfig.ruby, "-Ilib", path, { [:out, :err] => "embed-test.log" }) - begin - Timeout.timeout(10){ Process.wait(pid) } - rescue Timeout::Error - Process.kill(9, pid) - raise - else - if $?.exitstatus != 0 - raise "external process failed:\n#{ File.read("embed-test.log") }" - end - end - expect(File.read("embed-test.log")).to match(/callback called with \["hello", 5, 0\]/) + out = external_run(RbConfig.ruby, "embed-test/embed-test.rb") + expect(out).to match(/callback called with \["hello", 5, 0\]/) end end end diff --git a/spec/ffi/spec_helper.rb b/spec/ffi/spec_helper.rb index f84771e..5bfcdb9 100644 --- a/spec/ffi/spec_helper.rb +++ b/spec/ffi/spec_helper.rb @@ -4,6 +4,7 @@ # require_relative 'fixtures/compile' +require 'timeout' RSpec.configure do |c| c.filter_run_excluding :broken => true @@ -25,3 +26,20 @@ module LibTest extend FFI::Library ffi_lib TestLibrary::PATH end + +def external_run(cmd, rb_file, options: [], timeout: 10) + path = File.join(File.dirname(__FILE__), rb_file) + log = "#{path}.log" + pid = spawn(cmd, "-Ilib", path, { [:out, :err] => log }) + begin + Timeout.timeout(timeout){ Process.wait(pid) } + rescue Timeout::Error + Process.kill(9, pid) + raise + else + if $?.exitstatus != 0 + raise "external process failed:\n#{ File.read(log) }" + end + end + File.read(log) +end |