diff options
40 files changed, 68 insertions, 52 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c index 7bfdf4a..f075105 100644 --- a/ext/psych/parser.c +++ b/ext/psych/parser.c @@ -19,9 +19,9 @@ static ID id_end_mapping; #define PSYCH_TRANSCODE(_str, _yaml_enc, _internal_enc) \ do { \ - rb_enc_associate_index(_str, _yaml_enc); \ + rb_enc_associate_index((_str), (_yaml_enc)); \ if(_internal_enc) \ - _str = rb_str_export_to_enc(_str, _internal_enc); \ + (_str) = rb_str_export_to_enc((_str), (_internal_enc)); \ } while (0) static int io_reader(void * data, unsigned char *buf, size_t size, size_t *read) diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index 719720a..84ebc90 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -79,15 +79,20 @@ module Psych end if target.respond_to?(:to_yaml) - loc = target.method(:to_yaml).source_location.first - if loc !~ /(syck\/rubytypes.rb|psych\/core_ext.rb)/ - unless target.respond_to?(:encode_with) - if $VERBOSE - warn "implementing to_yaml is deprecated, please implement \"encode_with\"" + begin + loc = target.method(:to_yaml).source_location.first + if loc !~ /(syck\/rubytypes.rb|psych\/core_ext.rb)/ + unless target.respond_to?(:encode_with) + if $VERBOSE + warn "implementing to_yaml is deprecated, please implement \"encode_with\"" + end + + target.to_yaml(:nodump => true) end - - target.to_yaml(:nodump => true) end + rescue + # public_method or source_location might be overridden, + # and it's OK to skip it since it's only to emit a warning end end @@ -300,12 +305,17 @@ module Psych # FIXME: remove this method once "to_yaml_properties" is removed def find_ivars target - loc = target.method(:to_yaml_properties).source_location.first - unless loc.start_with?(Psych::DEPRECATED) || loc.end_with?('rubytypes.rb') - if $VERBOSE - warn "#{loc}: to_yaml_properties is deprecated, please implement \"encode_with(coder)\"" + begin + loc = target.method(:to_yaml_properties).source_location.first + unless loc.start_with?(Psych::DEPRECATED) || loc.end_with?('rubytypes.rb') + if $VERBOSE + warn "#{loc}: to_yaml_properties is deprecated, please implement \"encode_with(coder)\"" + end + return target.to_yaml_properties end - return target.to_yaml_properties + rescue + # public_method or source_location might be overridden, + # and it's OK to skip it since it's only to emit a warning. end target.instance_variables diff --git a/test/psych/json/test_stream.rb b/test/psych/json/test_stream.rb index 45d0219..0af64c1 100644 --- a/test/psych/json/test_stream.rb +++ b/test/psych/json/test_stream.rb @@ -1,4 +1,4 @@ -require_relative '../helper' +require 'psych/helper' module Psych module JSON diff --git a/test/psych/nodes/test_enumerable.rb b/test/psych/nodes/test_enumerable.rb index 57d4e89..19cf94b 100644 --- a/test/psych/nodes/test_enumerable.rb +++ b/test/psych/nodes/test_enumerable.rb @@ -1,4 +1,4 @@ -require_relative '../helper' +require 'psych/helper' module Psych module Nodes diff --git a/test/psych/test_alias_and_anchor.rb b/test/psych/test_alias_and_anchor.rb index 8c9cd80..48771d6 100644 --- a/test/psych/test_alias_and_anchor.rb +++ b/test/psych/test_alias_and_anchor.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestAliasAndAnchor < TestCase diff --git a/test/psych/test_array.rb b/test/psych/test_array.rb index f006cc8..ec6a1aa 100644 --- a/test/psych/test_array.rb +++ b/test/psych/test_array.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestArray < TestCase diff --git a/test/psych/test_boolean.rb b/test/psych/test_boolean.rb index b656f4f..ebfa25e 100644 --- a/test/psych/test_boolean.rb +++ b/test/psych/test_boolean.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych ### diff --git a/test/psych/test_class.rb b/test/psych/test_class.rb index 5a39b8c..cba88ba 100644 --- a/test/psych/test_class.rb +++ b/test/psych/test_class.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestClass < TestCase diff --git a/test/psych/test_coder.rb b/test/psych/test_coder.rb index 4809b13..7539c7d 100644 --- a/test/psych/test_coder.rb +++ b/test/psych/test_coder.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestCoder < TestCase diff --git a/test/psych/test_date_time.rb b/test/psych/test_date_time.rb index df66d14..fb76cb3 100644 --- a/test/psych/test_date_time.rb +++ b/test/psych/test_date_time.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' require 'date' module Psych diff --git a/test/psych/test_deprecated.rb b/test/psych/test_deprecated.rb index a272db2..cfce082 100644 --- a/test/psych/test_deprecated.rb +++ b/test/psych/test_deprecated.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestDeprecated < TestCase diff --git a/test/psych/test_document.rb b/test/psych/test_document.rb index 358fc51..55add5f 100644 --- a/test/psych/test_document.rb +++ b/test/psych/test_document.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestDocument < TestCase diff --git a/test/psych/test_emitter.rb b/test/psych/test_emitter.rb index 0554ae5..dfd20e1 100644 --- a/test/psych/test_emitter.rb +++ b/test/psych/test_emitter.rb @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -require_relative 'helper' +require 'psych/helper' module Psych class TestEmitter < TestCase diff --git a/test/psych/test_encoding.rb b/test/psych/test_encoding.rb index 8e97663..029ff75 100644 --- a/test/psych/test_encoding.rb +++ b/test/psych/test_encoding.rb @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -require_relative 'helper' +require 'psych/helper' module Psych class TestEncoding < TestCase diff --git a/test/psych/test_engine_manager.rb b/test/psych/test_engine_manager.rb index 8bd7d6c..d52a80e 100644 --- a/test/psych/test_engine_manager.rb +++ b/test/psych/test_engine_manager.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' require 'yaml' module Psych diff --git a/test/psych/test_exception.rb b/test/psych/test_exception.rb index 7d08ad1..806c5e2 100644 --- a/test/psych/test_exception.rb +++ b/test/psych/test_exception.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestException < TestCase diff --git a/test/psych/test_hash.rb b/test/psych/test_hash.rb index e682ab2..3147076 100644 --- a/test/psych/test_hash.rb +++ b/test/psych/test_hash.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestHash < TestCase diff --git a/test/psych/test_json_tree.rb b/test/psych/test_json_tree.rb index b694560..fefa1f5 100644 --- a/test/psych/test_json_tree.rb +++ b/test/psych/test_json_tree.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestJSONTree < TestCase diff --git a/test/psych/test_merge_keys.rb b/test/psych/test_merge_keys.rb index fef8892..b3ebe9b 100644 --- a/test/psych/test_merge_keys.rb +++ b/test/psych/test_merge_keys.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestMergeKeys < TestCase diff --git a/test/psych/test_nil.rb b/test/psych/test_nil.rb index e63c6c7..9b54a03 100644 --- a/test/psych/test_nil.rb +++ b/test/psych/test_nil.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestNil < TestCase diff --git a/test/psych/test_null.rb b/test/psych/test_null.rb index e953515..1ebf644 100644 --- a/test/psych/test_null.rb +++ b/test/psych/test_null.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych ### diff --git a/test/psych/test_object.rb b/test/psych/test_object.rb index 930f31f..9890d50 100644 --- a/test/psych/test_object.rb +++ b/test/psych/test_object.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class Tagged diff --git a/test/psych/test_omap.rb b/test/psych/test_omap.rb index f2f36d1..53f55f5 100644 --- a/test/psych/test_omap.rb +++ b/test/psych/test_omap.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestOmap < TestCase diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb index a60a0c6..decb241 100644 --- a/test/psych/test_parser.rb +++ b/test/psych/test_parser.rb @@ -1,6 +1,6 @@ # coding: utf-8 -require_relative 'helper' +require 'psych/helper' module Psych class TestParser < TestCase diff --git a/test/psych/test_psych.rb b/test/psych/test_psych.rb index 81fcccc..f59af46 100644 --- a/test/psych/test_psych.rb +++ b/test/psych/test_psych.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' require 'stringio' require 'tempfile' diff --git a/test/psych/test_scalar.rb b/test/psych/test_scalar.rb index e6b7697..3cf6b09 100644 --- a/test/psych/test_scalar.rb +++ b/test/psych/test_scalar.rb @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -require_relative 'helper' +require 'psych/helper' module Psych class TestScalar < TestCase diff --git a/test/psych/test_scalar_scanner.rb b/test/psych/test_scalar_scanner.rb index df54eb1..6599099 100644 --- a/test/psych/test_scalar_scanner.rb +++ b/test/psych/test_scalar_scanner.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestScalarScanner < TestCase diff --git a/test/psych/test_serialize_subclasses.rb b/test/psych/test_serialize_subclasses.rb index f597b7a..c822192 100644 --- a/test/psych/test_serialize_subclasses.rb +++ b/test/psych/test_serialize_subclasses.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestSerializeSubclasses < TestCase diff --git a/test/psych/test_set.rb b/test/psych/test_set.rb index 921fe22..bea67d9 100644 --- a/test/psych/test_set.rb +++ b/test/psych/test_set.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestSet < TestCase diff --git a/test/psych/test_stream.rb b/test/psych/test_stream.rb index 7e2f996..4d8f137 100644 --- a/test/psych/test_stream.rb +++ b/test/psych/test_stream.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestStream < TestCase diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index 1addc9f..96d77e0 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestString < TestCase diff --git a/test/psych/test_struct.rb b/test/psych/test_struct.rb index 5c6e9b8..42c4e11 100644 --- a/test/psych/test_struct.rb +++ b/test/psych/test_struct.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' class PsychStructWithIvar < Struct.new(:foo) attr_reader :bar diff --git a/test/psych/test_symbol.rb b/test/psych/test_symbol.rb index 2b4470d..3226141 100644 --- a/test/psych/test_symbol.rb +++ b/test/psych/test_symbol.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestSymbol < TestCase diff --git a/test/psych/test_to_yaml_properties.rb b/test/psych/test_to_yaml_properties.rb index 5b4860c..2636bec 100644 --- a/test/psych/test_to_yaml_properties.rb +++ b/test/psych/test_to_yaml_properties.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestToYamlProperties < MiniTest::Unit::TestCase diff --git a/test/psych/test_tree_builder.rb b/test/psych/test_tree_builder.rb index 7ad3ddd..9a134d5 100644 --- a/test/psych/test_tree_builder.rb +++ b/test/psych/test_tree_builder.rb @@ -1,4 +1,4 @@ -require_relative 'helper' +require 'psych/helper' module Psych class TestTreeBuilder < TestCase diff --git a/test/psych/test_yaml.rb b/test/psych/test_yaml.rb index 20bf26e..5c2f6dc 100644 --- a/test/psych/test_yaml.rb +++ b/test/psych/test_yaml.rb @@ -2,7 +2,7 @@ # vim:sw=4:ts=4 # $Id$ # -require_relative 'helper' +require 'psych/helper' # [ruby-core:01946] module Psych_Tests diff --git a/test/psych/visitors/test_depth_first.rb b/test/psych/visitors/test_depth_first.rb index a84f5b6..837c8e8 100644 --- a/test/psych/visitors/test_depth_first.rb +++ b/test/psych/visitors/test_depth_first.rb @@ -1,4 +1,4 @@ -require_relative '../helper' +require 'psych/helper' module Psych module Visitors diff --git a/test/psych/visitors/test_emitter.rb b/test/psych/visitors/test_emitter.rb index 7847cea..de27b45 100644 --- a/test/psych/visitors/test_emitter.rb +++ b/test/psych/visitors/test_emitter.rb @@ -1,4 +1,4 @@ -require_relative '../helper' +require 'psych/helper' module Psych module Visitors diff --git a/test/psych/visitors/test_to_ruby.rb b/test/psych/visitors/test_to_ruby.rb index b5b8e14..5b0702c 100644 --- a/test/psych/visitors/test_to_ruby.rb +++ b/test/psych/visitors/test_to_ruby.rb @@ -1,4 +1,4 @@ -require_relative '../helper' +require 'psych/helper' module Psych module Visitors diff --git a/test/psych/visitors/test_yaml_tree.rb b/test/psych/visitors/test_yaml_tree.rb index ed89e78..df77563 100644 --- a/test/psych/visitors/test_yaml_tree.rb +++ b/test/psych/visitors/test_yaml_tree.rb @@ -1,4 +1,4 @@ -require_relative '../helper' +require 'psych/helper' module Psych module Visitors @@ -38,6 +38,12 @@ module Psych assert_equal s.foo, obj.foo end + def test_override_method + s = Struct.new(:method).new('override') + obj = Psych.load(Psych.dump(s)) + assert_equal s.method, obj.method + end + def test_exception ex = Exception.new 'foo' loaded = Psych.load(Psych.dump(ex)) |