summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Sherwood <paul.sherwood@codethink.co.uk>2014-04-20 09:01:04 +0000
committerPaul Sherwood <paul.sherwood@codethink.co.uk>2014-04-20 09:01:04 +0000
commit6ecf40e1fa1b2c55f63d0ccb46bce2fca73b40ad (patch)
tree368a0326bcf36bc7e06cbbe7a1d55b752afd86ba /test
parentcb3ea602294b5038b5f7ac21d3875a2b52342956 (diff)
parent680d09b61ea7d850e27944311723a40c596e5d95 (diff)
downloadruby-6ecf40e1fa1b2c55f63d0ccb46bce2fca73b40ad.tar.gz
Merge commit '680d09' into baserock/ps/proto-web-systembaserock/ps/proto-web-system
Diffstat (limited to 'test')
-rw-r--r--test/bigdecimal/test_bigdecimal.rb34
-rw-r--r--test/coverage/test_coverage.rb2
-rw-r--r--test/date/test_date_parse.rb6
-rw-r--r--test/date/test_switch_hitter.rb55
-rw-r--r--test/dl/test_base.rb3
-rw-r--r--test/fiddle/helper.rb3
-rw-r--r--test/mkmf/test_framework.rb46
-rw-r--r--test/net/imap/Makefile15
-rw-r--r--test/net/imap/cacert.pem84
-rw-r--r--test/net/imap/server.crt65
-rw-r--r--test/net/imap/test_imap_response_parser.rb25
-rw-r--r--test/net/smtp/test_smtp.rb13
-rw-r--r--test/openssl/test_asn1.rb8
-rw-r--r--test/openssl/test_pkey_ec.rb32
-rw-r--r--test/openssl/test_ssl.rb56
-rw-r--r--test/optparse/test_acceptable.rb195
-rw-r--r--test/resolv/test_addr.rb13
-rw-r--r--test/resolv/test_dns.rb11
-rw-r--r--test/ripper/test_parser_events.rb22
-rw-r--r--test/ripper/test_scanner_events.rb48
-rw-r--r--test/ruby/envutil.rb25
-rw-r--r--test/ruby/memory_status.rb2
-rw-r--r--test/ruby/test_array.rb27
-rw-r--r--test/ruby/test_beginendblock.rb11
-rw-r--r--test/ruby/test_comparable.rb7
-rw-r--r--test/ruby/test_enumerator.rb31
-rw-r--r--test/ruby/test_float.rb12
-rw-r--r--test/ruby/test_gc.rb14
-rw-r--r--test/ruby/test_hash.rb37
-rw-r--r--test/ruby/test_io.rb97
-rw-r--r--test/ruby/test_io_m17n.rb12
-rw-r--r--test/ruby/test_m17n.rb2
-rw-r--r--test/ruby/test_method.rb14
-rw-r--r--test/ruby/test_module.rb44
-rw-r--r--test/ruby/test_pack.rb1
-rw-r--r--test/ruby/test_parse.rb21
-rw-r--r--test/ruby/test_proc.rb50
-rw-r--r--test/ruby/test_process.rb12
-rw-r--r--test/ruby/test_sprintf_comb.rb46
-rw-r--r--test/ruby/test_symbol.rb29
-rw-r--r--test/ruby/test_syntax.rb5
-rw-r--r--test/ruby/test_thread.rb27
-rw-r--r--test/ruby/test_time.rb23
-rw-r--r--test/rubygems/test_gem_requirement.rb20
-rw-r--r--test/rubygems/test_gem_version.rb12
-rw-r--r--test/socket/test_socket.rb71
-rw-r--r--test/socket/test_unix.rb23
-rw-r--r--test/test_mathn.rb98
-rw-r--r--test/test_tempfile.rb15
-rw-r--r--test/test_time.rb2
-rw-r--r--test/thread/test_queue.rb22
-rw-r--r--test/webrick/test_cgi.rb2
-rw-r--r--test/webrick/test_httputils.rb4
53 files changed, 1380 insertions, 174 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb
index 055b0ff4f0..02467937e5 100644
--- a/test/bigdecimal/test_bigdecimal.rb
+++ b/test/bigdecimal/test_bigdecimal.rb
@@ -1210,11 +1210,35 @@ class TestBigDecimal < Test::Unit::TestCase
end
def test_BigMath_exp
- n = 20
- assert_in_epsilon(Math.exp(n), BigMath.exp(BigDecimal("20"), n))
- assert_in_epsilon(Math.exp(40), BigMath.exp(BigDecimal("40"), n))
- assert_in_epsilon(Math.exp(-n), BigMath.exp(BigDecimal("-20"), n))
- assert_in_epsilon(Math.exp(-40), BigMath.exp(BigDecimal("-40"), n))
+ prec = 20
+ assert_in_epsilon(Math.exp(20), BigMath.exp(BigDecimal("20"), prec))
+ assert_in_epsilon(Math.exp(40), BigMath.exp(BigDecimal("40"), prec))
+ assert_in_epsilon(Math.exp(-20), BigMath.exp(BigDecimal("-20"), prec))
+ assert_in_epsilon(Math.exp(-40), BigMath.exp(BigDecimal("-40"), prec))
+ end
+
+ def test_BigMath_exp_with_float
+ prec = 20
+ assert_in_epsilon(Math.exp(20), BigMath.exp(20.0, prec))
+ assert_in_epsilon(Math.exp(40), BigMath.exp(40.0, prec))
+ assert_in_epsilon(Math.exp(-20), BigMath.exp(-20.0, prec))
+ assert_in_epsilon(Math.exp(-40), BigMath.exp(-40.0, prec))
+ end
+
+ def test_BigMath_exp_with_fixnum
+ prec = 20
+ assert_in_epsilon(Math.exp(20), BigMath.exp(20, prec))
+ assert_in_epsilon(Math.exp(40), BigMath.exp(40, prec))
+ assert_in_epsilon(Math.exp(-20), BigMath.exp(-20, prec))
+ assert_in_epsilon(Math.exp(-40), BigMath.exp(-40, prec))
+ end
+
+ def test_BigMath_exp_with_rational
+ prec = 20
+ assert_in_epsilon(Math.exp(20), BigMath.exp(Rational(40,2), prec))
+ assert_in_epsilon(Math.exp(40), BigMath.exp(Rational(80,2), prec))
+ assert_in_epsilon(Math.exp(-20), BigMath.exp(Rational(-40,2), prec))
+ assert_in_epsilon(Math.exp(-40), BigMath.exp(Rational(-80,2), prec))
end
def test_BigMath_exp_under_gc_stress
diff --git a/test/coverage/test_coverage.rb b/test/coverage/test_coverage.rb
index 4d785c3c0e..f4f192a578 100644
--- a/test/coverage/test_coverage.rb
+++ b/test/coverage/test_coverage.rb
@@ -47,7 +47,7 @@ class TestCoverage < Test::Unit::TestCase
Dir.mktmpdir {|tmp|
Dir.chdir(tmp) {
File.open("test.rb", "w") do |f|
- f.puts "p\n" * 10000
+ f.puts "__id__\n" * 10000
f.puts "def ignore(x); end"
f.puts "ignore([1"
f.puts "])"
diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb
index 1504473938..fc77ebc4ac 100644
--- a/test/date/test_date_parse.rb
+++ b/test/date/test_date_parse.rb
@@ -1028,10 +1028,16 @@ class TestDateParse < Test::Unit::TestCase
d = Date.rfc2822('Sat, 3 Feb 2001 04:05:06 +0700', Date::ITALY + 10)
assert_equal(Date.new(2001,2,3), d)
assert_equal(Date::ITALY + 10, d.start)
+ d = Date.rfc2822('3 Feb 2001 04:05:06 +0700', Date::ITALY + 10)
+ assert_equal(Date.new(2001,2,3), d)
+ assert_equal(Date::ITALY + 10, d.start)
d = DateTime.rfc2822('Sat, 3 Feb 2001 04:05:06 +0700', Date::ITALY + 10)
assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d)
assert_equal(Date::ITALY + 10, d.start)
+ d = DateTime.rfc2822('3 Feb 2001 04:05:06 +0700', Date::ITALY + 10)
+ assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d)
+ assert_equal(Date::ITALY + 10, d.start)
end
def test_httpdate
diff --git a/test/date/test_switch_hitter.rb b/test/date/test_switch_hitter.rb
index 8431d40a29..2a36792f56 100644
--- a/test/date/test_switch_hitter.rb
+++ b/test/date/test_switch_hitter.rb
@@ -294,6 +294,8 @@ class TestSH < Test::Unit::TestCase
assert_raise(Errno::ERANGE) do
Date.new(1 << 10000).strftime('%Y')
end
+ assert_equal('-3786825600', Date.new(1850).strftime('%s'))
+ assert_equal('-3786825600000', Date.new(1850).strftime('%Q'))
end
def test_cmp
@@ -472,6 +474,59 @@ class TestSH < Test::Unit::TestCase
period2_iter(+cm_period * (1 << 64) - 3, +cm_period * (1 << 64) + 3)
end
+ def test_different_alignments
+ assert_equal(0, Date.jd(0) <=> Date.civil(-4713, 11, 24, Date::GREGORIAN))
+ assert_equal(0, Date.jd(213447717) <=> Date.civil(579687, 11, 24))
+ assert_equal(0, Date.jd(-213447717) <=> Date.civil(-589113, 11, 24, Date::GREGORIAN))
+
+ assert_equal(0, Date.jd(0) <=> DateTime.civil(-4713, 11, 24, 0, 0, 0, 0, Date::GREGORIAN))
+ assert_equal(0, Date.jd(213447717) <=> DateTime.civil(579687, 11, 24))
+ assert_equal(0, Date.jd(-213447717) <=> DateTime.civil(-589113, 11, 24, 0, 0, 0, 0, Date::GREGORIAN))
+
+ assert(Date.jd(0) == Date.civil(-4713, 11, 24, Date::GREGORIAN))
+ assert(Date.jd(213447717) == Date.civil(579687, 11, 24))
+ assert(Date.jd(-213447717) == Date.civil(-589113, 11, 24, Date::GREGORIAN))
+
+ assert(Date.jd(0) == DateTime.civil(-4713, 11, 24, 0, 0, 0, 0, Date::GREGORIAN))
+ assert(Date.jd(213447717) == DateTime.civil(579687, 11, 24))
+ assert(Date.jd(-213447717) == DateTime.civil(-589113, 11, 24, 0, 0, 0, 0, Date::GREGORIAN))
+
+ assert(Date.jd(0) === Date.civil(-4713, 11, 24, Date::GREGORIAN))
+ assert(Date.jd(213447717) === Date.civil(579687, 11, 24))
+ assert(Date.jd(-213447717) === Date.civil(-589113, 11, 24, Date::GREGORIAN))
+
+ assert(Date.jd(0) === DateTime.civil(-4713, 11, 24, 12, 0, 0, 0, Date::GREGORIAN))
+ assert(Date.jd(213447717) === DateTime.civil(579687, 11, 24, 12))
+ assert(Date.jd(-213447717) === DateTime.civil(-589113, 11, 24, 12, 0, 0, 0, Date::GREGORIAN))
+
+ a = Date.jd(0)
+ b = Date.civil(-4713, 11, 24, Date::GREGORIAN)
+ assert_equal(0, a <=> b)
+
+ a = Date.civil(-4712, 1, 1, Date::JULIAN)
+ b = Date.civil(-4713, 11, 24, Date::GREGORIAN)
+ a.jd; b.jd
+ assert_equal(0, a <=> b)
+
+ a = Date.jd(0)
+ b = Date.civil(-4713, 11, 24, Date::GREGORIAN)
+ assert(a == b)
+
+ a = Date.civil(-4712, 1, 1, Date::JULIAN)
+ b = Date.civil(-4713, 11, 24, Date::GREGORIAN)
+ a.jd; b.jd
+ assert(a == b)
+
+ a = Date.jd(0)
+ b = Date.civil(-4713, 11, 24, Date::GREGORIAN)
+ assert(a === b)
+
+ a = Date.civil(-4712, 1, 1, Date::JULIAN)
+ b = Date.civil(-4713, 11, 24, Date::GREGORIAN)
+ a.jd; b.jd
+ assert(a === b)
+ end
+
def test_marshal
s = "\x04\bU:\tDate[\bU:\rRational[\ai\x03\xCF\xD3Ji\ai\x00o:\x13Date::Infinity\x06:\a@di\xFA"
d = Marshal.load(s)
diff --git a/test/dl/test_base.rb b/test/dl/test_base.rb
index 0642f0ed89..63dee050d9 100644
--- a/test/dl/test_base.rb
+++ b/test/dl/test_base.rb
@@ -32,6 +32,9 @@ when /darwin/
when /kfreebsd/
libc_so = "/lib/libc.so.0.1"
libm_so = "/lib/libm.so.1"
+when /gnu/ #GNU/Hurd
+ libc_so = "/lib/libc.so.0.3"
+ libm_so = "/lib/libm.so.6"
when /bsd|dragonfly/
libc_so = "/usr/lib/libc.so"
libm_so = "/usr/lib/libm.so"
diff --git a/test/fiddle/helper.rb b/test/fiddle/helper.rb
index ad69f55e69..9a46709693 100644
--- a/test/fiddle/helper.rb
+++ b/test/fiddle/helper.rb
@@ -38,6 +38,9 @@ when /kfreebsd/
when /bsd|dragonfly/
libc_so = "/usr/lib/libc.so"
libm_so = "/usr/lib/libm.so"
+when /gnu/ #GNU/Hurd
+ libc_so = "/lib/libc.so.0.3"
+ libm_so = "/lib/libm.so.6"
when /solaris/
libdir = '/lib'
case [0].pack('L!').size
diff --git a/test/mkmf/test_framework.rb b/test/mkmf/test_framework.rb
new file mode 100644
index 0000000000..48e8bf7213
--- /dev/null
+++ b/test/mkmf/test_framework.rb
@@ -0,0 +1,46 @@
+require_relative 'base'
+
+class TestMkmf
+ class TestHaveFramework < TestMkmf
+ def create_framework(fw, hdrname = "#{fw}.h")
+ Dir.mktmpdir("frameworks") do |dir|
+ fwdir = "#{dir}/#{fw}.framework"
+ hdrdir = "#{fwdir}/Headers"
+ FileUtils.mkdir_p(hdrdir)
+ File.write("#{hdrdir}/#{hdrname}", "")
+ src = "#{fwdir}/main.c"
+ File.write(src, "void #{fw}(void) {}")
+ cmd = LINK_SO.dup
+ RbConfig.expand(cmd, RbConfig::CONFIG.merge("OBJS"=>src))
+ cmd.gsub!("$@", "#{fwdir}/#{fw}")
+ cmd.gsub!(/ -bundle /, ' -dynamiclib ')
+ assert(xsystem(cmd), MKMFLOG)
+ $INCFLAGS << " " << "-F#{dir}".quote
+ yield fw, hdrname
+ end
+ end
+
+ def test_core_foundation_framework
+ assert(have_framework("CoreFoundation"), mkmflog("try as Objective-C"))
+ end
+
+ def test_multi_frameworks
+ assert(have_framework("CoreFoundation"), mkmflog("try as Objective-C"))
+ assert(have_framework("Cocoa"), mkmflog("try as Objective-C"))
+ end
+
+ def test_empty_framework
+ create_framework("MkmfTest") do |fw|
+ assert(have_framework(fw), MKMFLOG)
+ end
+ end
+
+ def test_different_name_header
+ bug8593 = '[ruby-core:55745] [Bug #8593]'
+ create_framework("MkmfTest", "test_mkmf.h") do |fw, hdrname|
+ assert(!have_framework(fw), MKMFLOG)
+ assert(have_framework([fw, hdrname]), MKMFLOG)
+ end
+ end
+ end
+end if /darwin/ =~ RUBY_PLATFORM
diff --git a/test/net/imap/Makefile b/test/net/imap/Makefile
new file mode 100644
index 0000000000..b2bc9c7368
--- /dev/null
+++ b/test/net/imap/Makefile
@@ -0,0 +1,15 @@
+all:
+
+regen_certs:
+ touch server.key
+ make server.crt
+
+cacert.pem: server.key
+ openssl req -new -x509 -days 1825 -key server.key -out cacert.pem -text -subj "/C=JP/ST=Shimane/L=Matz-e city/O=Ruby Core Team/CN=Ruby Test CA/emailAddress=security@ruby-lang.org"
+
+server.csr:
+ openssl req -new -key server.key -out server.csr -text -subj "/C=JP/ST=Shimane/O=Ruby Core Team/OU=Ruby Test/CN=localhost"
+
+server.crt: server.csr cacert.pem
+ openssl x509 -days 1825 -CA cacert.pem -CAkey server.key -set_serial 00 -in server.csr -req -text -out server.crt
+ rm server.csr
diff --git a/test/net/imap/cacert.pem b/test/net/imap/cacert.pem
index bd7e68ac95..7073387877 100644
--- a/test/net/imap/cacert.pem
+++ b/test/net/imap/cacert.pem
@@ -2,59 +2,65 @@ Certificate:
Data:
Version: 3 (0x2)
Serial Number:
- 9f:dc:f7:94:98:05:43:4c
+ b9:90:a2:bf:62:69:17:9c
Signature Algorithm: sha1WithRSAEncryption
Issuer: C=JP, ST=Shimane, L=Matz-e city, O=Ruby Core Team, CN=Ruby Test CA/emailAddress=security@ruby-lang.org
Validity
- Not Before: Dec 23 10:21:33 2010 GMT
- Not After : Jan 1 10:21:33 2014 GMT
+ Not Before: Jan 3 01:34:17 2014 GMT
+ Not After : Jan 2 01:34:17 2019 GMT
Subject: C=JP, ST=Shimane, L=Matz-e city, O=Ruby Core Team, CN=Ruby Test CA/emailAddress=security@ruby-lang.org
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
- Public-Key: (1024 bit)
- Modulus:
- 00:ce:be:2c:9f:47:ba:db:9c:9c:5b:f0:38:3b:f3:
- 74:20:37:76:23:9f:84:1c:81:90:b4:3e:00:20:34:
- 98:7e:81:69:50:a1:c3:65:96:ea:fa:00:da:8c:cc:
- 53:3f:ba:3c:d0:50:7a:5a:b4:6b:ac:d3:2e:18:ca:
- 2a:69:b3:6a:6f:38:c2:32:a8:06:b6:0a:30:a9:ee:
- 03:38:e9:05:a5:19:23:54:a8:3c:b9:08:ad:2b:72:
- 23:df:93:22:c4:46:a8:ea:f1:a6:e9:30:4a:3f:83:
- 39:e9:62:8e:8b:a3:5e:67:89:1d:7c:75:de:05:aa:
- 58:b1:b7:79:7c:10:80:6d:87
+ RSA Public Key: (1024 bit)
+ Modulus (1024 bit):
+ 00:db:75:d0:45:de:b1:df:bf:71:a0:0e:b0:a5:e6:
+ bc:f4:1c:9d:e5:25:67:64:c5:7b:cb:f1:af:c6:be:
+ 9a:aa:ea:7e:0f:cc:05:af:ef:40:69:06:b2:c9:13:
+ 9d:7e:eb:a2:06:e2:ea:7d:07:c7:c7:99:c7:fb:d5:
+ b8:eb:63:77:62:2b:18:12:c3:53:58:d0:f5:c7:40:
+ 0c:01:d1:26:82:34:16:09:e3:dc:65:f4:dc:bb:5d:
+ a5:41:60:e7:a9:74:ba:d7:4c:b6:a3:9c:c5:8c:89:
+ af:cb:e8:9f:05:fe:ea:fe:64:24:bf:e7:ed:e3:f6:
+ d0:fc:d6:eb:fc:06:82:10:fb
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Key Identifier:
- 41:C9:49:37:B1:FA:61:E3:BA:D7:19:3D:D9:DA:8C:B9:82:C9:B4:6A
+ E8:7E:58:AC:13:7B:03:22:8D:9E:AF:32:0B:84:89:80:80:0C:1E:C2
X509v3 Authority Key Identifier:
- keyid:41:C9:49:37:B1:FA:61:E3:BA:D7:19:3D:D9:DA:8C:B9:82:C9:B4:6A
+ keyid:E8:7E:58:AC:13:7B:03:22:8D:9E:AF:32:0B:84:89:80:80:0C:1E:C2
+ DirName:/C=JP/ST=Shimane/L=Matz-e city/O=Ruby Core Team/CN=Ruby Test CA/emailAddress=security@ruby-lang.org
+ serial:B9:90:A2:BF:62:69:17:9C
X509v3 Basic Constraints:
CA:TRUE
Signature Algorithm: sha1WithRSAEncryption
- 86:00:33:b9:dd:ff:5f:83:59:5f:c3:29:3c:d7:11:db:10:b3:
- d7:d1:70:fb:0a:c6:74:85:c6:ea:e1:15:c4:92:f8:0e:11:cc:
- ff:a6:3c:31:c2:2c:66:d8:fe:63:93:9f:b0:97:e6:f5:bc:5c:
- 80:68:96:5d:eb:77:b9:23:dd:68:a7:49:03:ff:22:48:55:f1:
- 39:7c:20:21:ff:64:52:e1:f6:cf:3c:b3:4d:2c:5c:03:62:ea:
- c5:49:99:07:fa:8d:ff:7b:c2:75:0c:ca:24:b5:0b:f5:b7:57:
- 3a:10:f0:8a:bb:9a:e8:92:4d:d5:6f:c2:a2:29:36:61:78:a4:
- dc:7b
+ 8f:77:06:4e:31:72:12:ee:68:09:70:27:d4:31:85:ef:10:95:
+ f9:0f:2b:66:63:08:37:88:6e:b7:9b:40:3e:18:77:33:86:e8:
+ 61:6a:b7:3c:cb:c7:a6:d6:d5:92:6a:1f:56:d0:9f:5c:32:56:
+ d3:37:52:fe:0e:20:c2:7a:0d:fe:2d:3c:81:da:b8:7f:4d:6a:
+ 08:01:d9:be:7a:a2:15:be:a6:ce:49:64:90:8c:9a:ca:6e:2e:
+ 84:48:1d:94:19:56:94:46:aa:25:9b:68:c2:80:60:bf:cb:2e:
+ 35:03:ea:0a:65:5a:33:38:c6:cc:81:46:c0:bc:36:86:96:39:
+ 10:7d
-----BEGIN CERTIFICATE-----
-MIIC6DCCAlGgAwIBAgIJAJ/c95SYBUNMMA0GCSqGSIb3DQEBBQUAMIGMMQswCQYD
-VQQGEwJKUDEQMA4GA1UECAwHU2hpbWFuZTEUMBIGA1UEBwwLTWF0ei1lIGNpdHkx
-FzAVBgNVBAoMDlJ1YnkgQ29yZSBUZWFtMRUwEwYDVQQDDAxSdWJ5IFRlc3QgQ0Ex
-JTAjBgkqhkiG9w0BCQEWFnNlY3VyaXR5QHJ1YnktbGFuZy5vcmcwHhcNMTAxMjIz
-MTAyMTMzWhcNMTQwMTAxMTAyMTMzWjCBjDELMAkGA1UEBhMCSlAxEDAOBgNVBAgM
-B1NoaW1hbmUxFDASBgNVBAcMC01hdHotZSBjaXR5MRcwFQYDVQQKDA5SdWJ5IENv
-cmUgVGVhbTEVMBMGA1UEAwwMUnVieSBUZXN0IENBMSUwIwYJKoZIhvcNAQkBFhZz
+MIIDjTCCAvagAwIBAgIJALmQor9iaRecMA0GCSqGSIb3DQEBBQUAMIGMMQswCQYD
+VQQGEwJKUDEQMA4GA1UECBMHU2hpbWFuZTEUMBIGA1UEBxMLTWF0ei1lIGNpdHkx
+FzAVBgNVBAoTDlJ1YnkgQ29yZSBUZWFtMRUwEwYDVQQDEwxSdWJ5IFRlc3QgQ0Ex
+JTAjBgkqhkiG9w0BCQEWFnNlY3VyaXR5QHJ1YnktbGFuZy5vcmcwHhcNMTQwMTAz
+MDEzNDE3WhcNMTkwMTAyMDEzNDE3WjCBjDELMAkGA1UEBhMCSlAxEDAOBgNVBAgT
+B1NoaW1hbmUxFDASBgNVBAcTC01hdHotZSBjaXR5MRcwFQYDVQQKEw5SdWJ5IENv
+cmUgVGVhbTEVMBMGA1UEAxMMUnVieSBUZXN0IENBMSUwIwYJKoZIhvcNAQkBFhZz
ZWN1cml0eUBydWJ5LWxhbmcub3JnMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
-gQDOviyfR7rbnJxb8Dg783QgN3Yjn4QcgZC0PgAgNJh+gWlQocNllur6ANqMzFM/
-ujzQUHpatGus0y4Yyipps2pvOMIyqAa2CjCp7gM46QWlGSNUqDy5CK0rciPfkyLE
-Rqjq8abpMEo/gznpYo6Lo15niR18dd4Fqlixt3l8EIBthwIDAQABo1AwTjAdBgNV
-HQ4EFgQUQclJN7H6YeO61xk92dqMuYLJtGowHwYDVR0jBBgwFoAUQclJN7H6YeO6
-1xk92dqMuYLJtGowDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQCGADO5
-3f9fg1lfwyk81xHbELPX0XD7CsZ0hcbq4RXEkvgOEcz/pjwxwixm2P5jk5+wl+b1
-vFyAaJZd63e5I91op0kD/yJIVfE5fCAh/2RS4fbPPLNNLFwDYurFSZkH+o3/e8J1
-DMoktQv1t1c6EPCKu5rokk3Vb8KiKTZheKTcew==
+gQDbddBF3rHfv3GgDrCl5rz0HJ3lJWdkxXvL8a/Gvpqq6n4PzAWv70BpBrLJE51+
+66IG4up9B8fHmcf71bjrY3diKxgSw1NY0PXHQAwB0SaCNBYJ49xl9Ny7XaVBYOep
+dLrXTLajnMWMia/L6J8F/ur+ZCS/5+3j9tD81uv8BoIQ+wIDAQABo4H0MIHxMB0G
+A1UdDgQWBBToflisE3sDIo2erzILhImAgAwewjCBwQYDVR0jBIG5MIG2gBToflis
+E3sDIo2erzILhImAgAwewqGBkqSBjzCBjDELMAkGA1UEBhMCSlAxEDAOBgNVBAgT
+B1NoaW1hbmUxFDASBgNVBAcTC01hdHotZSBjaXR5MRcwFQYDVQQKEw5SdWJ5IENv
+cmUgVGVhbTEVMBMGA1UEAxMMUnVieSBUZXN0IENBMSUwIwYJKoZIhvcNAQkBFhZz
+ZWN1cml0eUBydWJ5LWxhbmcub3JnggkAuZCiv2JpF5wwDAYDVR0TBAUwAwEB/zAN
+BgkqhkiG9w0BAQUFAAOBgQCPdwZOMXIS7mgJcCfUMYXvEJX5DytmYwg3iG63m0A+
+GHczhuhharc8y8em1tWSah9W0J9cMlbTN1L+DiDCeg3+LTyB2rh/TWoIAdm+eqIV
+vqbOSWSQjJrKbi6ESB2UGVaURqolm2jCgGC/yy41A+oKZVozOMbMgUbAvDaGljkQ
+fQ==
-----END CERTIFICATE-----
diff --git a/test/net/imap/server.crt b/test/net/imap/server.crt
index d848b26ab0..fa4f99493a 100644
--- a/test/net/imap/server.crt
+++ b/test/net/imap/server.crt
@@ -1,17 +1,17 @@
Certificate:
Data:
- Version: 3 (0x2)
+ Version: 1 (0x0)
Serial Number: 0 (0x0)
Signature Algorithm: sha1WithRSAEncryption
Issuer: C=JP, ST=Shimane, L=Matz-e city, O=Ruby Core Team, CN=Ruby Test CA/emailAddress=security@ruby-lang.org
Validity
- Not Before: Dec 23 10:23:52 2010 GMT
- Not After : Jan 1 10:23:52 2014 GMT
+ Not Before: Jan 3 01:34:17 2014 GMT
+ Not After : Jan 2 01:34:17 2019 GMT
Subject: C=JP, ST=Shimane, O=Ruby Core Team, OU=Ruby Test, CN=localhost
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
- Public-Key: (1024 bit)
- Modulus:
+ RSA Public Key: (1024 bit)
+ Modulus (1024 bit):
00:db:75:d0:45:de:b1:df:bf:71:a0:0e:b0:a5:e6:
bc:f4:1c:9d:e5:25:67:64:c5:7b:cb:f1:af:c6:be:
9a:aa:ea:7e:0f:cc:05:af:ef:40:69:06:b2:c9:13:
@@ -22,40 +22,27 @@ Certificate:
af:cb:e8:9f:05:fe:ea:fe:64:24:bf:e7:ed:e3:f6:
d0:fc:d6:eb:fc:06:82:10:fb
Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Basic Constraints:
- CA:FALSE
- Netscape Comment:
- OpenSSL Generated Certificate
- X509v3 Subject Key Identifier:
- E8:7E:58:AC:13:7B:03:22:8D:9E:AF:32:0B:84:89:80:80:0C:1E:C2
- X509v3 Authority Key Identifier:
- keyid:41:C9:49:37:B1:FA:61:E3:BA:D7:19:3D:D9:DA:8C:B9:82:C9:B4:6A
-
Signature Algorithm: sha1WithRSAEncryption
- ae:ee:cd:fe:c9:af:48:0b:50:37:ac:6a:f6:68:90:9b:67:df:
- 6f:2d:17:c9:3c:a5:da:ad:39:dc:2a:5b:07:88:26:38:19:30:
- d6:95:cf:10:69:c7:92:14:83:be:f1:b5:8e:6f:d9:91:51:c5:
- 63:ae:1c:89:ac:27:bf:4f:2a:8f:4e:0c:57:42:0a:c9:8e:0c:
- f4:f3:02:f7:ea:44:b6:e4:47:05:af:4e:74:e4:87:87:d9:c8:
- 76:ed:ab:32:7c:f0:31:34:10:14:bc:a6:37:cd:d7:dc:33:da:
- 82:d3:d4:9b:e9:d5:cd:38:cc:fa:81:5f:4e:fd:5f:53:05:5d:
- 76:f9
+ 85:f5:d3:05:8b:8c:f4:43:1c:88:f2:8f:b2:f2:93:77:b7:3d:
+ 95:c6:a0:34:bc:33:6a:d8:85:5f:3e:86:08:10:c5:5c:c1:76:
+ a3:53:3c:dc:38:98:23:97:e7:da:21:ac:e8:4d:3c:96:70:29:
+ ff:ff:1e:4a:9a:17:2b:db:04:62:b9:ef:ab:ea:a7:a5:e8:7c:
+ b1:d5:ed:30:a8:6c:78:de:51:7e:e3:8a:c2:a4:64:a8:63:a2:
+ bc:fd:43:9c:f3:55:7d:54:c9:6a:d8:53:1c:4b:6b:03:aa:b6:
+ 19:e6:a4:4f:47:00:96:c5:42:59:85:4e:c3:4e:cd:41:82:53:
+ 10:f8
-----BEGIN CERTIFICATE-----
-MIIC3jCCAkegAwIBAgIBADANBgkqhkiG9w0BAQUFADCBjDELMAkGA1UEBhMCSlAx
-EDAOBgNVBAgMB1NoaW1hbmUxFDASBgNVBAcMC01hdHotZSBjaXR5MRcwFQYDVQQK
-DA5SdWJ5IENvcmUgVGVhbTEVMBMGA1UEAwwMUnVieSBUZXN0IENBMSUwIwYJKoZI
-hvcNAQkBFhZzZWN1cml0eUBydWJ5LWxhbmcub3JnMB4XDTEwMTIyMzEwMjM1MloX
-DTE0MDEwMTEwMjM1MlowYDELMAkGA1UEBhMCSlAxEDAOBgNVBAgMB1NoaW1hbmUx
-FzAVBgNVBAoMDlJ1YnkgQ29yZSBUZWFtMRIwEAYDVQQLDAlSdWJ5IFRlc3QxEjAQ
-BgNVBAMMCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA23XQ
-Rd6x379xoA6wpea89Byd5SVnZMV7y/Gvxr6aqup+D8wFr+9AaQayyROdfuuiBuLq
-fQfHx5nH+9W462N3YisYEsNTWND1x0AMAdEmgjQWCePcZfTcu12lQWDnqXS610y2
-o5zFjImvy+ifBf7q/mQkv+ft4/bQ/Nbr/AaCEPsCAwEAAaN7MHkwCQYDVR0TBAIw
-ADAsBglghkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUw
-HQYDVR0OBBYEFOh+WKwTewMijZ6vMguEiYCADB7CMB8GA1UdIwQYMBaAFEHJSTex
-+mHjutcZPdnajLmCybRqMA0GCSqGSIb3DQEBBQUAA4GBAK7uzf7Jr0gLUDesavZo
-kJtn328tF8k8pdqtOdwqWweIJjgZMNaVzxBpx5IUg77xtY5v2ZFRxWOuHImsJ79P
-Ko9ODFdCCsmODPTzAvfqRLbkRwWvTnTkh4fZyHbtqzJ88DE0EBS8pjfN19wz2oLT
-1Jvp1c04zPqBX079X1MFXXb5
+MIICXDCCAcUCAQAwDQYJKoZIhvcNAQEFBQAwgYwxCzAJBgNVBAYTAkpQMRAwDgYD
+VQQIEwdTaGltYW5lMRQwEgYDVQQHEwtNYXR6LWUgY2l0eTEXMBUGA1UEChMOUnVi
+eSBDb3JlIFRlYW0xFTATBgNVBAMTDFJ1YnkgVGVzdCBDQTElMCMGCSqGSIb3DQEJ
+ARYWc2VjdXJpdHlAcnVieS1sYW5nLm9yZzAeFw0xNDAxMDMwMTM0MTdaFw0xOTAx
+MDIwMTM0MTdaMGAxCzAJBgNVBAYTAkpQMRAwDgYDVQQIEwdTaGltYW5lMRcwFQYD
+VQQKEw5SdWJ5IENvcmUgVGVhbTESMBAGA1UECxMJUnVieSBUZXN0MRIwEAYDVQQD
+Ewlsb2NhbGhvc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANt10EXesd+/
+caAOsKXmvPQcneUlZ2TFe8vxr8a+mqrqfg/MBa/vQGkGsskTnX7rogbi6n0Hx8eZ
+x/vVuOtjd2IrGBLDU1jQ9cdADAHRJoI0Fgnj3GX03LtdpUFg56l0utdMtqOcxYyJ
+r8vonwX+6v5kJL/n7eP20PzW6/wGghD7AgMBAAEwDQYJKoZIhvcNAQEFBQADgYEA
+hfXTBYuM9EMciPKPsvKTd7c9lcagNLwzatiFXz6GCBDFXMF2o1M83DiYI5fn2iGs
+6E08lnAp//8eSpoXK9sEYrnvq+qnpeh8sdXtMKhseN5RfuOKwqRkqGOivP1DnPNV
+fVTJathTHEtrA6q2GeakT0cAlsVCWYVOw07NQYJTEPg=
-----END CERTIFICATE-----
diff --git a/test/net/imap/test_imap_response_parser.rb b/test/net/imap/test_imap_response_parser.rb
index 6a5a117408..1547a05b2e 100644
--- a/test/net/imap/test_imap_response_parser.rb
+++ b/test/net/imap/test_imap_response_parser.rb
@@ -116,4 +116,29 @@ EOF
* 1 FETCH (UID 92285 )
EOF
end
+
+ # [Bug #8281]
+ def test_acl
+ parser = Net::IMAP::ResponseParser.new
+ response = parser.parse(<<EOF.gsub(/\n/, "\r\n").taint)
+* ACL "INBOX/share" "imshare2copy1366146467@xxxxxxxxxxxxxxxxxx.com" lrswickxteda
+EOF
+ assert_equal("ACL", response.name)
+ assert_equal(1, response.data.length)
+ assert_equal("INBOX/share", response.data[0].mailbox)
+ assert_equal("imshare2copy1366146467@xxxxxxxxxxxxxxxxxx.com",
+ response.data[0].user)
+ assert_equal("lrswickxteda", response.data[0].rights)
+ end
+
+ # [Bug #8415]
+ def test_capability
+ parser = Net::IMAP::ResponseParser.new
+ response = parser.parse("* CAPABILITY st11p00mm-iscream009 1Q49 XAPPLEPUSHSERVICE IMAP4 IMAP4rev1 SASL-IR AUTH=ATOKEN AUTH=PLAIN\r\n")
+ assert_equal("CAPABILITY", response.name)
+ assert_equal("AUTH=PLAIN", response.data.last)
+ response = parser.parse("* CAPABILITY st11p00mm-iscream009 1Q49 XAPPLEPUSHSERVICE IMAP4 IMAP4rev1 SASL-IR AUTH=ATOKEN AUTH=PLAIN \r\n")
+ assert_equal("CAPABILITY", response.name)
+ assert_equal("AUTH=PLAIN", response.data.last)
+ end
end
diff --git a/test/net/smtp/test_smtp.rb b/test/net/smtp/test_smtp.rb
index 8af6a37d53..ba2943db56 100644
--- a/test/net/smtp/test_smtp.rb
+++ b/test/net/smtp/test_smtp.rb
@@ -3,6 +3,19 @@ require 'minitest/autorun'
module Net
class TestSMTP < MiniTest::Unit::TestCase
+ def test_critical
+ smtp = Net::SMTP.new 'localhost', 25
+
+ assert_raises RuntimeError do
+ smtp.send :critical do
+ raise 'fail on purpose'
+ end
+ end
+
+ assert_kind_of Net::SMTP::Response, smtp.send(:critical),
+ '[Bug #9125]'
+ end
+
def test_esmtp
smtp = Net::SMTP.new 'localhost', 25
assert smtp.esmtp
diff --git a/test/openssl/test_asn1.rb b/test/openssl/test_asn1.rb
index 811fe387fa..3e6d3c9a42 100644
--- a/test/openssl/test_asn1.rb
+++ b/test/openssl/test_asn1.rb
@@ -263,6 +263,14 @@ rEzBQ0F9dUyqQ9gyRg8KHhDfv9HzT1d/rnUZMkoombwYBRIUChGCYV0GnJcan2Zm
end
end
+ def test_decode_utctime
+ expected = Time.at 1374535380
+ assert_equal expected, OpenSSL::ASN1.decode("\x17\v1307222323Z").value
+
+ expected += 17
+ assert_equal expected, OpenSSL::ASN1.decode("\x17\r130722232317Z").value
+ end
+
def test_create_inf_length_primitive
expected = %w{ 24 80 04 01 61 00 00 }
raw = [expected.join('')].pack('H*')
diff --git a/test/openssl/test_pkey_ec.rb b/test/openssl/test_pkey_ec.rb
index e63f617140..0856c2785e 100644
--- a/test/openssl/test_pkey_ec.rb
+++ b/test/openssl/test_pkey_ec.rb
@@ -7,28 +7,29 @@ class OpenSSL::TestEC < Test::Unit::TestCase
@data1 = 'foo'
@data2 = 'bar' * 1000 # data too long for DSA sig
- @group1 = OpenSSL::PKey::EC::Group.new('secp112r1')
- @group2 = OpenSSL::PKey::EC::Group.new('sect163k1')
- @group3 = OpenSSL::PKey::EC::Group.new('prime256v1')
+ @groups = []
+ @keys = []
- @key1 = OpenSSL::PKey::EC.new
- @key1.group = @group1
- @key1.generate_key
+ OpenSSL::PKey::EC.builtin_curves.each do |curve, comment|
+ next if curve.start_with?("Oakley") # Oakley curves are not suitable for ECDSA
+ group = OpenSSL::PKey::EC::Group.new(curve)
- @key2 = OpenSSL::PKey::EC.new(@group2.curve_name)
- @key2.generate_key
+ key = OpenSSL::PKey::EC.new(group)
+ key.generate_key
- @key3 = OpenSSL::PKey::EC.new(@group3)
- @key3.generate_key
-
- @groups = [@group1, @group2, @group3]
- @keys = [@key1, @key2, @key3]
+ @groups << group
+ @keys << key
+ end
end
def compare_keys(k1, k2)
assert_equal(k1.to_pem, k2.to_pem)
end
+ def test_builtin_curves
+ assert(!OpenSSL::PKey::EC.builtin_curves.empty?)
+ end
+
def test_curve_names
@groups.each_with_index do |group, idx|
key = @keys[idx]
@@ -44,11 +45,12 @@ class OpenSSL::TestEC < Test::Unit::TestCase
end
end
- def test_encoding
+ def test_group_encoding
for group in @groups
for meth in [:to_der, :to_pem]
txt = group.send(meth)
gr = OpenSSL::PKey::EC::Group.new(txt)
+
assert_equal(txt, gr.send(meth))
assert_equal(group.generator.to_bn, gr.generator.to_bn)
@@ -58,7 +60,9 @@ class OpenSSL::TestEC < Test::Unit::TestCase
assert_equal(group.degree, gr.degree)
end
end
+ end
+ def test_key_encoding
for key in @keys
group = key.group
diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb
index 5d40a5576b..2b92cf9701 100644
--- a/test/openssl/test_ssl.rb
+++ b/test/openssl/test_ssl.rb
@@ -351,6 +351,35 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
}
end
+ def test_verify_certificate_identity
+ [true, false].each do |criticality|
+ cert = create_null_byte_SAN_certificate(criticality)
+ assert_equal(false, OpenSSL::SSL.verify_certificate_identity(cert, 'www.example.com'))
+ assert_equal(true, OpenSSL::SSL.verify_certificate_identity(cert, "www.example.com\0.evil.com"))
+ assert_equal(false, OpenSSL::SSL.verify_certificate_identity(cert, '192.168.7.255'))
+ assert_equal(true, OpenSSL::SSL.verify_certificate_identity(cert, '192.168.7.1'))
+ assert_equal(false, OpenSSL::SSL.verify_certificate_identity(cert, '13::17'))
+ assert_equal(true, OpenSSL::SSL.verify_certificate_identity(cert, '13:0:0:0:0:0:0:17'))
+ end
+ end
+
+ # Create NULL byte SAN certificate
+ def create_null_byte_SAN_certificate(critical = false)
+ ef = OpenSSL::X509::ExtensionFactory.new
+ cert = OpenSSL::X509::Certificate.new
+ cert.subject = OpenSSL::X509::Name.parse "/DC=some/DC=site/CN=Some Site"
+ ext = ef.create_ext('subjectAltName', 'DNS:placeholder,IP:192.168.7.1,IP:13::17', critical)
+ ext_asn1 = OpenSSL::ASN1.decode(ext.to_der)
+ san_list_der = ext_asn1.value.reduce(nil) { |memo,val| val.tag == 4 ? val.value : memo }
+ san_list_asn1 = OpenSSL::ASN1.decode(san_list_der)
+ san_list_asn1.value[0].value = "www.example.com\0.evil.com"
+ pos = critical ? 2 : 1
+ ext_asn1.value[pos].value = san_list_asn1.to_der
+ real_ext = OpenSSL::X509::Extension.new ext_asn1
+ cert.add_extension(real_ext)
+ cert
+ end
+
def test_tlsext_hostname
return unless OpenSSL::SSL::SSLSocket.instance_methods.include?(:hostname)
@@ -438,6 +467,33 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
}
end
+ def test_invalid_shutdown_by_gc
+ assert_nothing_raised {
+ start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true){|server, port|
+ 10.times {
+ sock = TCPSocket.new("127.0.0.1", port)
+ ssl = OpenSSL::SSL::SSLSocket.new(sock)
+ GC.start
+ ssl.connect
+ sock.close
+ }
+ }
+ }
+ end
+
+ def test_close_after_socket_close
+ start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true){|server, port|
+ sock = TCPSocket.new("127.0.0.1", port)
+ ssl = OpenSSL::SSL::SSLSocket.new(sock)
+ ssl.sync_close = true
+ ssl.connect
+ sock.close
+ assert_nothing_raised do
+ ssl.close
+ end
+ }
+ end
+
end
end
diff --git a/test/optparse/test_acceptable.rb b/test/optparse/test_acceptable.rb
new file mode 100644
index 0000000000..6ec619ef8c
--- /dev/null
+++ b/test/optparse/test_acceptable.rb
@@ -0,0 +1,195 @@
+require_relative 'test_optparse'
+
+class TestOptionParser::Acceptable < TestOptionParser
+
+ def setup
+ super
+ @opt.def_option("--integer VAL", Integer) { |v| @integer = v }
+ @opt.def_option("--float VAL", Float) { |v| @float = v }
+ @opt.def_option("--numeric VAL", Numeric) { |v| @numeric = v }
+
+ @opt.def_option("--decimal-integer VAL",
+ OptionParser::DecimalInteger) { |i| @decimal_integer = i }
+ @opt.def_option("--octal-integer VAL",
+ OptionParser::OctalInteger) { |i| @octal_integer = i }
+ @opt.def_option("--decimal-numeric VAL",
+ OptionParser::DecimalNumeric) { |i| @decimal_numeric = i }
+ end
+
+ def test_integer
+ assert_equal(%w"", no_error {@opt.parse!(%w"--integer 0")})
+ assert_equal(0, @integer)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--integer 0b10")})
+ assert_equal(2, @integer)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--integer 077")})
+ assert_equal(63, @integer)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--integer 10")})
+ assert_equal(10, @integer)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--integer 0x3")})
+ assert_equal(3, @integer)
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--integer 0b")
+ end
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--integer 09")
+ end
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--integer 0x")
+ end
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--integer 1234xyz")
+ end
+ end
+
+ def test_float
+ assert_equal(%w"", no_error {@opt.parse!(%w"--float 0")})
+ assert_in_epsilon(0.0, @float)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--float 0.0")})
+ assert_in_epsilon(0.0, @float)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--float 1.2")})
+ assert_in_epsilon(1.2, @float)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--float 1E2")})
+ assert_in_epsilon(100, @float)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--float 1E-2")})
+ assert_in_epsilon(0.01, @float)
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--float 0e")
+ end
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--float 1.234xyz")
+ end
+ end
+
+ def test_numeric
+ assert_equal(%w"", no_error {@opt.parse!(%w"--numeric 0")})
+ assert_equal(0, @numeric)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--numeric 0/1")})
+ assert_equal(0, @numeric)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--numeric 1/2")})
+ assert_equal(Rational(1, 2), @numeric)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--numeric 1.2/2.3")})
+ assert_equal(Rational(12, 23), @numeric)
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--numeric 1/")
+ end
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--numeric 12/34xyz")
+ end
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--numeric 12x/34yz")
+ end
+ end
+
+ def test_decimal_integer
+ assert_equal(%w"", no_error {@opt.parse!(%w"--decimal-integer 0")})
+ assert_equal(0, @decimal_integer)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--decimal-integer 10")})
+ assert_equal(10, @decimal_integer)
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--decimal-integer 0b1")
+ end
+
+ e = assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--decimal-integer 09")
+ end
+
+ assert_equal("invalid argument: --decimal-integer 09", e.message)
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--decimal-integer x")
+ end
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--decimal-integer 1234xyz")
+ end
+ end
+
+ def test_octal_integer
+ assert_equal(%w"", no_error {@opt.parse!(%w"--octal-integer 0")})
+ assert_equal(0, @octal_integer)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--octal-integer 6")})
+ assert_equal(6, @octal_integer)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--octal-integer 07")})
+ assert_equal(7, @octal_integer)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--octal-integer 10")})
+ assert_equal(8, @octal_integer)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--octal-integer 011")})
+ assert_equal(9, @octal_integer)
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--octal-integer 09")
+ end
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--octal-integer 0b1")
+ end
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--octal-integer x")
+ end
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--octal-integer 01234xyz")
+ end
+ end
+
+ def test_decimal_numeric
+ assert_equal(%w"", no_error {@opt.parse!(%w"--decimal-numeric 0")})
+ assert_equal(0, @decimal_numeric)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--decimal-numeric 01")})
+ assert_equal(1, @decimal_numeric)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--decimal-numeric 1.2")})
+ assert_in_delta(1.2, @decimal_numeric)
+
+ assert_equal(%w"", no_error {@opt.parse!(%w"--decimal-numeric 1E2")})
+ assert_in_delta(100.0, @decimal_numeric)
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--decimal-numeric 0b1")
+ end
+
+ e = assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--decimal-numeric 09")
+ end
+
+ assert_equal("invalid argument: --decimal-numeric 09", e.message)
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--decimal-integer 1234xyz")
+ end
+
+ assert_raises(OptionParser::InvalidArgument) do
+ @opt.parse!(%w"--decimal-integer 12.34xyz")
+ end
+ end
+
+end
+
diff --git a/test/resolv/test_addr.rb b/test/resolv/test_addr.rb
index 84bc8c2d3b..b4718430cc 100644
--- a/test/resolv/test_addr.rb
+++ b/test/resolv/test_addr.rb
@@ -1,6 +1,7 @@
require 'test/unit'
require 'resolv'
require 'socket'
+require 'tempfile'
class TestResolvAddr < Test::Unit::TestCase
def test_invalid_ipv4_address
@@ -13,4 +14,16 @@ class TestResolvAddr < Test::Unit::TestCase
end
}
end
+
+ def test_invalid_byte_comment
+ bug9273 = '[ruby-core:59239] [Bug #9273]'
+ Tempfile.open('resolv_test_addr_') do |tmpfile|
+ tmpfile.print("\xff\x00\x40")
+ tmpfile.close
+ hosts = Resolv::Hosts.new(tmpfile.path)
+ assert_nothing_raised(ArgumentError, bug9273) do
+ hosts.each_address("") {break}
+ end
+ end
+ end
end
diff --git a/test/resolv/test_dns.rb b/test/resolv/test_dns.rb
index 9a9c33ea84..0b2a8aacd6 100644
--- a/test/resolv/test_dns.rb
+++ b/test/resolv/test_dns.rb
@@ -1,6 +1,7 @@
require 'test/unit'
require 'resolv'
require 'socket'
+require 'tempfile'
class TestResolvDNS < Test::Unit::TestCase
def setup
@@ -118,4 +119,14 @@ class TestResolvDNS < Test::Unit::TestCase
}
end
+ def test_invalid_byte_comment
+ bug9273 = '[ruby-core:59239] [Bug #9273]'
+ Tempfile.open('resolv_test_dns_') do |tmpfile|
+ tmpfile.print("\xff\x00\x40")
+ tmpfile.close
+ assert_nothing_raised(ArgumentError, bug9273) do
+ Resolv::DNS::Config.parse_resolv_conf(tmpfile.path)
+ end
+ end
+ end
end
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index af41d3e6a4..1e3e6a3625 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -24,6 +24,10 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
dp.parse.to_s
end
+ def compile_error(str)
+ parse(str, :compile_error) {|e, msg| return msg}
+ end
+
def test_program
thru_program = false
assert_equal '[void()]', parse('', :on_program) {thru_program = true}
@@ -1135,8 +1139,20 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
end
def test_unterminated_regexp
- compile_error = false
- parse('/', :compile_error) {|e, msg| compile_error = msg}
- assert_equal("unterminated regexp meets end of file", compile_error)
+ assert_equal("unterminated regexp meets end of file", compile_error('/'))
+ end
+
+ def test_invalid_instance_variable_name
+ assert_equal("`@1' is not allowed as an instance variable name", compile_error('@1'))
+ assert_equal("`@%' is not allowed as an instance variable name", compile_error('@%'))
+ end
+
+ def test_invalid_class_variable_name
+ assert_equal("`@@1' is not allowed as a class variable name", compile_error('@@1'))
+ assert_equal("`@@%' is not allowed as a class variable name", compile_error('@@%'))
+ end
+
+ def test_invalid_global_variable_name
+ assert_equal("`$%' is not allowed as a global variable name", compile_error('$%'))
end
end if ripper_test
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index c92ec494ed..0f61ac7880 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -90,28 +90,28 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
end
def test_location
- validate_location ""
- validate_location " "
- validate_location "@"
- validate_location "\n"
- validate_location "\r\n"
- validate_location "\n\n\n\n\n\r\n\n\n"
- validate_location "\n;\n;\n;\n;\n"
- validate_location "nil"
- validate_location "@ivar"
- validate_location "1;2;3"
- validate_location "1\n2\n3"
- validate_location "1\n2\n3\n"
- validate_location "def m(a) nil end"
- validate_location "if true then false else nil end"
- validate_location "BEGIN{print nil}"
- validate_location "%w(a b\nc\r\nd \ne )"
- validate_location %Q["a\nb\r\nc"]
- validate_location "print(<<EOS)\nheredoc\nEOS\n"
- validate_location "print(<<-\"EOS\")\nheredoc\n EOS\n"
- end
-
- def validate_location(src)
+ assert_location ""
+ assert_location " "
+ assert_location ":"
+ assert_location "\n"
+ assert_location "\r\n"
+ assert_location "\n\n\n\n\n\r\n\n\n"
+ assert_location "\n;\n;\n;\n;\n"
+ assert_location "nil"
+ assert_location "@ivar"
+ assert_location "1;2;3"
+ assert_location "1\n2\n3"
+ assert_location "1\n2\n3\n"
+ assert_location "def m(a) nil end"
+ assert_location "if true then false else nil end"
+ assert_location "BEGIN{print nil}"
+ assert_location "%w(a b\nc\r\nd \ne )"
+ assert_location %Q["a\nb\r\nc"]
+ assert_location "print(<<""EOS)\nheredoc\nEOS\n"
+ assert_location "print(<<-\"EOS\")\nheredoc\n EOS\n"
+ end
+
+ def assert_location(src)
buf = ''
Ripper.lex(src).each do |pos, type, tok|
line, col = *pos
@@ -823,8 +823,8 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
def test_CHAR
assert_equal [],
scan('CHAR', "")
- assert_equal ["@"],
- scan('CHAR', "@")
+ assert_equal ["?a"],
+ scan('CHAR', "?a")
assert_equal [],
scan('CHAR', "@ivar")
end
diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb
index 73f0101ac1..6998842259 100644
--- a/test/ruby/envutil.rb
+++ b/test/ruby/envutil.rb
@@ -184,6 +184,31 @@ module Test
assert(msg === stderr, "warning message #{stderr.inspect} is expected to match #{msg.inspect}")
end
+ def assert_no_memory_leak(args, prepare, code, message=nil, opt = {})
+ limit = opt.delete(:limit) || 1.5
+ token = "\e[7;1m#{$$.to_s}:#{Time.now.strftime('%s.%L')}:#{rand(0x10000).to_s(16)}:\e[m"
+ token_dump = token.dump
+ token_re = Regexp.quote(token)
+ envs = args.shift if Array === args and Hash === args.first
+ args = [
+ "--disable=gems",
+ "-r", File.expand_path("../memory_status", __FILE__),
+ *args,
+ "-v", "-",
+ ]
+ args.unshift(envs) if envs
+ cmd = [
+ 'END {STDERR.puts '"#{token_dump}"'"FINAL=#{Memory::Status.new.size}"}',
+ prepare,
+ 'STDERR.puts('"#{token_dump}"'"START=#{$initial_size = Memory::Status.new.size}")',
+ code,
+ ].join("\n")
+ _, err, status = EnvUtil.invoke_ruby(args, cmd, true, true, opt)
+ before = err.sub!(/^#{token_re}START=(\d+)\n/, '') && $1.to_i
+ after = err.sub!(/^#{token_re}FINAL=(\d+)\n/, '') && $1.to_i
+ assert_equal([true, ""], [status.success?, err], message)
+ assert_operator(after.fdiv(before), :<, limit, message)
+ end
def assert_is_minus_zero(f)
assert(1.0/f == -Float::INFINITY, "#{f} is not -0.0")
diff --git a/test/ruby/memory_status.rb b/test/ruby/memory_status.rb
index f504c0a736..cd4a62c1c0 100644
--- a/test/ruby/memory_status.rb
+++ b/test/ruby/memory_status.rb
@@ -7,7 +7,7 @@ module Memory
PROC_FILE = procfile
VM_PAT = /^Vm(\w+):\s+(\d+)/
def self.read_status
- IO.foreach(PROC_FILE) do |l|
+ IO.foreach(PROC_FILE, encoding: Encoding::ASCII_8BIT) do |l|
yield($1.downcase.intern, $2.to_i * 1024) if VM_PAT =~ l
end
end
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 28d3e4156b..4350e0578f 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -552,6 +552,29 @@ class TestArray < Test::Unit::TestCase
assert_equal(3, a.count {|x| x % 2 == 1 })
assert_equal(2, a.count(1) {|x| x % 2 == 1 })
assert_raise(ArgumentError) { a.count(0, 1) }
+
+ bug8654 = '[ruby-core:56072]'
+ assert_in_out_err [], <<-EOS, ["0"], [], bug8654
+ a1 = []
+ a2 = Array.new(100) { |i| i }
+ a2.count do |i|
+ p i
+ a2.replace(a1) if i == 0
+ end
+ EOS
+
+ assert_in_out_err [], <<-EOS, ["[]", "0"], [], bug8654
+ ARY = Array.new(100) { |i| i }
+ class Fixnum
+ alias old_equal ==
+ def == other
+ ARY.replace([]) if self.equal?(0)
+ p ARY
+ self.equal?(other)
+ end
+ end
+ p ARY.count(42)
+ EOS
end
def test_delete
@@ -1624,8 +1647,8 @@ class TestArray < Test::Unit::TestCase
[2,2,2,2],[2,2,2,3],[2,2,3,3],[2,3,3,3],[3,3,3,3]],
a.repeated_combination(4).to_a.sort)
assert_equal(@cls[], a.repeated_combination(-1).to_a)
- assert_equal("abcde".each_char.to_a.repeated_combination(5).map{|a|a.sort}.sort,
- "edcba".each_char.to_a.repeated_combination(5).map{|a|a.sort}.sort)
+ assert_equal("abcde".each_char.to_a.repeated_combination(5).map{|e|e.sort}.sort,
+ "edcba".each_char.to_a.repeated_combination(5).map{|e|e.sort}.sort)
assert_equal(@cls[].repeated_combination(0).to_a, @cls[[]])
assert_equal(@cls[].repeated_combination(1).to_a, @cls[])
diff --git a/test/ruby/test_beginendblock.rb b/test/ruby/test_beginendblock.rb
index b590835a2d..121d116c35 100644
--- a/test/ruby/test_beginendblock.rb
+++ b/test/ruby/test_beginendblock.rb
@@ -158,4 +158,15 @@ EOW
assert_equal(["", "", 42], [out, err, status.exitstatus], "#{bug5218}: #{ex}")
end
end
+
+ def test_callcc_at_exit
+ bug9110 = '[ruby-core:58329][Bug #9110]'
+ script = <<EOS
+require "continuation"
+c = nil
+at_exit { c.call }
+at_exit { callcc {|_c| c = _c } }
+EOS
+ assert_normal_exit(script, bug9110)
+ end
end
diff --git a/test/ruby/test_comparable.rb b/test/ruby/test_comparable.rb
index 00ce6b485a..3526c73add 100644
--- a/test/ruby/test_comparable.rb
+++ b/test/ruby/test_comparable.rb
@@ -69,4 +69,11 @@ class TestComparable < Test::Unit::TestCase
assert_raise(ArgumentError) { 1.0 < nil }
assert_raise(ArgumentError) { 1.0 < Object.new }
end
+
+ def test_no_cmp
+ bug9003 = '[ruby-core:57736] [Bug #9003]'
+ assert_nothing_raised(SystemStackError, bug9003) {
+ @o <=> @o.dup
+ }
+ end
end
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb
index 10ba2f184e..feaa2de698 100644
--- a/test/ruby/test_enumerator.rb
+++ b/test/ruby/test_enumerator.rb
@@ -1,4 +1,5 @@
require 'test/unit'
+require_relative "envutil"
class TestEnumerator < Test::Unit::TestCase
def setup
@@ -97,6 +98,36 @@ class TestEnumerator < Test::Unit::TestCase
assert_equal([[1,5],[2,6],[3,7]], @obj.to_enum(:foo, 1, 2, 3).with_index(5).to_a)
end
+ def test_with_index_large_offset
+ bug8010 = '[ruby-dev:47131] [Bug #8010]'
+ s = 1 << (8*1.size-2)
+ assert_equal([[1,s],[2,s+1],[3,s+2]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010)
+ s <<= 1
+ assert_equal([[1,s],[2,s+1],[3,s+2]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010)
+ end
+
+ def test_with_index_nonnum_offset
+ bug8010 = '[ruby-dev:47131] [Bug #8010]'
+ s = Object.new
+ def s.to_int; 1 end
+ assert_equal([[1,1],[2,2],[3,3]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010)
+ end
+
+ def test_with_index_string_offset
+ bug8010 = '[ruby-dev:47131] [Bug #8010]'
+ assert_raise(TypeError, bug8010){ @obj.to_enum(:foo, 1, 2, 3).with_index('1').to_a }
+ end
+
+ def test_with_index_dangling_memo
+ bug9178 = '[ruby-core:58692] [Bug #9178]'
+ assert_in_out_err([], <<-"end;", ["Enumerator", "[false, [1]]"], [], bug9178)
+ bug = "#{bug9178}"
+ e = [1].to_enum(:chunk).with_index {|c,i| i == 5}
+ puts e.class
+ p e.to_a[0]
+ end;
+ end
+
def test_with_object
obj = [0, 1]
ret = (1..10).each.with_object(obj) {|i, memo|
diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb
index d2cee75433..301aeecf0f 100644
--- a/test/ruby/test_float.rb
+++ b/test/ruby/test_float.rb
@@ -519,4 +519,16 @@ class TestFloat < Test::Unit::TestCase
sleep(0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1)
end
end
+
+ def test_long_string
+ assert_normal_exit(<<-'end;')
+ assert_in_epsilon(10.0, ("1."+"1"*300000).to_f*9)
+ end;
+ end
+
+ def test_long_string
+ assert_normal_exit(<<-'end;')
+ assert_in_epsilon(10.0, ("1."+"1"*300000).to_f*9)
+ end;
+ end
end
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index f04e7e0255..381fcd4d18 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -112,4 +112,18 @@ class TestGc < Test::Unit::TestCase
ObjectSpace.define_finalizer(Thread.main) { p 'finalize' }
EOS
end
+
+ def test_sweep_in_finalizer
+ bug9205 = '[ruby-core:58833] [Bug #9205]'
+ 2.times do
+ assert_ruby_status([], <<-'end;', bug9205)
+ raise_proc = proc do |id|
+ GC.start
+ end
+ 1000.times do
+ ObjectSpace.define_finalizer(Object.new, raise_proc)
+ end
+ end;
+ end
+ end
end
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index 82272cb301..019196bd2e 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -1,5 +1,6 @@
require 'test/unit'
require 'continuation'
+require_relative "envutil"
class TestHash < Test::Unit::TestCase
@@ -116,6 +117,12 @@ class TestHash < Test::Unit::TestCase
end
+ def test_self_initialize_copy
+ h = @cls[1=>2]
+ h.instance_eval {initialize_copy(h)}
+ assert_equal(2, h[1])
+ end
+
def test_AREF # '[]'
t = Time.now
h = @cls[
@@ -144,8 +151,6 @@ class TestHash < Test::Unit::TestCase
assert_equal('nil', h1[nil])
assert_equal(nil, h1['nil'])
assert_equal(:default, h1['koala'])
-
-
end
def test_ASET # '[]='
@@ -920,4 +925,32 @@ class TestHash < Test::Unit::TestCase
assert_not_equal(h.hash, h.invert.hash, feature4262)
end
end
+
+ def test_exception_in_rehash
+ bug9187 = '[ruby-core:58728] [Bug #9187]'
+
+ prepare = <<-EOS
+ class Foo
+ def initialize
+ @raise = false
+ end
+
+ def hash
+ raise if @raise
+ @raise = true
+ return 0
+ end
+ end
+ EOS
+
+ code = <<-EOS
+ h = {Foo.new => true}
+ 10_0000.times do
+ h.rehash rescue nil
+ end
+ GC.start
+ EOS
+
+ assert_no_memory_leak([], prepare, code, bug9187)
+ end
end
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index ad9b80faec..5e3a12c999 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -1094,6 +1094,19 @@ class TestIO < Test::Unit::TestCase
end
end
+ def test_close_read_write_separately
+ bug = '[ruby-list:49598]'
+ (1..10).each do |i|
+ assert_nothing_raised(IOError, "#{bug} trying ##{i}") do
+ IO.popen(EnvUtil.rubybin, "r+") {|f|
+ th = Thread.new {f.close_write}
+ f.close_read
+ th.join
+ }
+ end
+ end
+ end
+
def test_pid
r, w = IO.pipe
assert_equal(nil, r.pid)
@@ -1110,6 +1123,17 @@ class TestIO < Test::Unit::TestCase
assert_raise(IOError) { pipe.pid }
end
+ def tesst_pid_after_close_read
+ pid1 = pid2 = nil
+ IO.popen(["echo", ""], "r+") do |io|
+ pid1 = io.pid
+ io.close_read
+ pid2 = io.pid
+ end
+ assert_not_nil(pid1)
+ assert_equal(pid1, pid2)
+ end
+
def make_tempfile
t = Tempfile.new("test_io")
t.binmode
@@ -2147,4 +2171,77 @@ End
IO.select(tempfiles)
}, bug8080
end
+
+ def test_read_32bit_boundary
+ bug8431 = '[ruby-core:55098] [Bug #8431]'
+ make_tempfile {|t|
+ assert_separately(["-", bug8431, t.path], <<-"end;")
+ msg = ARGV.shift
+ f = open(ARGV[0], "rb")
+ f.seek(0xffff_ffff)
+ assert_nil(f.read(1), msg)
+ end;
+ }
+ end if /mswin|mingw/ =~ RUBY_PLATFORM
+
+ def test_write_32bit_boundary
+ bug8431 = '[ruby-core:55098] [Bug #8431]'
+ make_tempfile {|t|
+ assert_separately(["-", bug8431, t.path], <<-"end;", timeout: 30)
+ msg = ARGV.shift
+ f = open(ARGV[0], "wb")
+ f.seek(0xffff_ffff)
+ begin
+ # this will consume very long time or fail by ENOSPC on a
+ # filesystem which sparse file is not supported
+ f.write('1')
+ rescue SystemCallError
+ else
+ assert_equal(0x1_0000_0000, f.tell, msg)
+ end
+ end;
+ }
+ end if /mswin|mingw/ =~ RUBY_PLATFORM
+
+ def test_read_unlocktmp_ensure
+ bug8669 = '[ruby-core:56121] [Bug #8669]'
+
+ str = ""
+ r, = IO.pipe
+ t = Thread.new { r.read(nil, str) }
+ sleep 0.1 until t.stop?
+ t.raise
+ sleep 0.1 while t.alive?
+ assert_nothing_raised(RuntimeError, bug8669) { str.clear }
+ ensure
+ t.kill
+ end
+
+ def test_readpartial_unlocktmp_ensure
+ bug8669 = '[ruby-core:56121] [Bug #8669]'
+
+ str = ""
+ r, = IO.pipe
+ t = Thread.new { r.readpartial(4096, str) }
+ sleep 0.1 until t.stop?
+ t.raise
+ sleep 0.1 while t.alive?
+ assert_nothing_raised(RuntimeError, bug8669) { str.clear }
+ ensure
+ t.kill
+ end
+
+ def test_sysread_unlocktmp_ensure
+ bug8669 = '[ruby-core:56121] [Bug #8669]'
+
+ str = ""
+ r, = IO.pipe
+ t = Thread.new { r.sysread(4096, str) }
+ sleep 0.1 until t.stop?
+ t.raise
+ sleep 0.1 while t.alive?
+ assert_nothing_raised(RuntimeError, bug8669) { str.clear }
+ ensure
+ t.kill
+ end
end
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 98c9e2b41c..c22f665286 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -2067,7 +2067,17 @@ EOT
open("a", "wb") {|f| f.puts "a"}
open("a", "rt") {|f| f.getc}
}
- assert(c.ascii_only?, "should be ascii_only #{bug4557}")
+ assert(c.ascii_only?, bug4557)
+ end
+
+ def test_getc_conversion
+ bug8516 = '[ruby-core:55444] [Bug #8516]'
+ c = with_tmpdir {
+ open("a", "wb") {|f| f.putc "\xe1"}
+ open("a", "r:iso-8859-1:utf-8") {|f| f.getc}
+ }
+ refute(c.ascii_only?, bug8516)
+ assert_equal(1, c.size, bug8516)
end
def test_default_mode_on_dosish
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index 699c8151dd..e92b85dbb8 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -1180,7 +1180,7 @@ class TestM17N < Test::Unit::TestCase
def test_symbol_op
ops = %w"
- .. ... + - +(binary) -(binary) * / % ** +@ -@ | ^ & ! <=> > >= < <= ==
+ .. ... + - * / % ** +@ -@ | ^ & ! <=> > >= < <= ==
=== != =~ !~ ~ ! [] []= << >> :: `
"
ops.each do |op|
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index ea6c5f2164..889c50efbe 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -472,4 +472,18 @@ class TestMethod < Test::Unit::TestCase
1000.times {p = Bug6171.new('test'); 10000.times {p.reverse}}
EOC
end
+
+ def test_gced_bmethod
+ assert_normal_exit %q{
+ require 'irb'
+ IRB::Irb.module_eval do
+ define_method(:eval_input) do
+ IRB::Irb.module_eval { alias_method :eval_input, :to_s }
+ GC.start
+ Kernel
+ end
+ end
+ IRB.start
+ }, '[Bug #7825]'
+ end
end
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 6176f484bc..1fe67df2be 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -277,6 +277,17 @@ class TestModule < Test::Unit::TestCase
assert_equal([:MIXIN, :USER], User.constants.sort)
end
+ def test_self_initialize_copy
+ bug9535 = '[ruby-dev:47989] [Bug #9535]'
+ m = Module.new do
+ def foo
+ :ok
+ end
+ initialize_copy(self)
+ end
+ assert_equal(:ok, Object.new.extend(m).foo, bug9535)
+ end
+
def test_included_modules
assert_equal([], Mixin.included_modules)
assert_equal([Mixin], User.included_modules)
@@ -669,6 +680,19 @@ class TestModule < Test::Unit::TestCase
m.instance_eval { remove_const(:Foo) }
end
+ class Bug9413
+ class << self
+ Foo = :foo
+ end
+ end
+
+ def test_singleton_constants
+ bug9413 = '[ruby-core:59763] [Bug #9413]'
+ c = Bug9413.singleton_class
+ assert_include(c.constants(true), :Foo, bug9413)
+ assert_include(c.constants(false), :Foo, bug9413)
+ end
+
def test_frozen_class
m = Module.new
m.freeze
@@ -1220,4 +1244,24 @@ class TestModule < Test::Unit::TestCase
INPUT
assert_in_out_err([], src, ["NameError"], [])
end
+
+ def test_include_module_with_constants_invalidates_method_cache
+ assert_in_out_err([], <<-RUBY, %w(123 456), [])
+ A = 123
+
+ class Foo
+ def self.a
+ A
+ end
+ end
+
+ module M
+ A = 456
+ end
+
+ puts Foo.a
+ Foo.send(:include, M)
+ puts Foo.a
+ RUBY
+ end
end
diff --git a/test/ruby/test_pack.rb b/test/ruby/test_pack.rb
index c862215cb4..52beb9f8d4 100644
--- a/test/ruby/test_pack.rb
+++ b/test/ruby/test_pack.rb
@@ -180,6 +180,7 @@ class TestPack < Test::Unit::TestCase
assert_equal a[0], a.pack("p").unpack("p")[0]
assert_equal a, a.pack("p").freeze.unpack("p*")
assert_raise(ArgumentError) { (a.pack("p") + "").unpack("p*") }
+ assert_raise(ArgumentError) { (a.pack("p") << "d").unpack("p*") }
end
def test_format_string_modified
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 14990be12c..6de57c1a22 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -358,6 +358,17 @@ class TestParse < Test::Unit::TestCase
assert_equal("foo 1 bar", "foo #$1 bar")
end
+ def test_dstr_disallowd_variable
+ bug8375 = '[ruby-core:54885] [Bug #8375]'
+ %w[@ @1 @@. @@ @@1 @@. $ $%].each do |src|
+ src = '#'+src+' '
+ str = assert_nothing_raised(SyntaxError, "#{bug8375} #{src.dump}") do
+ break eval('"'+src+'"')
+ end
+ assert_equal(src, str, bug8375)
+ end
+ end
+
def test_dsym
assert_nothing_raised { eval(':""') }
end
@@ -524,13 +535,14 @@ class TestParse < Test::Unit::TestCase
)
end
- assert_raise(SyntaxError) do
- eval %q(
+ assert_nothing_raised(SyntaxError) do
+ x = eval %q(
<<FOO
#$
FOO
)
end
+ assert_equal "\#$\n", x
assert_raise(SyntaxError) do
eval %Q(
@@ -550,14 +562,15 @@ FOO
)
end
- assert_raise(SyntaxError) do
- eval %q(
+ assert_nothing_raised(SyntaxError) do
+ x = eval %q(
<<FOO
#$
foo
FOO
)
end
+ assert_equal "\#$\nfoo\n", x
assert_nothing_raised do
eval "x = <<""FOO\r\n1\r\nFOO"
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index 3cac94a100..7560ce94ef 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -1,4 +1,5 @@
require 'test/unit'
+require_relative 'envutil'
class TestProc < Test::Unit::TestCase
def setup
@@ -140,6 +141,14 @@ class TestProc < Test::Unit::TestCase
method(:m2).to_proc
end
+ def m1(var)
+ var
+ end
+
+ def m_block_given?
+ m1(block_given?)
+ end
+
# [yarv-dev:777] block made by Method#to_proc
def test_method_to_proc
b = block()
@@ -147,6 +156,37 @@ class TestProc < Test::Unit::TestCase
assert_instance_of(Binding, b.binding, '[ruby-core:25589]')
end
+ def test_block_given_method
+ m = method(:m_block_given?)
+ assert(!m.call, "without block")
+ assert(m.call {}, "with block")
+ assert(!m.call, "without block second")
+ end
+
+ def test_block_given_method_to_proc
+ bug8341 = '[Bug #8341]'
+ m = method(:m_block_given?).to_proc
+ assert(!m.call, "#{bug8341} without block")
+ assert(m.call {}, "#{bug8341} with block")
+ assert(!m.call, "#{bug8341} without block second")
+ end
+
+ def test_block_persist_between_calls
+ bug8341 = '[Bug #8341]'
+ o = Object.new
+ def o.m1(top=true)
+ if top
+ [block_given?, @m.call(false)]
+ else
+ block_given?
+ end
+ end
+ m = o.method(:m1).to_proc
+ o.instance_variable_set(:@m, m)
+ assert_equal([true, false], m.call {}, "#{bug8341} nested with block")
+ assert_equal([false, false], m.call, "#{bug8341} nested without block")
+ end
+
def test_curry
b = proc {|x, y, z| (x||0) + (y||0) + (z||0) }
assert_equal(6, b.curry[1][2][3])
@@ -818,4 +858,14 @@ class TestProc < Test::Unit::TestCase
assert_equal('zot', o.method(:foo).to_proc.() {'zot'}, bug3792)
}
end
+
+ def test_overriden_lambda
+ bug8345 = '[ruby-core:54687] [Bug #8345]'
+ assert_normal_exit('def lambda; end; method(:puts).to_proc', bug8345)
+ end
+
+ def test_overriden_proc
+ bug8345 = '[ruby-core:54688] [Bug #8345]'
+ assert_normal_exit('def proc; end; ->{}.curry', bug8345)
+ end
end
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index d1e2e1984d..83ff379ca9 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -1319,6 +1319,18 @@ class TestProcess < Test::Unit::TestCase
assert_equal(2, data.size, bug4920)
assert_not_include(data.map(&:to_i), pid)
end
+ else # darwin
+ def test_daemon_no_threads
+ data = Timeout.timeout(3) do
+ IO.popen("-") do |f|
+ break f.readlines.map(&:chomp) if f
+ th = Thread.start {sleep 3}
+ Process.daemon(true, true)
+ puts Thread.list.size, th.status.inspect
+ end
+ end
+ assert_equal(["1", "false"], data)
+ end
end
end
diff --git a/test/ruby/test_sprintf_comb.rb b/test/ruby/test_sprintf_comb.rb
index 261732bcbc..c58ddf4f15 100644
--- a/test/ruby/test_sprintf_comb.rb
+++ b/test/ruby/test_sprintf_comb.rb
@@ -107,7 +107,9 @@ class TestSprintfComb < Test::Unit::TestCase
]
VS.reverse!
- def combination(*args, &b)
+ FLAGS = [['', ' '], ['', '#'], ['', '+'], ['', '-'], ['', '0']]
+
+ def self.combination(*args, &b)
#AllPairs.exhaustive_each(*args, &b)
AllPairs.each(*args, &b)
end
@@ -268,17 +270,8 @@ class TestSprintfComb < Test::Unit::TestCase
str
end
- def test_format_integer
- combination(
- %w[B b d o X x],
- [nil, 0, 5, 20],
- ["", ".", ".0", ".8", ".20"],
- ['', ' '],
- ['', '#'],
- ['', '+'],
- ['', '-'],
- ['', '0']) {|type, width, precision, sp, hs, pl, mi, zr|
- format = "%#{sp}#{hs}#{pl}#{mi}#{zr}#{width}#{precision}#{type}"
+ def self.assertions_format_integer(format)
+ proc {
VS.each {|v|
r = sprintf format, v
e = emu_int format, v
@@ -293,6 +286,14 @@ class TestSprintfComb < Test::Unit::TestCase
}
end
+ combination(%w[B b d o X x],
+ [nil, 0, 5, 20],
+ ["", ".", ".0", ".8", ".20"],
+ *FLAGS) {|type, width, precision, sp, hs, pl, mi, zr|
+ format = "%#{sp}#{hs}#{pl}#{mi}#{zr}#{width}#{precision}#{type}"
+ define_method("test_format_integer(#{format})", assertions_format_integer(format))
+ }
+
FLOAT_VALUES = [
-1e100,
-123456789.0,
@@ -526,17 +527,8 @@ class TestSprintfComb < Test::Unit::TestCase
end
- def test_format_float
- combination(
- %w[e E f g G],
- [nil, 0, 5, 20],
- ["", ".", ".0", ".8", ".20", ".200"],
- ['', ' '],
- ['', '#'],
- ['', '+'],
- ['', '-'],
- ['', '0']) {|type, width, precision, sp, hs, pl, mi, zr|
- format = "%#{sp}#{hs}#{pl}#{mi}#{zr}#{width}#{precision}#{type}"
+ def self.assertions_format_float(format)
+ proc {
FLOAT_VALUES.each {|v|
r = sprintf format, v
e = emu_float format, v
@@ -550,4 +542,12 @@ class TestSprintfComb < Test::Unit::TestCase
}
}
end
+
+ combination(%w[e E f g G],
+ [nil, 0, 5, 20],
+ ["", ".", ".0", ".8", ".20", ".200", ".9999"],
+ *FLAGS) {|type, width, precision, sp, hs, pl, mi, zr|
+ format = "%#{sp}#{hs}#{pl}#{mi}#{zr}#{width}#{precision}#{type}"
+ define_method("test_format_float(#{format})", assertions_format_float(format))
+ }
end
diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb
index c98f954092..23c50e6778 100644
--- a/test/ruby/test_symbol.rb
+++ b/test/ruby/test_symbol.rb
@@ -33,7 +33,7 @@ class TestSymbol < Test::Unit::TestCase
assert_inspect_evaled(':foo')
assert_inspect_evaled(':foo!')
assert_inspect_evaled(':bar?')
- assert_inspect_evaled(':<<')
+ assert_inspect_evaled(":<<")
assert_inspect_evaled(':>>')
assert_inspect_evaled(':<=')
assert_inspect_evaled(':>=')
@@ -102,6 +102,33 @@ class TestSymbol < Test::Unit::TestCase
assert_raise(ArgumentError) { :foo.to_proc.call }
end
+ def m_block_given?
+ block_given?
+ end
+
+ def m2_block_given?(m = nil)
+ if m
+ [block_given?, m.call(self)]
+ else
+ block_given?
+ end
+ end
+
+ def test_block_given_to_proc
+ bug8531 = '[Bug #8531]'
+ m = :m_block_given?.to_proc
+ assert(!m.call(self), "#{bug8531} without block")
+ assert(m.call(self) {}, "#{bug8531} with block")
+ assert(!m.call(self), "#{bug8531} without block second")
+ end
+
+ def test_block_persist_between_calls
+ bug8531 = '[Bug #8531]'
+ m2 = :m2_block_given?.to_proc
+ assert_equal([true, false], m2.call(self, m2) {}, "#{bug8531} nested with block")
+ assert_equal([false, false], m2.call(self, m2), "#{bug8531} nested without block")
+ end
+
def test_succ
assert_equal(:fop, :foo.succ)
end
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index d924679c7f..a65b567153 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -55,6 +55,11 @@ class TestSyntax < Test::Unit::TestCase
f.close!
end
+ def test_do_block_in_call_args
+ bug9308 = '[ruby-core:59342] [Bug #9308]'
+ assert_valid_syntax("bar def foo; self.each do end end", bug9308)
+ end
+
def test_reserved_method_no_args
bug6403 = '[ruby-dev:45626]'
assert_valid_syntax("def self; :foo; end", __FILE__, bug6403)
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index e8cb3b1722..4d99053b2f 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -710,4 +710,31 @@ class TestThreadGroup < Test::Unit::TestCase
end
assert_in_delta(t1 - t0, 1, 1)
end
+
+ def test_blocking_mutex_unlocked_on_fork
+ bug8433 = '[ruby-core:55102] [Bug #8433]'
+
+ mutex = Mutex.new
+ flag = false
+ mutex.lock
+
+ th = Thread.new do
+ mutex.synchronize do
+ flag = true
+ sleep
+ end
+ end
+
+ Thread.pass until th.stop?
+ mutex.unlock
+
+ pid = Process.fork do
+ exit(mutex.locked?)
+ end
+
+ th.kill
+
+ pid, status = Process.waitpid2(pid)
+ assert_equal(false, status.success?, bug8433)
+ end if Process.respond_to?(:fork)
end
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index 961c49432c..03172149ea 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -14,6 +14,20 @@ class TestTime < Test::Unit::TestCase
$VERBOSE = @verbose
end
+ def no_leap_seconds?
+ # 1972-06-30T23:59:60Z is the first leap second.
+ Time.utc(1972, 7, 1, 0, 0, 0) - Time.utc(1972, 6, 30, 23, 59, 59) == 1
+ end
+
+ def get_t2000
+ if no_leap_seconds?
+ # Sat Jan 01 00:00:00 UTC 2000
+ Time.at(946684800).gmtime
+ else
+ Time.utc(2000, 1, 1)
+ end
+ end
+
def test_new
assert_equal(Time.utc(2000,2,10), Time.new(2000,2,10, 11,0,0, 3600*11))
assert_equal(Time.utc(2000,2,10), Time.new(2000,2,9, 13,0,0, -3600*11))
@@ -378,6 +392,15 @@ class TestTime < Test::Unit::TestCase
assert_kind_of(Integer, T2000.hash)
end
+ def test_reinitialize
+ bug8099 = '[ruby-core:53436] [Bug #8099]'
+ t2000 = get_t2000
+ assert_raise(TypeError, bug8099) {
+ t2000.send(:initialize, 2013, 03, 14)
+ }
+ assert_equal(get_t2000, t2000, bug8099)
+ end
+
def test_init_copy
assert_equal(T2000, T2000.dup)
assert_raise(TypeError) do
diff --git a/test/rubygems/test_gem_requirement.rb b/test/rubygems/test_gem_requirement.rb
index 0bc6ad7059..d79cc8e3f7 100644
--- a/test/rubygems/test_gem_requirement.rb
+++ b/test/rubygems/test_gem_requirement.rb
@@ -37,17 +37,19 @@ class TestGemRequirement < Gem::TestCase
end
def test_parse_bad
- e = assert_raises ArgumentError do
- Gem::Requirement.parse nil
- end
-
- assert_equal 'Illformed requirement [nil]', e.message
+ [
+ nil,
+ '',
+ '! 1',
+ '= junk',
+ '1..2',
+ ].each do |bad|
+ e = assert_raises ArgumentError do
+ Gem::Requirement.parse bad
+ end
- e = assert_raises ArgumentError do
- Gem::Requirement.parse ""
+ assert_equal "Illformed requirement [#{bad.inspect}]", e.message
end
-
- assert_equal 'Illformed requirement [""]', e.message
end
def test_prerelease_eh
diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb
index f578063edc..e543ef8056 100644
--- a/test/rubygems/test_gem_version.rb
+++ b/test/rubygems/test_gem_version.rb
@@ -64,12 +64,18 @@ class TestGemVersion < Gem::TestCase
end
def test_initialize_bad
- ["junk", "1.0\n2.0"].each do |bad|
- e = assert_raises ArgumentError do
+ %W[
+ junk
+ 1.0\n2.0
+ 1..2
+ 1.2\ 3.4
+ 1-2-3
+ ].each do |bad|
+ e = assert_raises ArgumentError, bad do
Gem::Version.new bad
end
- assert_equal "Malformed version number string #{bad}", e.message
+ assert_equal "Malformed version number string #{bad}", e.message, bad
end
end
diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb
index f693a62e4b..548288817f 100644
--- a/test/socket/test_socket.rb
+++ b/test/socket/test_socket.rb
@@ -454,4 +454,75 @@ class TestSocket < Test::Unit::TestCase
ensure
server.close
end
+
+ def test_connect_in_rescue
+ serv = Addrinfo.tcp(nil, 0).listen
+ addr = serv.connect_address
+ begin
+ raise "dummy error"
+ rescue
+ s = addr.connect
+ assert(!s.closed?)
+ end
+ ensure
+ serv.close if serv && !serv.closed?
+ s.close if s && !s.closed?
+ end
+
+ def test_bind_in_rescue
+ begin
+ raise "dummy error"
+ rescue
+ s = Addrinfo.tcp(nil, 0).bind
+ assert(!s.closed?)
+ end
+ ensure
+ s.close if s && !s.closed?
+ end
+
+ def test_listen_in_rescue
+ begin
+ raise "dummy error"
+ rescue
+ s = Addrinfo.tcp(nil, 0).listen
+ assert(!s.closed?)
+ end
+ ensure
+ s.close if s && !s.closed?
+ end
+
+ def test_udp_server_sockets_in_rescue
+ begin
+ raise "dummy error"
+ rescue
+ ss = Socket.udp_server_sockets(0)
+ ss.each {|s|
+ assert(!s.closed?)
+ }
+ end
+ ensure
+ if ss
+ ss.each {|s|
+ s.close if !s.closed?
+ }
+ end
+ end
+
+ def test_tcp_server_sockets_in_rescue
+ begin
+ raise "dummy error"
+ rescue
+ ss = Socket.tcp_server_sockets(0)
+ ss.each {|s|
+ assert(!s.closed?)
+ }
+ end
+ ensure
+ if ss
+ ss.each {|s|
+ s.close if !s.closed?
+ }
+ end
+ end
+
end if defined?(Socket)
diff --git a/test/socket/test_unix.rb b/test/socket/test_unix.rb
index 3559eb8a75..71ca0d78df 100644
--- a/test/socket/test_unix.rb
+++ b/test/socket/test_unix.rb
@@ -5,6 +5,7 @@ end
require "test/unit"
require "tempfile"
+require "timeout"
require "tmpdir"
require "thread"
require "io/nonblock"
@@ -348,6 +349,28 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
s2.close if s2
end
+ def test_dgram_pair_sendrecvmsg_errno_set
+ s1, s2 = to_close = UNIXSocket.pair(Socket::SOCK_DGRAM)
+ pipe = IO.pipe
+ to_close.concat(pipe)
+ set_errno = lambda do
+ begin
+ pipe[0].read_nonblock(1)
+ fail
+ rescue => e
+ assert(IO::WaitReadable === e)
+ end
+ end
+ Timeout.timeout(10) do
+ set_errno.call
+ assert_equal(2, s1.sendmsg("HI"))
+ set_errno.call
+ assert_equal("HI", s2.recvmsg[0])
+ end
+ ensure
+ to_close.each(&:close) if to_close
+ end
+
def test_epipe # [ruby-dev:34619]
s1, s2 = UNIXSocket.pair
s1.shutdown(Socket::SHUT_WR)
diff --git a/test/test_mathn.rb b/test/test_mathn.rb
index f511adb7d5..42a93139fd 100644
--- a/test/test_mathn.rb
+++ b/test/test_mathn.rb
@@ -5,6 +5,102 @@ require_relative 'ruby/envutil'
class TestMathn < Test::Unit::TestCase
def test_power
assert_in_out_err ['-r', 'mathn', '-e', 'a=1**2;!a'], "", [], [], '[ruby-core:25740]'
- assert_in_out_err ['-r', 'mathn', '-e', 'a=(1<<126)**2;!a'], "", [], [], '[ruby-core:25740]'
+ assert_in_out_err ['-r', 'mathn', '-e', 'a=(1 << 126)**2;!a'], "", [], [], '[ruby-core:25740]'
+ end
+
+ def assert_separated_equal(options, expected, actual, message = nil)
+ assert_in_out_err([*options, '-e', "p((#{actual})==(#{expected}))"], "", ["true"], [], message)
+ end
+
+ def test_floor
+ assert_separated_equal(%w[-rmathn], " 2", "( 13/5).floor")
+ assert_separated_equal(%w[-rmathn], " 2", "( 5/2).floor")
+ assert_separated_equal(%w[-rmathn], " 2", "( 12/5).floor")
+ assert_separated_equal(%w[-rmathn], "-3", "(-12/5).floor")
+ assert_separated_equal(%w[-rmathn], "-3", "( -5/2).floor")
+ assert_separated_equal(%w[-rmathn], "-3", "(-13/5).floor")
+
+ assert_separated_equal(%w[-rmathn], " 2", "( 13/5).floor(0)")
+ assert_separated_equal(%w[-rmathn], " 2", "( 5/2).floor(0)")
+ assert_separated_equal(%w[-rmathn], " 2", "( 12/5).floor(0)")
+ assert_separated_equal(%w[-rmathn], "-3", "(-12/5).floor(0)")
+ assert_separated_equal(%w[-rmathn], "-3", "( -5/2).floor(0)")
+ assert_separated_equal(%w[-rmathn], "-3", "(-13/5).floor(0)")
+
+ assert_separated_equal(%w[-rmathn], "( 13/5)", "( 13/5).floor(2)")
+ assert_separated_equal(%w[-rmathn], "( 5/2)", "( 5/2).floor(2)")
+ assert_separated_equal(%w[-rmathn], "( 12/5)", "( 12/5).floor(2)")
+ assert_separated_equal(%w[-rmathn], "(-12/5)", "(-12/5).floor(2)")
+ assert_separated_equal(%w[-rmathn], "( -5/2)", "( -5/2).floor(2)")
+ assert_separated_equal(%w[-rmathn], "(-13/5)", "(-13/5).floor(2)")
+ end
+
+ def test_ceil
+ assert_separated_equal(%w[-rmathn], " 3", "( 13/5).ceil")
+ assert_separated_equal(%w[-rmathn], " 3", "( 5/2).ceil")
+ assert_separated_equal(%w[-rmathn], " 3", "( 12/5).ceil")
+ assert_separated_equal(%w[-rmathn], "-2", "(-12/5).ceil")
+ assert_separated_equal(%w[-rmathn], "-2", "( -5/2).ceil")
+ assert_separated_equal(%w[-rmathn], "-2", "(-13/5).ceil")
+
+ assert_separated_equal(%w[-rmathn], " 3", "( 13/5).ceil(0)")
+ assert_separated_equal(%w[-rmathn], " 3", "( 5/2).ceil(0)")
+ assert_separated_equal(%w[-rmathn], " 3", "( 12/5).ceil(0)")
+ assert_separated_equal(%w[-rmathn], "-2", "(-12/5).ceil(0)")
+ assert_separated_equal(%w[-rmathn], "-2", "( -5/2).ceil(0)")
+ assert_separated_equal(%w[-rmathn], "-2", "(-13/5).ceil(0)")
+
+ assert_separated_equal(%w[-rmathn], "( 13/5)", "( 13/5).ceil(2)")
+ assert_separated_equal(%w[-rmathn], "( 5/2)", "( 5/2).ceil(2)")
+ assert_separated_equal(%w[-rmathn], "( 12/5)", "( 12/5).ceil(2)")
+ assert_separated_equal(%w[-rmathn], "(-12/5)", "(-12/5).ceil(2)")
+ assert_separated_equal(%w[-rmathn], "( -5/2)", "( -5/2).ceil(2)")
+ assert_separated_equal(%w[-rmathn], "(-13/5)", "(-13/5).ceil(2)")
+ end
+
+ def test_truncate
+ assert_separated_equal(%w[-rmathn], " 2", "( 13/5).truncate")
+ assert_separated_equal(%w[-rmathn], " 2", "( 5/2).truncate")
+ assert_separated_equal(%w[-rmathn], " 2", "( 12/5).truncate")
+ assert_separated_equal(%w[-rmathn], "-2", "(-12/5).truncate")
+ assert_separated_equal(%w[-rmathn], "-2", "( -5/2).truncate")
+ assert_separated_equal(%w[-rmathn], "-2", "(-13/5).truncate")
+
+ assert_separated_equal(%w[-rmathn], " 2", "( 13/5).truncate(0)")
+ assert_separated_equal(%w[-rmathn], " 2", "( 5/2).truncate(0)")
+ assert_separated_equal(%w[-rmathn], " 2", "( 12/5).truncate(0)")
+ assert_separated_equal(%w[-rmathn], "-2", "(-12/5).truncate(0)")
+ assert_separated_equal(%w[-rmathn], "-2", "( -5/2).truncate(0)")
+ assert_separated_equal(%w[-rmathn], "-2", "(-13/5).truncate(0)")
+
+ assert_separated_equal(%w[-rmathn], "( 13/5)", "( 13/5).truncate(2)")
+ assert_separated_equal(%w[-rmathn], "( 5/2)", "( 5/2).truncate(2)")
+ assert_separated_equal(%w[-rmathn], "( 12/5)", "( 12/5).truncate(2)")
+ assert_separated_equal(%w[-rmathn], "(-12/5)", "(-12/5).truncate(2)")
+ assert_separated_equal(%w[-rmathn], "( -5/2)", "( -5/2).truncate(2)")
+ assert_separated_equal(%w[-rmathn], "(-13/5)", "(-13/5).truncate(2)")
+ end
+
+ def test_round
+ assert_separated_equal(%w[-rmathn], " 3", "( 13/5).round")
+ assert_separated_equal(%w[-rmathn], " 3", "( 5/2).round")
+ assert_separated_equal(%w[-rmathn], " 2", "( 12/5).round")
+ assert_separated_equal(%w[-rmathn], "-2", "(-12/5).round")
+ assert_separated_equal(%w[-rmathn], "-3", "( -5/2).round")
+ assert_separated_equal(%w[-rmathn], "-3", "(-13/5).round")
+
+ assert_separated_equal(%w[-rmathn], " 3", "( 13/5).round(0)")
+ assert_separated_equal(%w[-rmathn], " 3", "( 5/2).round(0)")
+ assert_separated_equal(%w[-rmathn], " 2", "( 12/5).round(0)")
+ assert_separated_equal(%w[-rmathn], "-2", "(-12/5).round(0)")
+ assert_separated_equal(%w[-rmathn], "-3", "( -5/2).round(0)")
+ assert_separated_equal(%w[-rmathn], "-3", "(-13/5).round(0)")
+
+ assert_separated_equal(%w[-rmathn], "( 13/5)", "( 13/5).round(2)")
+ assert_separated_equal(%w[-rmathn], "( 5/2)", "( 5/2).round(2)")
+ assert_separated_equal(%w[-rmathn], "( 12/5)", "( 12/5).round(2)")
+ assert_separated_equal(%w[-rmathn], "(-12/5)", "(-12/5).round(2)")
+ assert_separated_equal(%w[-rmathn], "( -5/2)", "( -5/2).round(2)")
+ assert_separated_equal(%w[-rmathn], "(-13/5)", "(-13/5).round(2)")
end
end
diff --git a/test/test_tempfile.rb b/test/test_tempfile.rb
index 1462a981f7..c6cbbeeeeb 100644
--- a/test/test_tempfile.rb
+++ b/test/test_tempfile.rb
@@ -206,6 +206,21 @@ puts Tempfile.new('foo').path
end
end
+ def test_tempfile_finalizer_does_not_run_if_unlinked
+ bug8768 = '[ruby-core:56521] [Bug #8768]'
+ args = %w(--disable-gems -rtempfile)
+ assert_in_out_err(args, <<-'EOS') do |(filename), (error)|
+ tmp = Tempfile.new('foo')
+ puts tmp.path
+ tmp.close
+ tmp.unlink
+ $DEBUG = true
+ EOS
+ refute File.exist?(filename)
+ assert_nil(error, "#{bug8768} we used to get a confusing 'removing ...done' here")
+ end
+ end
+
def test_size_flushes_buffer_before_determining_file_size
t = tempfile("foo")
t.write("hello")
diff --git a/test/test_time.rb b/test/test_time.rb
index 9dbce3f654..df6bbfd20c 100644
--- a/test/test_time.rb
+++ b/test/test_time.rb
@@ -393,6 +393,8 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
def test_strptime
assert_equal(Time.utc(2005, 8, 28, 06, 54, 20), Time.strptime("28/Aug/2005:06:54:20 +0000", "%d/%b/%Y:%T %z"))
assert_equal(Time.at(1).localtime, Time.strptime("1", "%s"))
+ assert_equal(false, Time.strptime('0', '%s').utc?)
+ assert_equal(3600, Time.strptime('0 +0100', '%s %z').utc_offset)
end
def test_nsec
diff --git a/test/thread/test_queue.rb b/test/thread/test_queue.rb
index b0ffe0866d..9d8d481ba4 100644
--- a/test/thread/test_queue.rb
+++ b/test/thread/test_queue.rb
@@ -10,6 +10,28 @@ class TestQueue < Test::Unit::TestCase
grind(5, 1000, 15, SizedQueue, 1000)
end
+ def test_sized_queue_clear
+ # Fill queue, then test that SizedQueue#clear wakes up all waiting threads
+ sq = SizedQueue.new(2)
+ 2.times { sq << 1 }
+
+ t1 = Thread.new do
+ sq << 1
+ end
+
+ t2 = Thread.new do
+ sq << 1
+ end
+
+ t3 = Thread.new do
+ Thread.pass
+ sq.clear
+ end
+
+ [t3, t2, t1].each(&:join)
+ assert_equal sq.length, 2
+ end
+
def grind(num_threads, num_objects, num_iterations, klass, *args)
from_workers = klass.new(*args)
to_workers = klass.new(*args)
diff --git a/test/webrick/test_cgi.rb b/test/webrick/test_cgi.rb
index d930c265de..702b8b46bd 100644
--- a/test/webrick/test_cgi.rb
+++ b/test/webrick/test_cgi.rb
@@ -19,7 +19,7 @@ class TestWEBrickCGI < Test::Unit::TestCase
end
},
}
- if RUBY_PLATFORM =~ /mswin32|mingw|cygwin|bccwin32/
+ if RUBY_PLATFORM =~ /mswin|mingw|cygwin|bccwin32/
config[:CGIPathEnv] = ENV['PATH'] # runtime dll may not be in system dir.
end
TestWEBrick.start_httpserver(config){|server, addr, port, log|
diff --git a/test/webrick/test_httputils.rb b/test/webrick/test_httputils.rb
index ebe8a2b8a5..2753cbe6c9 100644
--- a/test/webrick/test_httputils.rb
+++ b/test/webrick/test_httputils.rb
@@ -66,6 +66,10 @@ class TestWEBrickHTTPUtils < Test::Unit::TestCase
assert_equal("/~foo%20bar", escape("/~foo bar"))
assert_equal("/~foo%09bar", escape("/~foo\tbar"))
assert_equal("/~foo+bar", escape("/~foo+bar"))
+ bug8425 = '[Bug #8425] [ruby-core:55052]'
+ assert_nothing_raised(ArgumentError, Encoding::CompatibilityError, bug8425) {
+ assert_equal("%E3%83%AB%E3%83%93%E3%83%BC%E3%81%95%E3%82%93", escape("\u{30EB 30D3 30FC 3055 3093}"))
+ }
end
def test_escape_form