From 97ecab7b34aaf58f472254356afcd3d529e57401 Mon Sep 17 00:00:00 2001 From: shirosaki Date: Thu, 22 Nov 2012 14:55:32 +0000 Subject: Fix cache validity check of require * array.c (rb_ary_shared_with_p): fix cache validity check. If #pop or #shift has been called against $: or $", the array will be still shared with the snapshot. We check array length for cache validity. [ruby-core:49518] [Bug #7383] * test/ruby/test_require.rb (TestRequire#test_require_with_array_pop, TestRequire#test_require_with_array_shift): add tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_require.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'test') diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index 36d7c788bf..d3cae1e01c 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -545,4 +545,35 @@ class TestRequire < Test::Unit::TestCase } } end + + def assert_require_with_shared_array_modified(add, del) + bug7383 = '[ruby-core:49518]' + Dir.mktmpdir {|tmp| + Dir.chdir(tmp) { + open("foo.rb", "w") {} + Dir.mkdir("a") + open(File.join("a", "bar.rb"), "w") {} + assert_in_out_err([], <<-INPUT, %w(:ok), [], bug7383) + $:.#{add} "#{tmp}" + $:.#{add} "#{tmp}/a" + require "foo" + $:.#{del} + # Expanded load path cache should be rebuilt. + begin + require "bar" + rescue LoadError + p :ok + end + INPUT + } + } + end + + def test_require_with_array_pop + assert_require_with_shared_array_modified("push", "pop") + end + + def test_require_with_array_shift + assert_require_with_shared_array_modified("unshift", "shift") + end end -- cgit v1.2.3