* eval.c (Init_eval): add aliases invoke_method and

invoke_functional_method corresponding send and funcall
  respectively.  [ruby-talk:197512]

* parse.y (parser_yylex): returns the most typical keyword token
  on EXPR_FNAME.  [ruby-core:7995]

* ext/socket/socket.c: protoize.

* parse.y (then): remove ':' from 'then' and 'do' rules.

* hash.c (env_aset): raise TypeError on nil with more descriptive
  message.  [ruby-core:07990]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2006-06-17 14:50:04 +00:00
parent 7d274ff6fb
commit 7b48490222
7 changed files with 363 additions and 356 deletions

View File

@ -1,3 +1,14 @@
Sat Jun 17 23:42:26 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (Init_eval): add aliases invoke_method and
invoke_functional_method corresponding send and funcall
respectively. [ruby-talk:197512]
* parse.y (parser_yylex): returns the most typical keyword token
on EXPR_FNAME. [ruby-core:7995]
* ext/socket/socket.c: protoize.
Sat Jun 17 14:53:32 2006 Tanaka Akira <akr@m17n.org> Sat Jun 17 14:53:32 2006 Tanaka Akira <akr@m17n.org>
* lib/pathname.rb (Kernel#Pathname): new method. * lib/pathname.rb (Kernel#Pathname): new method.
@ -7,16 +18,16 @@ Sat Jun 17 02:01:00 2006 Tanaka Akira <akr@m17n.org>
* lib/pp.rb (Kernel#pretty_inspect): defined for pretty printed * lib/pp.rb (Kernel#pretty_inspect): defined for pretty printed
string. string.
Sat Jun 17 00:23:58 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (reswords): kDO_BLOCK was missing. fixed: [ruby-core:7995]
Fri Jun 16 01:41:00 2006 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri Jun 16 01:41:00 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_proc_arity): get rid of segfault for mere splat. * eval.c (rb_proc_arity): get rid of segfault for mere splat.
* gc.c (gc_mark_children): NODE_BLOCK_PASS needs u3 to be marked. * gc.c (gc_mark_children): NODE_BLOCK_PASS needs u3 to be marked.
Thu Jun 15 22:06:56 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (then): remove ':' from 'then' and 'do' rules.
Wed Jun 14 18:00:20 2006 Eric Hodel <drbrain@segment7.net> Wed Jun 14 18:00:20 2006 Eric Hodel <drbrain@segment7.net>
* enum.c (enum_any): Documentation typo. * enum.c (enum_any): Documentation typo.
@ -30,6 +41,11 @@ Wed Jun 14 16:11:37 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* eval.c (rb_f_method_name, rb_f_callee_name): document typo. * eval.c (rb_f_method_name, rb_f_callee_name): document typo.
Wed Jun 14 15:19:14 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* hash.c (env_aset): raise TypeError on nil with more descriptive
message. [ruby-core:07990]
Tue Jun 13 17:22:19 2006 Yukihiro Matsumoto <matz@ruby-lang.org> Tue Jun 13 17:22:19 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/socket/socket.c (Init_socket): remove obsolete constants: * ext/socket/socket.c (Init_socket): remove obsolete constants:

2
eval.c
View File

@ -7820,7 +7820,9 @@ Init_eval(void)
rb_define_method(rb_cBasicObject, "send", rb_f_send, -1); rb_define_method(rb_cBasicObject, "send", rb_f_send, -1);
rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1); rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1);
rb_define_method(rb_cBasicObject, "invoke_method", rb_f_send, -1);
rb_define_method(rb_cBasicObject, "funcall", rb_f_funcall, -1); rb_define_method(rb_cBasicObject, "funcall", rb_f_funcall, -1);
rb_define_method(rb_cBasicObject, "invoke_functional_method", rb_f_funcall, -1);
rb_define_method(rb_mKernel, "instance_eval", rb_obj_instance_eval, -1); rb_define_method(rb_mKernel, "instance_eval", rb_obj_instance_eval, -1);
rb_define_method(rb_mKernel, "instance_exec", rb_obj_instance_exec, -1); rb_define_method(rb_mKernel, "instance_exec", rb_obj_instance_exec, -1);

