[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / test / win32ole / test_err_in_callback.rb
blobbea5781bc9e70c6ca7ac36dcf13addc5befb3392
1 # frozen_string_literal: false
3 # test Win32OLE avoids cfp consistency error when the exception raised
4 # in WIN32OLE::Event handler block. [ruby-dev:35450]
7 begin
8   require 'win32ole'
9 rescue LoadError
10 end
11 if defined?(WIN32OLE)
12   require 'mkmf'
13   require 'pathname'
14   require 'test/unit'
15   require 'tmpdir'
16   class TestErrInCallBack < Test::Unit::TestCase
17     def setup
18       @ruby = nil
19       if File.exist?("./" + CONFIG["RUBY_INSTALL_NAME"] + CONFIG["EXEEXT"])
20         sep = File::ALT_SEPARATOR || "/"
21         @ruby = "." + sep + CONFIG["RUBY_INSTALL_NAME"]
22         cwd = Pathname.new(File.expand_path('.'))
23         @iopt = $:.map {|e|
24           " -I " + (Pathname.new(e).relative_path_from(cwd).to_s rescue e)
25         }.join("")
26         script = File.join(File.dirname(__FILE__), "err_in_callback.rb")
27         @script = Pathname.new(script).relative_path_from(cwd).to_s rescue script
28       end
29     end
31     def available_adodb?
32       begin
33         WIN32OLE.new('ADODB.Connection')
34       rescue WIN32OLE::RuntimeError
35         return false
36       end
37       return true
38     end
40     def test_err_in_callback
41       omit "'ADODB.Connection' is not available" unless available_adodb?
42       if @ruby
43         Dir.mktmpdir do |tmpdir|
44           logfile = File.join(tmpdir, "test_err_in_callback.log")
45           cmd = "#{@ruby} -v #{@iopt} #{@script} > #{logfile.gsub(%r(/), '\\')} 2>&1"
46           system(cmd)
47           str = ""
48           open(logfile) {|ifs|
49             str = ifs.read
50           }
51           assert_match(/NameError/, str)
52         end
53       end
54     end
55   end
56 end