2008-07-25 10:49:53 -04:00
|
|
|
#
|
|
|
|
# test Win32OLE avoids cfp consistency error when the exception raised
|
|
|
|
# in WIN32OLE_EVENT handler block. [ruby-dev:35450]
|
|
|
|
#
|
|
|
|
|
|
|
|
begin
|
|
|
|
require 'win32ole'
|
|
|
|
rescue LoadError
|
|
|
|
end
|
|
|
|
if defined?(WIN32OLE)
|
2008-08-12 00:35:13 -04:00
|
|
|
require 'mkmf'
|
2013-03-20 02:24:14 -04:00
|
|
|
require 'pathname'
|
2008-08-12 00:35:13 -04:00
|
|
|
require 'test/unit'
|
2013-03-18 01:47:37 -04:00
|
|
|
require 'tmpdir'
|
2008-07-25 10:49:53 -04:00
|
|
|
class TestErrInCallBack < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
@ruby = nil
|
|
|
|
if File.exist?("./" + CONFIG["RUBY_INSTALL_NAME"] + CONFIG["EXEEXT"])
|
2008-08-02 09:59:43 -04:00
|
|
|
sep = File::ALT_SEPARATOR || "/"
|
|
|
|
@ruby = "." + sep + CONFIG["RUBY_INSTALL_NAME"]
|
2013-03-20 02:24:14 -04:00
|
|
|
cwd = Pathname.new(File.expand_path('.'))
|
2008-07-25 10:49:53 -04:00
|
|
|
@iopt = $:.map {|e|
|
2013-03-20 04:52:04 -04:00
|
|
|
" -I " + (Pathname.new(e).relative_path_from(cwd).to_s rescue e)
|
2008-07-25 10:49:53 -04:00
|
|
|
}.join("")
|
2013-03-20 04:52:04 -04:00
|
|
|
script = File.join(File.dirname(__FILE__), "err_in_callback.rb")
|
|
|
|
@script = Pathname.new(script).relative_path_from(cwd).to_s rescue script
|
2008-07-25 10:49:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-23 06:13:53 -04:00
|
|
|
def available_adodb?
|
|
|
|
begin
|
2014-03-02 14:21:57 -05:00
|
|
|
WIN32OLE.new('ADODB.Connection')
|
2011-07-23 06:13:53 -04:00
|
|
|
rescue WIN32OLERuntimeError
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2008-07-25 10:49:53 -04:00
|
|
|
def test_err_in_callback
|
2011-07-23 06:13:53 -04:00
|
|
|
skip "'ADODB.Connection' is not available" unless available_adodb?
|
2008-07-25 10:49:53 -04:00
|
|
|
if @ruby
|
2013-03-18 01:47:37 -04:00
|
|
|
Dir.mktmpdir do |tmpdir|
|
|
|
|
logfile = File.join(tmpdir, "test_err_in_callback.log")
|
|
|
|
cmd = "#{@ruby} -v #{@iopt} #{@script} > #{logfile.gsub(%r(/), '\\')} 2>&1"
|
2014-03-02 14:21:57 -05:00
|
|
|
system(cmd)
|
2013-03-18 01:47:37 -04:00
|
|
|
str = ""
|
|
|
|
open(logfile) {|ifs|
|
|
|
|
str = ifs.read
|
|
|
|
}
|
|
|
|
assert_match(/NameError/, str)
|
|
|
|
end
|
2008-07-25 10:49:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|