* test/ruby/test_beginendblock.rb: add tests for nested BEGIN/END.
* test/ruby/beginmainend.rb: add tests for nested BEGIN/END. * test/ruby/endblockwarn.rb: new file added to test of END-in-method warning. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0a5f6fd37d
commit
cd8d08b532
@ -1,3 +1,12 @@
|
|||||||
|
Tue Oct 7 15:23:09 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
||||||
|
|
||||||
|
* test/ruby/test_beginendblock.rb: add tests for nested BEGIN/END.
|
||||||
|
|
||||||
|
* test/ruby/beginmainend.rb: add tests for nested BEGIN/END.
|
||||||
|
|
||||||
|
* test/ruby/endblockwarn.rb: new file added to test of END-in-method
|
||||||
|
warning.
|
||||||
|
|
||||||
Tue Oct 7 12:23:47 2003 Tanaka Akira <akr@m17n.org>
|
Tue Oct 7 12:23:47 2003 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
* ext/fcntl/fcntl.c (Init_fcntl): define Fcntl::O_ACCMODE.
|
* ext/fcntl/fcntl.c (Init_fcntl): define Fcntl::O_ACCMODE.
|
||||||
|
@ -1,25 +1,31 @@
|
|||||||
|
errout = ARGV.shift
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
puts "begin1"
|
puts "b1"
|
||||||
local_begin1 = "local_begin1"
|
local_begin1 = "local_begin1"
|
||||||
$global_begin1 = "global_begin1"
|
$global_begin1 = "global_begin1"
|
||||||
ConstBegin1 = "ConstBegin1"
|
ConstBegin1 = "ConstBegin1"
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
puts "begin2"
|
puts "b2"
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
puts "b2-1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# for scope check
|
# for scope check
|
||||||
raise if defined?(local_begin1)
|
raise if defined?(local_begin1)
|
||||||
raise unless defined?($global_begin1)
|
raise unless defined?($global_begin1)
|
||||||
raise unless defined?(::ConstBegin1)
|
raise unless defined?(::ConstBegin1)
|
||||||
local_for_end2 = "end2"
|
local_for_end2 = "e2"
|
||||||
$global_for_end1 = "end1"
|
$global_for_end1 = "e1"
|
||||||
|
|
||||||
puts "main"
|
puts "main"
|
||||||
|
|
||||||
END {
|
END {
|
||||||
puts local_for_end2
|
puts local_for_end2 # e2
|
||||||
}
|
}
|
||||||
|
|
||||||
END {
|
END {
|
||||||
@ -29,27 +35,51 @@ END {
|
|||||||
|
|
||||||
eval <<EOE
|
eval <<EOE
|
||||||
BEGIN {
|
BEGIN {
|
||||||
puts "innerbegin1"
|
puts "b3"
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
puts "b3-1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
puts "innerbegin2"
|
puts "b4"
|
||||||
}
|
}
|
||||||
|
|
||||||
END {
|
END {
|
||||||
puts "innerend2"
|
puts "e3"
|
||||||
}
|
}
|
||||||
|
|
||||||
END {
|
END {
|
||||||
puts "innerend1"
|
puts "e4"
|
||||||
|
|
||||||
|
END {
|
||||||
|
puts "e4-1"
|
||||||
|
|
||||||
|
END {
|
||||||
|
puts "e4-1-1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
END {
|
||||||
|
puts "e4-2"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
EOE
|
EOE
|
||||||
|
|
||||||
END {
|
END {
|
||||||
exit
|
exit
|
||||||
puts "should not be dumped"
|
puts "should not be dumped"
|
||||||
|
|
||||||
|
END {
|
||||||
|
puts "not reached"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
END {
|
END {
|
||||||
puts $global_for_end1
|
puts $global_for_end1 # e1
|
||||||
|
|
||||||
|
END {
|
||||||
|
puts "e1-1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
26
test/ruby/endblockwarn.rb
Normal file
26
test/ruby/endblockwarn.rb
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
BEGIN {
|
||||||
|
if errout = ARGV.shift
|
||||||
|
dir = File.dirname(File.expand_path(__FILE__))
|
||||||
|
basename = File.basename(__FILE__)
|
||||||
|
require "#{dir}/envutil"
|
||||||
|
STDERR.reopen(File.open(errout, "w"))
|
||||||
|
STDERR.sync = true
|
||||||
|
Dir.chdir(dir)
|
||||||
|
cmd = "\"#{EnvUtil.rubybin}\" \"#{basename}\""
|
||||||
|
exec(cmd)
|
||||||
|
exit!("must not reach here")
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
def end1
|
||||||
|
END {}
|
||||||
|
end
|
||||||
|
|
||||||
|
end1
|
||||||
|
|
||||||
|
eval <<EOE
|
||||||
|
def end2
|
||||||
|
END {}
|
||||||
|
end
|
||||||
|
EOE
|
||||||
|
|
@ -1,27 +1,57 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
require 'tempfile'
|
||||||
require "#{File.dirname(File.expand_path(__FILE__))}/envutil"
|
require "#{File.dirname(File.expand_path(__FILE__))}/envutil"
|
||||||
|
|
||||||
class TestBeginEndBlock < Test::Unit::TestCase
|
class TestBeginEndBlock < Test::Unit::TestCase
|
||||||
DIR = File.dirname(File.expand_path(__FILE__))
|
DIR = File.dirname(File.expand_path(__FILE__))
|
||||||
|
|
||||||
|
def q(content)
|
||||||
|
"\"#{content}\""
|
||||||
|
end
|
||||||
|
|
||||||
def test_beginendblock
|
def test_beginendblock
|
||||||
ruby = EnvUtil.rubybin
|
ruby = EnvUtil.rubybin
|
||||||
io = IO.popen("\"#{ruby}\" \"#{DIR}/beginmainend.rb\"")
|
target = File.join(DIR, 'beginmainend.rb')
|
||||||
assert_equal(%w(begin1 begin2 main innerbegin1 innerbegin2 end1 innerend1 innerend2 end2).join("\n") << "\n", io.read)
|
io = IO.popen("#{q(ruby)} #{q(target)}")
|
||||||
|
assert_equal(%w(b1 b2-1 b2 main b3-1 b3 b4 e1 e4 e3 e2 e4-2 e4-1 e1-1 e4-1-1), io.read.split)
|
||||||
|
io.close
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_begininmethod
|
def test_begininmethod
|
||||||
assert_raises(SyntaxError) do
|
assert_raises(SyntaxError) do
|
||||||
eval("def foo; BEGIN {}; end")
|
eval("def foo; BEGIN {}; end")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert_raises(SyntaxError) do
|
||||||
|
eval('eval("def foo; BEGIN {}; end")')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_endinmethod
|
def test_endblockwarn
|
||||||
verbose, $VERBOSE = $VERBOSE, nil
|
ruby = EnvUtil.rubybin
|
||||||
assert_nothing_raised(SyntaxError) do
|
# Use Tempfile to create temporary file path.
|
||||||
eval("def foo; END {}; end")
|
launcher = Tempfile.new(self.class.name)
|
||||||
end
|
errout = Tempfile.new(self.class.name)
|
||||||
ensure
|
|
||||||
$VERBOSE = verbose
|
launcher << <<EOF
|
||||||
|
errout = ARGV.shift
|
||||||
|
STDERR.reopen(File.open(errout, "w"))
|
||||||
|
STDERR.sync = true
|
||||||
|
Dir.chdir(#{q(DIR)})
|
||||||
|
cmd = "\\"#{ruby}\\" \\"endblockwarn.rb\\""
|
||||||
|
exec(cmd)
|
||||||
|
exit!("must not reach here")
|
||||||
|
EOF
|
||||||
|
launcher.close
|
||||||
|
launcherpath = launcher.path
|
||||||
|
errout.close
|
||||||
|
erroutpath = errout.path
|
||||||
|
system("#{q(ruby)} #{q(launcherpath)} #{q(erroutpath)}")
|
||||||
|
expected = <<EOW
|
||||||
|
endblockwarn.rb:16: warning: END in method; use at_exit
|
||||||
|
(eval):2: warning: END in method; use at_exit
|
||||||
|
EOW
|
||||||
|
assert_equal(expected, File.read(erroutpath))
|
||||||
|
# expecting Tempfile to unlink launcher and errout file.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,6 +13,9 @@ class TestFloat < Test::Unit::TestCase
|
|||||||
assert_equal(3, 2.6.round)
|
assert_equal(3, 2.6.round)
|
||||||
assert_equal(-2, (-2.4).truncate)
|
assert_equal(-2, (-2.4).truncate)
|
||||||
assert((13.4 % 1 - 0.4).abs < 0.0001)
|
assert((13.4 % 1 - 0.4).abs < 0.0001)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_nan
|
||||||
nan = 0.0/0
|
nan = 0.0/0
|
||||||
def nan.test(v)
|
def nan.test(v)
|
||||||
extend Test::Unit::Assertions
|
extend Test::Unit::Assertions
|
||||||
@ -36,7 +39,9 @@ class TestFloat < Test::Unit::TestCase
|
|||||||
nan.test(-0.001);
|
nan.test(-0.001);
|
||||||
nan.test(1.0/0);
|
nan.test(1.0/0);
|
||||||
nan.test(-1.0/0);
|
nan.test(-1.0/0);
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_precision
|
||||||
#s = "3.7517675036461267e+17"
|
#s = "3.7517675036461267e+17"
|
||||||
#assert(s == sprintf("%.16e", s.to_f))
|
#assert(s == sprintf("%.16e", s.to_f))
|
||||||
f = 3.7517675036461267e+17
|
f = 3.7517675036461267e+17
|
||||||
|
Loading…
x
Reference in New Issue
Block a user