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