File diff suppressed because it is too large Load Diff

3
file.c
View File

@ -2877,7 +2877,8 @@ rb_file_join(VALUE ary, VALUE sep)
len += 10; len += 10;
} }
} }
if (!NIL_P(sep) && TYPE(sep) == T_STRING) { if (!NIL_P(sep)) {
StringValue(sep);
len += RSTRING(sep)->len * RARRAY(ary)->len - 1; len += RSTRING(sep)->len * RARRAY(ary)->len - 1;
} }
result = rb_str_buf_new(len); result = rb_str_buf_new(len);

3
hash.c
View File

@ -1759,6 +1759,9 @@ env_aset(VALUE obj, VALUE nm, VALUE val)
rb_raise(rb_eSecurityError, "can't change environment variable"); rb_raise(rb_eSecurityError, "can't change environment variable");
} }
if (NIL_P(val)) {
rb_raise(rb_eTypeError, "cannot assign nil; use Hash#delete instead");
}
StringValue(nm); StringValue(nm);
StringValue(val); StringValue(val);
name = RSTRING(nm)->ptr; name = RSTRING(nm)->ptr;

View File

@ -1,5 +1,3 @@
# :nodoc:
#
# Author:: Nathaniel Talbott. # Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. # Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
# License:: Ruby license. # License:: Ruby license.
@ -10,21 +8,39 @@ require 'test/unit/util/backtracefilter'
module Test # :nodoc: module Test # :nodoc:
module Unit # :nodoc: module Unit # :nodoc:
# Contains all of the standard Test::Unit assertions. Mixed in ##
# to Test::Unit::TestCase. To mix it in and use its # Test::Unit::Assertions contains the standard Test::Unit assertions.
# functionality, you simply need to rescue # Assertions is included in Test::Unit::TestCase.
# Test::Unit::AssertionFailedError, and you can additionally #
# override add_assertion to be notified whenever an assertion # To include it in your own code and use its functionality, you simply
# is made. # need to rescue Test::Unit::AssertionFailedError. Additionally you may
# override add_assertion to get notified whenever an assertion is made.
# #
# Notes: # Notes:
# * The message to each assertion, if given, will be # * The message to each assertion, if given, will be propagated with the
# propagated with the failure. # failure.
# * It's easy to add your own assertions based on assert_block(). # * It is easy to add your own assertions based on assert_block().
#
# = Example Custom Assertion
#
# def deny(boolean, message = nil)
# message = build_message message, '<?> is not false or nil.', boolean
# assert_block message do
# not boolean
# end
# end
module Assertions module Assertions
# The assertion upon which all other assertions are ##
# based. Passes if the block yields true. # The assertion upon which all other assertions are based. Passes if the
# block yields true.
#
# Example:
# assert_block "Couldn't do the thing" do
# do_the_thing
# end
public public
def assert_block(message="assert_block failed.") # :yields: def assert_block(message="assert_block failed.") # :yields:
_wrap_assertion do _wrap_assertion do
@ -34,7 +50,12 @@ module Test # :nodoc:
end end
end end
# Passes if boolean is true. ##
# Asserts that +boolean+ is not false or nil.
#
# Example:
# assert [1, 2].include?(5)
public public
def assert(boolean, message=nil) def assert(boolean, message=nil)
_wrap_assertion do _wrap_assertion do
@ -43,10 +64,16 @@ module Test # :nodoc:
end end
end end
# Passes if expected == actual. Note that the ordering of ##
# arguments is important, since a helpful error message is # Passes if +expected+ == +actual.
# generated when this one fails that tells you the values #
# of expected and actual. # Note that the ordering of arguments is important, since a helpful
# error message is generated when this one fails that tells you the
# values of expected and actual.
#
# Example:
# assert_equal 'MY STRING', 'my string'.upcase
public public
def assert_equal(expected, actual, message=nil) def assert_equal(expected, actual, message=nil)
full_message = build_message(message, <<EOT, expected, actual) full_message = build_message(message, <<EOT, expected, actual)
@ -57,7 +84,7 @@ EOT
end end
private private
def _check_exception_class(args) def _check_exception_class(args) # :nodoc:
args.partition do |klass| args.partition do |klass|
next if klass.instance_of?(Module) next if klass.instance_of?(Module)
assert(Exception >= klass, "Should expect a class of exception, #{klass}") assert(Exception >= klass, "Should expect a class of exception, #{klass}")
@ -66,12 +93,19 @@ EOT
end end
private private
def _expected_exception?(actual_exception, exceptions, modules) def _expected_exception?(actual_exception, exceptions, modules) # :nodoc:
exceptions.include?(actual_exception.class) or exceptions.include?(actual_exception.class) or
modules.any? {|mod| actual_exception.is_a?(mod)} modules.any? {|mod| actual_exception.is_a?(mod)}
end end
# Passes if block raises one of the given exceptions. ##
# Passes if the block raises one of the given exceptions.
#
# Example:
# assert_raise RuntimeError, LoadError do
# raise 'Boom!!!'
# end
public public
def assert_raise(*args) def assert_raise(*args)
_wrap_assertion do _wrap_assertion do
@ -98,13 +132,22 @@ EOT
end end
end end
# Alias of assert_raise. Will be deprecated in 1.9, and removed in 2.0. ##
# Alias of assert_raise.
#
# Will be deprecated in 1.9, and removed in 2.0.
public public
def assert_raises(*args, &block) def assert_raises(*args, &block)
assert_raise(*args, &block) assert_raise(*args, &block)
end end
# Passes if object.class == klass. ##
# Passes if +object+ .instance_of? +klass+
#
# Example:
# assert_instance_of String, 'foo'
public public
def assert_instance_of(klass, object, message="") def assert_instance_of(klass, object, message="")
_wrap_assertion do _wrap_assertion do
@ -118,13 +161,23 @@ EOT
end end
end end
# Passes if object.nil?. ##
# Passes if +object+ is nil.
#
# Example:
# assert_nil [1, 2].uniq!
public public
def assert_nil(object, message="") def assert_nil(object, message="")
assert_equal(nil, object, message) assert_equal(nil, object, message)
end end
# Passes if object.kind_of?(klass). ##
# Passes if +object+ .kind_of? +klass+
#
# Example:
# assert_kind_of Object, 'foo'
public public
def assert_kind_of(klass, object, message="") def assert_kind_of(klass, object, message="")
_wrap_assertion do _wrap_assertion do
@ -134,7 +187,12 @@ EOT
end end
end end
# Passes if object.respond_to?(method) is true. ##
# Passes if +object+ .respond_to? +method+
#
# Example:
# assert_respond_to 'bugbear', :slice
public public
def assert_respond_to(object, method, message="") def assert_respond_to(object, method, message="")
_wrap_assertion do _wrap_assertion do
@ -152,7 +210,12 @@ EOT
end end
end end
# Passes if string =~ pattern. ##
# Passes if +string+ =~ +pattern+.
#
# Example:
# assert_match(/\d+/, 'five, 6, seven')
public public
def assert_match(pattern, string, message="") def assert_match(pattern, string, message="")
_wrap_assertion do _wrap_assertion do
@ -167,8 +230,14 @@ EOT
end end
end end
# Passes if actual.equal?(expected) (i.e. they are the ##
# same instance). # Passes if +actual+ .equal? +expected+ (i.e. they are the same
# instance).
#
# Example:
# o = Object.new
# assert_same o, o
public public
def assert_same(expected, actual, message="") def assert_same(expected, actual, message="")
full_message = build_message(message, <<EOT, expected, expected.__id__, actual, actual.__id__) full_message = build_message(message, <<EOT, expected, expected.__id__, actual, actual.__id__)
@ -180,9 +249,14 @@ EOT
assert_block(full_message) { actual.equal?(expected) } assert_block(full_message) { actual.equal?(expected) }
end end
# Compares the two objects based on the passed ##
# operator. Passes if object1.__send__(operator, object2) # Compares the +object1+ with +object2+ using +operator+.
# is true. #
# Passes if object1.__send__(operator, object2) is true.
#
# Example:
# assert_operator 5, :>=, 4
public public
def assert_operator(object1, operator, object2, message="") def assert_operator(object1, operator, object2, message="")
_wrap_assertion do _wrap_assertion do
@ -197,7 +271,14 @@ EOT
end end
end end
##
# Passes if block does not raise an exception. # Passes if block does not raise an exception.
#
# Example:
# assert_nothing_raised do
# [1, 2].uniq
# end
public public
def assert_nothing_raised(*args) def assert_nothing_raised(*args)
_wrap_assertion do _wrap_assertion do
@ -221,13 +302,23 @@ EOT
end end
end end
# Always fails. ##
# Flunk always fails.
#
# Example:
# flunk 'Not done testing yet.'
public public
def flunk(message="Flunked") def flunk(message="Flunked")
assert_block(build_message(message)){false} assert_block(build_message(message)){false}
end end
# Passes if !actual.equal?(expected). ##
# Passes if ! +actual+ .equal? +expected+
#
# Example:
# assert_not_same Object.new, Object.new
public public
def assert_not_same(expected, actual, message="") def assert_not_same(expected, actual, message="")
full_message = build_message(message, <<EOT, expected, expected.__id__, actual, actual.__id__) full_message = build_message(message, <<EOT, expected, expected.__id__, actual, actual.__id__)
@ -239,21 +330,36 @@ EOT
assert_block(full_message) { !actual.equal?(expected) } assert_block(full_message) { !actual.equal?(expected) }
end end
# Passes if expected != actual. ##
# Passes if +expected+ != +actual+
#
# Example:
# assert_not_equal 'some string', 5
public public
def assert_not_equal(expected, actual, message="") def assert_not_equal(expected, actual, message="")
full_message = build_message(message, "<?> expected to be != to\n<?>.", expected, actual) full_message = build_message(message, "<?> expected to be != to\n<?>.", expected, actual)
assert_block(full_message) { expected != actual } assert_block(full_message) { expected != actual }
end end
# Passes if !object.nil?. ##
# Passes if ! +object+ .nil?
#
# Example:
# assert_not_nil '1 two 3'.sub!(/two/, '2')
public public
def assert_not_nil(object, message="") def assert_not_nil(object, message="")
full_message = build_message(message, "<?> expected to not be nil.", object) full_message = build_message(message, "<?> expected to not be nil.", object)
assert_block(full_message){!object.nil?} assert_block(full_message){!object.nil?}
end end
# Passes if string !~ regularExpression. ##
# Passes if +regexp+ !~ +string+
#
# Example:
# assert_no_match(/two/, 'one 2 three')
public public
def assert_no_match(regexp, string, message="") def assert_no_match(regexp, string, message="")
_wrap_assertion do _wrap_assertion do
@ -266,7 +372,14 @@ EOT
UncaughtThrow = {NameError => /^uncaught throw \`(.+)\'$/, UncaughtThrow = {NameError => /^uncaught throw \`(.+)\'$/,
ThreadError => /^uncaught throw \`(.+)\' in thread /} #` ThreadError => /^uncaught throw \`(.+)\' in thread /} #`
# Passes if block throws symbol. ##
# Passes if the block throws +expected_symbol+
#
# Example:
# assert_throws :done do
# throw :done
# end
public public
def assert_throws(expected_symbol, message="", &proc) def assert_throws(expected_symbol, message="", &proc)
_wrap_assertion do _wrap_assertion do
@ -290,7 +403,14 @@ EOT
end end
end end
##
# Passes if block does not throw anything. # Passes if block does not throw anything.
#
# Example:
# assert_nothing_thrown do
# [1, 2].uniq
# end
public public
def assert_nothing_thrown(message="", &proc) def assert_nothing_thrown(message="", &proc)
_wrap_assertion do _wrap_assertion do
@ -308,8 +428,13 @@ EOT
end end
end end
# Passes if expected_float and actual_float are equal ##
# within delta tolerance. # Passes if +expected_float+ and +actual_float+ are equal
# within +delta+ tolerance.
#
# Example:
# assert_in_delta 0.05, (50000.0 / 10**6), 0.00001
public public
def assert_in_delta(expected_float, actual_float, delta, message="") def assert_in_delta(expected_float, actual_float, delta, message="")
_wrap_assertion do _wrap_assertion do
@ -326,7 +451,17 @@ EOT
end end
end end
# Passes if the method sent returns a true value. ##
# Passes if the method send returns a true value.
#
# +send_array+ is composed of:
# * A receiver
# * A method
# * Arguments to the method
#
# Example:
# assert_send [[1, 2], :include?, 4]
public public
def assert_send(send_array, message="") def assert_send(send_array, message="")
_wrap_assertion do _wrap_assertion do
@ -340,6 +475,10 @@ EOT
end end
end end
##
# Builds a failure message. +head+ is added before the +template+ and
# +arguments+ replaces the '?'s positionally in the template.
public public
def build_message(head, template=nil, *arguments) # :nodoc: def build_message(head, template=nil, *arguments) # :nodoc:
template &&= template.chomp template &&= template.chomp
@ -362,20 +501,26 @@ EOT
end end
end end
# Called whenever an assertion is made. ##
# Called whenever an assertion is made. Define this in classes that
# include Test::Unit::Assertions to record assertion counts.
private private
def add_assertion def add_assertion
end end
# Select whether or not to use the prettyprinter. If this ##
# option is set to false before any assertions are made, the # Select whether or not to use the pretty-printer. If this option is set
# prettyprinter will not be required at all. # to false before any assertions are made, pp.rb will not be required.
public public
def self.use_pp=(value) def self.use_pp=(value)
AssertionMessage.use_pp = value AssertionMessage.use_pp = value
end end
class AssertionMessage # :nodoc: all # :stopdoc:
class AssertionMessage
@use_pp = true @use_pp = true
class << self class << self
attr_accessor :use_pp attr_accessor :use_pp
@ -469,6 +614,9 @@ EOM
message_parts.join("\n") message_parts.join("\n")
end end
end end
# :startdoc:
end end
end end
end end

13
parse.y
View File

@ -1651,7 +1651,7 @@ op : '|' { ifndef_ripper($$ = '|'); }
reswords : k__LINE__ | k__FILE__ | klBEGIN | klEND reswords : k__LINE__ | k__FILE__ | klBEGIN | klEND
| kALIAS | kAND | kBEGIN | kBREAK | kCASE | kCLASS | kDEF | kALIAS | kAND | kBEGIN | kBREAK | kCASE | kCLASS | kDEF
| kDEFINED | kDO | kDO_BLOCK | kELSE | kELSIF | kEND | kENSURE | kFALSE | kDEFINED | kDO | kELSE | kELSIF | kEND | kENSURE | kFALSE
| kFOR | kIN | kMODULE | kNEXT | kNIL | kNOT | kFOR | kIN | kMODULE | kNEXT | kNIL | kNOT
| kOR | kREDO | kRESCUE | kRETRY | kRETURN | kSELF | kSUPER | kOR | kREDO | kRESCUE | kRETRY | kRETURN | kSELF | kSUPER
| kTHEN | kTRUE | kUNDEF | kWHEN | kYIELD | kTHEN | kTRUE | kUNDEF | kWHEN | kYIELD
@ -2834,11 +2834,6 @@ then : term
/*%c /*%c
{ $$ = Qnil; } { $$ = Qnil; }
%*/ %*/
| ':'
/*%c%*/
/*%c
{ $$ = Qnil; }
%*/
| kTHEN | kTHEN
| term kTHEN | term kTHEN
/*%c%*/ /*%c%*/
@ -2852,11 +2847,6 @@ do : term
/*%c /*%c
{ $$ = Qnil; } { $$ = Qnil; }
%*/ %*/
| ':'
/*%c%*/
/*%c
{ $$ = Qnil; }
%*/
| kDO_COND | kDO_COND
; ;
@ -6727,6 +6717,7 @@ parser_yylex(struct parser_params *parser)
lex_state = kw->state; lex_state = kw->state;
if (state == EXPR_FNAME) { if (state == EXPR_FNAME) {
set_yylval_id(rb_intern(kw->name)); set_yylval_id(rb_intern(kw->name));
return kw->id[0];
} }
if (kw->id[0] == kDO) { if (kw->id[0] == kDO) {
if (lpar_beg && lpar_beg == paren_nest) { if (lpar_beg && lpar_beg == paren_nest) {