diff options
author | Jean Boussier <[email protected]> | 2024-03-13 12:50:11 +0100 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2024-03-14 17:56:15 +0100 |
commit | 09d8c99cdcb04fb6c6c8e61c9dea28927a3a0b46 (patch) | |
tree | 646ab40dec94c5bd405b485e62f00343cc50db72 /test/ruby | |
parent | 4e03d56e21e3df98a828c8efb7011b01db1a8d52 (diff) |
Ensure test suite is compatible with --frozen-string-literal
As preparation for https://bugs.ruby-lang.org/issues/20205
making sure the test suite is compatible with frozen string
literals is making things easier.
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/enc/test_case_mapping.rb | 10 | ||||
-rw-r--r-- | test/ruby/enc/test_case_options.rb | 12 | ||||
-rw-r--r-- | test/ruby/test_argf.rb | 26 | ||||
-rw-r--r-- | test/ruby/test_bignum.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_dir_m17n.rb | 40 | ||||
-rw-r--r-- | test/ruby/test_env.rb | 4 | ||||
-rw-r--r-- | test/ruby/test_gc_compact.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 4 | ||||
-rw-r--r-- | test/ruby/test_iseq.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_literal.rb | 10 | ||||
-rw-r--r-- | test/ruby/test_refinement.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_rubyoptions.rb | 5 | ||||
-rw-r--r-- | test/ruby/test_transcode.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_yjit.rb | 16 |
14 files changed, 71 insertions, 66 deletions
diff --git a/test/ruby/enc/test_case_mapping.rb b/test/ruby/enc/test_case_mapping.rb index 31acdc4331..a7d1ed0d16 100644 --- a/test/ruby/enc/test_case_mapping.rb +++ b/test/ruby/enc/test_case_mapping.rb @@ -47,7 +47,7 @@ class TestCaseMappingPreliminary < Test::Unit::TestCase # different properties; careful: roundtrip isn't always guaranteed def check_swapcase_properties(expected, start, *flags) assert_equal expected, start.swapcase(*flags) - temp = start + temp = +start assert_equal expected, temp.swapcase!(*flags) assert_equal start, start.swapcase(*flags).swapcase(*flags) assert_equal expected, expected.swapcase(*flags).swapcase(*flags) @@ -61,10 +61,10 @@ class TestCaseMappingPreliminary < Test::Unit::TestCase end def test_invalid - assert_raise(ArgumentError, "Should not be possible to upcase invalid string.") { "\xEB".force_encoding('UTF-8').upcase } - assert_raise(ArgumentError, "Should not be possible to downcase invalid string.") { "\xEB".force_encoding('UTF-8').downcase } - assert_raise(ArgumentError, "Should not be possible to capitalize invalid string.") { "\xEB".force_encoding('UTF-8').capitalize } - assert_raise(ArgumentError, "Should not be possible to swapcase invalid string.") { "\xEB".force_encoding('UTF-8').swapcase } + assert_raise(ArgumentError, "Should not be possible to upcase invalid string.") { "\xEB".dup.force_encoding('UTF-8').upcase } + assert_raise(ArgumentError, "Should not be possible to downcase invalid string.") { "\xEB".dup.force_encoding('UTF-8').downcase } + assert_raise(ArgumentError, "Should not be possible to capitalize invalid string.") { "\xEB".dup.force_encoding('UTF-8').capitalize } + assert_raise(ArgumentError, "Should not be possible to swapcase invalid string.") { "\xEB".dup.force_encoding('UTF-8').swapcase } end def test_general diff --git a/test/ruby/enc/test_case_options.rb b/test/ruby/enc/test_case_options.rb index e9bf50fcfc..40a85ee970 100644 --- a/test/ruby/enc/test_case_options.rb +++ b/test/ruby/enc/test_case_options.rb @@ -19,7 +19,7 @@ class TestCaseOptions < Test::Unit::TestCase def assert_raise_both_types(*options) assert_raise_functional_operations 'a', *options - assert_raise_bang_operations 'a', *options + assert_raise_bang_operations +'a', *options assert_raise_functional_operations :a, *options end @@ -51,7 +51,7 @@ class TestCaseOptions < Test::Unit::TestCase def assert_okay_both_types(*options) assert_okay_functional_operations 'a', *options - assert_okay_bang_operations 'a', *options + assert_okay_bang_operations +'a', *options assert_okay_functional_operations :a, *options end @@ -69,10 +69,10 @@ class TestCaseOptions < Test::Unit::TestCase assert_raise(ArgumentError) { 'a'.upcase :fold } assert_raise(ArgumentError) { 'a'.capitalize :fold } assert_raise(ArgumentError) { 'a'.swapcase :fold } - assert_nothing_raised { 'a'.downcase! :fold } - assert_raise(ArgumentError) { 'a'.upcase! :fold } - assert_raise(ArgumentError) { 'a'.capitalize! :fold } - assert_raise(ArgumentError) { 'a'.swapcase! :fold } + assert_nothing_raised { 'a'.dup.downcase! :fold } + assert_raise(ArgumentError) { 'a'.dup.upcase! :fold } + assert_raise(ArgumentError) { 'a'.dup.capitalize! :fold } + assert_raise(ArgumentError) { 'a'.dup.swapcase! :fold } assert_nothing_raised { :a.downcase :fold } assert_raise(ArgumentError) { :a.upcase :fold } assert_raise(ArgumentError) { :a.capitalize :fold } diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb index fed1bf88b4..39c5e88893 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -593,7 +593,7 @@ class TestArgf < Test::Unit::TestCase def test_read2 ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# - s = "" + s = +"" ARGF.read(8, s) p s }; @@ -604,7 +604,7 @@ class TestArgf < Test::Unit::TestCase def test_read2_with_not_empty_buffer ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# - s = "0123456789" + s = +"0123456789" ARGF.read(8, s) p s }; @@ -617,7 +617,7 @@ class TestArgf < Test::Unit::TestCase {# nil while ARGF.gets p ARGF.read - p ARGF.read(0, "") + p ARGF.read(0, +"") }; assert_equal("nil\n\"\"\n", f.read) end @@ -626,13 +626,13 @@ class TestArgf < Test::Unit::TestCase def test_readpartial ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# - s = "" + s = +"" begin loop do s << ARGF.readpartial(1) - t = ""; ARGF.readpartial(1, t); s << t + t = +""; ARGF.readpartial(1, t); s << t # not empty buffer - u = "abcdef"; ARGF.readpartial(1, u); s << u + u = +"abcdef"; ARGF.readpartial(1, u); s << u end rescue EOFError puts s @@ -645,11 +645,11 @@ class TestArgf < Test::Unit::TestCase def test_readpartial2 ruby('-e', "#{<<~"{#"}\n#{<<~'};'}") do |f| {# - s = "" + s = +"" begin loop do s << ARGF.readpartial(1) - t = ""; ARGF.readpartial(1, t); s << t + t = +""; ARGF.readpartial(1, t); s << t end rescue EOFError $stdout.binmode @@ -680,7 +680,7 @@ class TestArgf < Test::Unit::TestCase def test_getc ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# - s = "" + s = +"" while c = ARGF.getc s << c end @@ -706,7 +706,7 @@ class TestArgf < Test::Unit::TestCase def test_readchar ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# - s = "" + s = +"" begin while c = ARGF.readchar s << c @@ -784,7 +784,7 @@ class TestArgf < Test::Unit::TestCase def test_each_char ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# - s = "" + s = +"" ARGF.each_char {|c| s << c } puts s }; @@ -1073,7 +1073,7 @@ class TestArgf < Test::Unit::TestCase ruby('-e', "#{<<~"{#"}\n#{<<~'};'}") do |f| {# $stdout.sync = true - :wait_readable == ARGF.read_nonblock(1, "", exception: false) or + :wait_readable == ARGF.read_nonblock(1, +"", exception: false) or abort "did not return :wait_readable" begin @@ -1086,7 +1086,7 @@ class TestArgf < Test::Unit::TestCase IO.select([ARGF]) == [[ARGF], [], []] or abort 'did not awaken for readability (before byte)' - buf = '' + buf = +'' buf.object_id == ARGF.read_nonblock(1, buf).object_id or abort "read destination buffer failed" print buf diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb index 065a944853..1f882c6cb9 100644 --- a/test/ruby/test_bignum.rb +++ b/test/ruby/test_bignum.rb @@ -207,7 +207,7 @@ class TestBignum < Test::Unit::TestCase assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") begin; digits = [["3", 700], ["0", 2700], ["1", 1], ["0", 26599]] - num = digits.inject("") {|s,(c,n)|s << c*n}.to_i + num = digits.inject(+"") {|s,(c,n)|s << c*n}.to_i assert_equal digits.sum {|c,n|n}, num.to_s.size end; end diff --git a/test/ruby/test_dir_m17n.rb b/test/ruby/test_dir_m17n.rb index 67bad8a514..b4b1007d62 100644 --- a/test/ruby/test_dir_m17n.rb +++ b/test/ruby/test_dir_m17n.rb @@ -56,7 +56,7 @@ class TestDir_M17N < Test::Unit::TestCase return if Bug::File::Fs.fsname(Dir.tmpdir) == "apfs" with_tmpdir {|d| assert_separately(%w[-EASCII-8BIT], <<-'EOS', :chdir=>d) - filename = "\xff".force_encoding("ASCII-8BIT") # invalid byte sequence as UTF-8 + filename = "\xff".dup.force_encoding("ASCII-8BIT") # invalid byte sequence as UTF-8 File.open(filename, "w") {} opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) @@ -64,7 +64,7 @@ class TestDir_M17N < Test::Unit::TestCase assert_include(ents, filename) EOS assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d) - filename = "\xff".force_encoding("UTF-8") # invalid byte sequence as UTF-8 + filename = "\xff".dup.force_encoding("UTF-8") # invalid byte sequence as UTF-8 File.open(filename, "w") {} opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) @@ -77,7 +77,7 @@ class TestDir_M17N < Test::Unit::TestCase def test_filename_as_bytes_extutf8 with_tmpdir {|d| assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d) - filename = "\xc2\xa1".force_encoding("utf-8") + filename = "\xc2\xa1".dup.force_encoding("utf-8") File.open(filename, "w") {} opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) @@ -85,9 +85,9 @@ class TestDir_M17N < Test::Unit::TestCase EOS assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d) if /mswin|mingw|darwin/ =~ RUBY_PLATFORM - filename = "\x8f\xa2\xc2".force_encoding("euc-jp") + filename = "\x8f\xa2\xc2".dup.force_encoding("euc-jp") else - filename = "\xc2\xa1".force_encoding("euc-jp") + filename = "\xc2\xa1".dup.force_encoding("euc-jp") end assert_nothing_raised(Errno::ENOENT) do open(filename) {} @@ -96,8 +96,8 @@ class TestDir_M17N < Test::Unit::TestCase # no meaning test on windows unless /mswin|mingw|darwin/ =~ RUBY_PLATFORM assert_separately(%W[-EUTF-8], <<-'EOS', :chdir=>d) - filename1 = "\xc2\xa1".force_encoding("utf-8") - filename2 = "\xc2\xa1".force_encoding("euc-jp") + filename1 = "\xc2\xa1".dup.force_encoding("utf-8") + filename2 = "\xc2\xa1".dup.force_encoding("euc-jp") filename3 = filename1.encode("euc-jp") filename4 = filename2.encode("utf-8") assert_file.stat(filename1) @@ -121,13 +121,13 @@ class TestDir_M17N < Test::Unit::TestCase assert_include(ents, filename) EOS assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d) - filename = "\xA4\xA2".force_encoding("euc-jp") + filename = "\xA4\xA2".dup.force_encoding("euc-jp") opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) assert_include(ents, filename) EOS assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d) - filename = "\xA4\xA2".force_encoding("euc-jp") + filename = "\xA4\xA2".dup.force_encoding("euc-jp") assert_nothing_raised(Errno::ENOENT) do open(filename) {} end @@ -149,7 +149,7 @@ class TestDir_M17N < Test::Unit::TestCase EOS assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d) filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP - filename2 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP + filename2 = "\xA4\xA2".dup.force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) assert_include(ents, filename1) @@ -158,7 +158,7 @@ class TestDir_M17N < Test::Unit::TestCase assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d) filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP filename2 = "\u3042" # HIRAGANA LETTER A which is representable in EUC-JP - filename3 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP + filename3 = "\xA4\xA2".dup.force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP assert_file.stat(filename1) assert_file.stat(filename2) assert_file.stat(filename3) @@ -172,7 +172,7 @@ class TestDir_M17N < Test::Unit::TestCase return if /cygwin/ =~ RUBY_PLATFORM with_tmpdir {|d| assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d) - filename = "\xA4\xA2".force_encoding("euc-jp") + filename = "\xA4\xA2".dup.force_encoding("euc-jp") File.open(filename, "w") {} opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) @@ -189,7 +189,7 @@ class TestDir_M17N < Test::Unit::TestCase return if /cygwin/ =~ RUBY_PLATFORM with_tmpdir {|d| assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d) - filename = "\xA4\xA2".force_encoding("euc-jp") + filename = "\xA4\xA2".dup.force_encoding("euc-jp") File.open(filename, "w") {} ents = Dir.entries(".") if /darwin/ =~ RUBY_PLATFORM @@ -200,7 +200,7 @@ class TestDir_M17N < Test::Unit::TestCase assert_include(ents, filename) EOS assert_separately(%w[-EASCII-8BIT], <<-'EOS', :chdir=>d) - filename = "\xA4\xA2".force_encoding('ASCII-8BIT') + filename = "\xA4\xA2".dup.force_encoding('ASCII-8BIT') ents = Dir.entries(".") unless ents.include?(filename) case RUBY_PLATFORM @@ -231,7 +231,7 @@ class TestDir_M17N < Test::Unit::TestCase return if /cygwin/ =~ RUBY_PLATFORM with_tmpdir {|d| assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d) - filename = "\xA4\xA2".force_encoding("euc-jp") + filename = "\xA4\xA2".dup.force_encoding("euc-jp") File.open(filename, "w") {} opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) @@ -241,7 +241,7 @@ class TestDir_M17N < Test::Unit::TestCase assert_include(ents, filename) EOS assert_separately(%w[-EEUC-JP:UTF-8], <<-'EOS', :chdir=>d) - filename = "\u3042" + filename = "\u3042".dup opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) if /darwin/ =~ RUBY_PLATFORM @@ -350,7 +350,7 @@ class TestDir_M17N < Test::Unit::TestCase end def test_glob_escape_multibyte - name = "\x81\\".force_encoding(Encoding::Shift_JIS) + name = "\x81\\".dup.force_encoding(Encoding::Shift_JIS) with_tmpdir do open(name, "w") {} rescue next match, = Dir.glob("#{name}*") @@ -363,8 +363,8 @@ class TestDir_M17N < Test::Unit::TestCase with_tmpdir do list = %W"file_one.ext file_two.ext \u{6587 4ef6}1.txt \u{6587 4ef6}2.txt" list.each {|f| open(f, "w") {}} - a = "file_one*".force_encoding Encoding::IBM437 - b = "file_two*".force_encoding Encoding::EUC_JP + a = "file_one*".dup.force_encoding Encoding::IBM437 + b = "file_two*".dup.force_encoding Encoding::EUC_JP assert_equal([a, b].map(&:encoding), Dir[a, b].map(&:encoding)) if Bug::File::Fs.fsname(Dir.pwd) == "apfs" # High Sierra's APFS cannot use filenames with undefined character @@ -375,7 +375,7 @@ class TestDir_M17N < Test::Unit::TestCase Dir.mkdir(dir) list << dir bug12081 = '[ruby-core:73868] [Bug #12081]' - a = "*".force_encoding("us-ascii") + a = "*".dup.force_encoding("us-ascii") result = Dir[a].map {|n| if n.encoding == Encoding::ASCII_8BIT || n.encoding == Encoding::ISO_8859_1 || diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb index cdadeac148..4b5f18e7bb 100644 --- a/test/ruby/test_env.rb +++ b/test/ruby/test_env.rb @@ -612,8 +612,8 @@ class TestEnv < Test::Unit::TestCase <<-"end;" envvars_to_check = [ "foo\0bar", - "#{'\xa1\xa1'}".force_encoding(Encoding::UTF_16LE), - "foo".force_encoding(Encoding::ISO_2022_JP), + "#{'\xa1\xa1'}".dup.force_encoding(Encoding::UTF_16LE), + "foo".dup.force_encoding(Encoding::ISO_2022_JP), ] envvars_to_check.each do |#{var_name}| #{str_for_yielding_exception_class(code_str)} diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb index adf82620f3..f47c0b046b 100644 --- a/test/ruby/test_gc_compact.rb +++ b/test/ruby/test_gc_compact.rb @@ -372,7 +372,7 @@ class TestGCCompact < Test::Unit::TestCase Fiber.new { str = "a" * GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE] * 4 - $ary = STR_COUNT.times.map { "" << str } + $ary = STR_COUNT.times.map { +"" << str } }.resume stats = GC.verify_compaction_references(expand_heap: true, toward: :empty) diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index f9312e1c3f..f60ba0cffd 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1963,14 +1963,14 @@ class TestHashOnly < Test::Unit::TestCase end def test_AREF_fstring_key_default_proc - assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + assert_separately(['--disable-frozen-string-literal'], "#{<<~"begin;"}\n#{<<~'end;'}") begin; h = Hash.new do |h, k| k.frozen? end str = "foo" - refute str.frozen? # assumes this file is frozen_string_literal: false + refute str.frozen? refute h[str] refute h["foo"] end; diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index ebb28af116..dc84d8bd7c 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -168,7 +168,7 @@ class TestISeq < Test::Unit::TestCase end def test_disasm_encoding - src = "\u{3042} = 1; \u{3042}; \u{3043}" + src = +"\u{3042} = 1; \u{3042}; \u{3043}" asm = compile(src).disasm assert_equal(src.encoding, asm.encoding) assert_predicate(asm, :valid_encoding?) diff --git a/test/ruby/test_literal.rb b/test/ruby/test_literal.rb index 72dcce04e1..61e1e096df 100644 --- a/test/ruby/test_literal.rb +++ b/test/ruby/test_literal.rb @@ -142,6 +142,8 @@ class TestRubyLiteral < Test::Unit::TestCase end def test_frozen_string + default = eval("'test'").frozen? + all_assertions do |a| a.for("false with indicator") do str = eval("# -*- frozen-string-literal: false -*-\n""'foo'") @@ -161,19 +163,19 @@ class TestRubyLiteral < Test::Unit::TestCase end a.for("false with preceding garbage") do str = eval("# x frozen-string-literal: false\n""'foo'") - assert_not_predicate(str, :frozen?) + assert_equal(default, str.frozen?) end a.for("true with preceding garbage") do str = eval("# x frozen-string-literal: true\n""'foo'") - assert_not_predicate(str, :frozen?) + assert_equal(default, str.frozen?) end a.for("false with succeeding garbage") do str = eval("# frozen-string-literal: false x\n""'foo'") - assert_not_predicate(str, :frozen?) + assert_equal(default, str.frozen?) end a.for("true with succeeding garbage") do str = eval("# frozen-string-literal: true x\n""'foo'") - assert_not_predicate(str, :frozen?) + assert_equal(default, str.frozen?) end end end diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 4fb23d1b54..11acf31f21 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -1044,7 +1044,7 @@ class TestRefinement < Test::Unit::TestCase end using Test def t - 'Refinements are broken!'.chop! + 'Refinements are broken!'.dup.chop! end t module Test diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 29810d5dd7..446548d6d9 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -1196,13 +1196,16 @@ class TestRubyOptions < Test::Unit::TestCase end def test_frozen_string_literal_debug + default_frozen = eval("'test'").frozen? + with_debug_pat = /created at/ wo_debug_pat = /can\'t modify frozen String: "\w+" \(FrozenError\)\n\z/ frozen = [ ["--enable-frozen-string-literal", true], ["--disable-frozen-string-literal", false], - [nil, false], ] + frozen << [nil, false] unless default_frozen + debugs = [ ["--debug-frozen-string-literal", true], ["--debug=frozen-string-literal", true], diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb index 4b63263aae..ceef19e7ea 100644 --- a/test/ruby/test_transcode.rb +++ b/test/ruby/test_transcode.rb @@ -2265,7 +2265,7 @@ class TestTranscode < Test::Unit::TestCase result = th.map(&:value) end end - expected = "\xa4\xa2".force_encoding(Encoding::EUC_JP) + expected = "\xa4\xa2".dup.force_encoding(Encoding::EUC_JP) assert_equal([expected]*num, result, bug11277) end; end diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb index 67e684656d..df71dbffc0 100644 --- a/test/ruby/test_yjit.rb +++ b/test/ruby/test_yjit.rb @@ -320,10 +320,10 @@ class TestYJIT < Test::Unit::TestCase end def test_compile_opt_aset - assert_compiles('[1,2,3][2] = 4', insns: %i[opt_aset]) - assert_compiles('{}[:foo] = :bar', insns: %i[opt_aset]) - assert_compiles('[1,2,3][0..-1] = []', insns: %i[opt_aset]) - assert_compiles('"foo"[3] = "d"', insns: %i[opt_aset]) + assert_compiles('[1,2,3][2] = 4', insns: %i[opt_aset], frozen_string_literal: false) + assert_compiles('{}[:foo] = :bar', insns: %i[opt_aset], frozen_string_literal: false) + assert_compiles('[1,2,3][0..-1] = []', insns: %i[opt_aset], frozen_string_literal: false) + assert_compiles('"foo"[3] = "d"', insns: %i[opt_aset], frozen_string_literal: false) end def test_compile_attr_set @@ -1471,8 +1471,8 @@ class TestYJIT < Test::Unit::TestCase end h = Hash.new { nil } - foo("\x80".b, "\xA1A1".force_encoding("EUC-JP"), h) - foo("\x80".b, "\xA1A1".force_encoding("EUC-JP"), h) + foo("\x80".b, "\xA1A1".dup.force_encoding("EUC-JP"), h) + foo("\x80".b, "\xA1A1".dup.force_encoding("EUC-JP"), h) RUBY end @@ -1489,7 +1489,7 @@ class TestYJIT < Test::Unit::TestCase end def test_opt_aref_with - assert_compiles(<<~RUBY, insns: %i[opt_aref_with], result: "bar") + assert_compiles(<<~RUBY, insns: %i[opt_aref_with], result: "bar", frozen_string_literal: false) h = {"foo" => "bar"} h["foo"] @@ -1671,7 +1671,7 @@ class TestYJIT < Test::Unit::TestCase RUBY script = <<~RUBY - #{"# frozen_string_literal: true" if frozen_string_literal} + #{"# frozen_string_literal: " + frozen_string_literal.to_s unless frozen_string_literal.nil?} _test_proc = -> { #{test_script} } |