yarv-diff:244
From: ko1 atdot.net
Date: 13 Feb 2006 17:07:02 -0000
Subject: [yarv-diff:244] r407 - in trunk: . test/ruby
Author: aamine
Date: 2006-02-14 02:07:02 +0900 (Tue, 14 Feb 2006)
New Revision: 407
Added:
trunk/test/ruby/beginmainend.rb
trunk/test/ruby/endblockwarn.rb
trunk/test/ruby/test_file.rb
Modified:
trunk/ChangeLog
trunk/test/ruby/test_beginendblock.rb
Log:
* test/ruby/test_beginendblock.rb: unlock tests.
* test/ruby/beginmainend.rb: new file (imported from ruby CVS trunk HEAD).
* test/ruby/endblockwarn.rb: new file (imported from ruby CVS trunk HEAD).
* test/ruby/test_file.rb: new file (imported from ruby CVS trunk HEAD).
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-02-13 16:52:40 UTC (rev 406)
+++ trunk/ChangeLog 2006-02-13 17:07:02 UTC (rev 407)
@@ -4,6 +4,20 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2006-02-14(Tue) 02:06:25 +0900 Minero Aoki <aamine loveruby.net>
+
+ * test/ruby/test_beginendblock.rb: unlock tests.
+
+ * test/ruby/beginmainend.rb: new file (imported from ruby CVS
+ trunk HEAD).
+
+ * test/ruby/endblockwarn.rb: new file (imported from ruby CVS
+ trunk HEAD).
+
+ * test/ruby/test_file.rb: new file (imported from ruby CVS trunk
+ HEAD).
+
+
2006-02-14(Tue) 01:42:11 +0900 Koichi Sasada <ko1 atdot.net>
* error.c : fix include file positon
Added: trunk/test/ruby/beginmainend.rb
===================================================================
--- trunk/test/ruby/beginmainend.rb 2006-02-13 16:52:40 UTC (rev 406)
+++ trunk/test/ruby/beginmainend.rb 2006-02-13 17:07:02 UTC (rev 407)
@@ -0,0 +1,80 @@
+errout = ARGV.shift
+
+BEGIN {
+ puts "b1"
+ local_begin1 = "local_begin1"
+ $global_begin1 = "global_begin1"
+ ConstBegin1 = "ConstBegin1"
+}
+
+BEGIN {
+ puts "b2"
+
+ BEGIN {
+ puts "b2-1"
+ }
+}
+
+# for scope check
+raise if defined?(local_begin1)
+raise unless defined?($global_begin1)
+raise unless defined?(::ConstBegin1)
+local_for_end2 = "e2"
+$global_for_end1 = "e1"
+
+puts "main"
+
+END {
+ puts local_for_end2 # e2
+}
+
+eval <<EOE
+ BEGIN {
+ puts "b3"
+
+ BEGIN {
+ puts "b3-1"
+ }
+ }
+
+ BEGIN {
+ puts "b4"
+ }
+
+ END {
+ puts "e3"
+ }
+
+ END {
+ puts "e4"
+
+ END {
+ puts "e4-1"
+
+ END {
+ puts "e4-1-1"
+ }
+ }
+
+ END {
+ puts "e4-2"
+ }
+ }
+EOE
+
+END {
+ exit
+ puts "should not be dumped"
+
+ END {
+ puts "not reached"
+ }
+}
+
+END {
+ puts $global_for_end1 # e1
+
+ END {
+ puts "e1-1"
+ }
+}
Added: trunk/test/ruby/endblockwarn.rb
===================================================================
--- trunk/test/ruby/endblockwarn.rb 2006-02-13 16:52:40 UTC (rev 406)
+++ trunk/test/ruby/endblockwarn.rb 2006-02-13 17:07:02 UTC (rev 407)
@@ -0,0 +1,12 @@
+def end1
+ END {}
+end
+
+end1
+
+eval <<EOE
+ def end2
+ END {}
+ end
+EOE
+
Modified: trunk/test/ruby/test_beginendblock.rb
===================================================================
--- trunk/test/ruby/test_beginendblock.rb 2006-02-13 16:52:40 UTC (rev 406)
+++ trunk/test/ruby/test_beginendblock.rb 2006-02-13 17:07:02 UTC (rev 407)
@@ -1,5 +1,3 @@
-# We cannot test these cases.
-=begin
require 'test/unit'
require 'tempfile'
require 'envutil'
@@ -12,6 +10,7 @@
end
def test_beginendblock
+assert false, "TODO: BEGIN{} support is incomplete"
ruby = EnvUtil.rubybin
target = File.join(DIR, 'beginmainend.rb')
io = IO.popen("#{q(ruby)} #{q(target)}")
@@ -48,13 +47,16 @@
errout.close
erroutpath = errout.path
system("#{q(ruby)} #{q(launcherpath)} #{q(erroutpath)}")
+# expected = <<EOW
+#endblockwarn.rb:2: warning: END in method; use at_exit
+#(eval):2: warning: END in method; use at_exit
+#EOW
expected = <<EOW
-endblockwarn.rb:2: warning: END in method; use at_exit
-(eval):2: warning: END in method; use at_exit
+warning: END in method; use at_exit
+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
Added: trunk/test/ruby/test_file.rb
===================================================================
--- trunk/test/ruby/test_file.rb 2006-02-13 16:52:40 UTC (rev 406)
+++ trunk/test/ruby/test_file.rb 2006-02-13 17:07:02 UTC (rev 407)
@@ -0,0 +1,117 @@
+require 'test/unit'
+require 'tempfile'
+require 'ut_eof'
+
+class TestFile < Test::Unit::TestCase
+
+ # I don't know Ruby's spec about "unlink-before-close" exactly.
+ # This test asserts current behaviour.
+ def test_unlink_before_close
+ filename = File.basename(__FILE__) + ".#{$$}"
+ w = File.open(filename, "w")
+ w << "foo"
+ w.close
+ r = File.open(filename, "r")
+ begin
+ if /(mswin|bccwin|mingw|emx)/ =~ RUBY_PLATFORM
+ assert_raise(Errno::EACCES) {File.unlink(filename)}
+ else
+ assert_nothing_raised {File.unlink(filename)}
+ end
+ ensure
+ r.close
+ File.unlink(filename) if File.exist?(filename)
+ end
+ end
+
+ include TestEOF
+ def open_file(content)
+ f = Tempfile.new("test-eof")
+ f << content
+ f.rewind
+ yield f
+ end
+ alias open_file_rw open_file
+
+ include TestEOF::Seek
+
+ def test_truncate_wbuf # [ruby-dev:24191]
+ f = Tempfile.new("test-truncate")
+ f.print "abc"
+ f.truncate(0)
+ f.print "def"
+ f.close
+ assert_equal("\0\0\0def", File.read(f.path))
+ end
+
+ def test_truncate_rbuf # [ruby-dev:24197]
+ f = Tempfile.new("test-truncate")
+ f.puts "abc"
+ f.puts "def"
+ f.close
+ f.open
+ assert_equal("abc\n", f.gets)
+ f.truncate(3)
+ assert_equal(nil, f.gets)
+ end
+
+ def test_truncate_beyond_eof
+ f = Tempfile.new("test-truncate")
+ f.print "abc"
+ f.truncate 10
+ assert_equal("\0" * 7, f.read(100), "[ruby-dev:24532]")
+ end
+
+ def test_read_all_extended_file
+ f = Tempfile.new("test-extended-file")
+ assert_nil(f.getc)
+ open(f.path, "w") {|g| g.print "a" }
+ assert_equal("a", f.read)
+ end
+
+ def test_gets_extended_file
+ f = Tempfile.new("test-extended-file")
+ assert_nil(f.getc)
+ open(f.path, "w") {|g| g.print "a" }
+ assert_equal("a", f.gets("a"))
+ end
+
+ def test_gets_para_extended_file
+ f = Tempfile.new("test-extended-file")
+ assert_nil(f.getc)
+ open(f.path, "w") {|g| g.print "\na" }
+ assert_equal("a", f.gets(""))
+ end
+
+ def test_each_byte_extended_file
+ f = Tempfile.new("test-extended-file")
+ assert_nil(f.getc)
+ open(f.path, "w") {|g| g.print "a" }
+ result = []
+ f.each_byte {|b| result << b }
+ assert_equal([?a], result)
+ end
+
+ def test_getc_extended_file
+ f = Tempfile.new("test-extended-file")
+ assert_nil(f.getc)
+ open(f.path, "w") {|g| g.print "a" }
+ assert_equal(?a, f.getc)
+ end
+
+ def test_s_chown
+ assert_nothing_raised { File.chown -1, -1 }
+ assert_nothing_raised { File.chown nil, nil }
+ end
+
+ def test_chown
+ assert_nothing_raised {
+ File.open(__FILE__) {|f| f.chown -1, -1 }
+ }
+ # [ruby-dev:27140]
+ assert_nothing_raised {
+ File.open(__FILE__) {|f| f.chown nil, nil }
+ }
+ end
+
+end
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml