Skip to content

Commit af08d92

Browse files
committed
Add test for warning about modifying chilled literal strings
1 parent 09cd312 commit af08d92

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

command_line/frozen_strings_spec.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,28 @@
4242
ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb")).chomp.should == "false"
4343
end
4444

45-
it "if file has no frozen_string_literal comment produce different mutable strings each time" do
46-
ruby_exe(fixture(__FILE__, "string_literal_raw.rb")).chomp.should == "frozen:false interned:false"
45+
context "if file has no frozen_string_literal comment" do
46+
it "produce different mutable strings each time" do
47+
ruby_exe(fixture(__FILE__, "string_literal_raw.rb")).chomp.should == "frozen:false interned:false"
48+
end
49+
50+
guard -> { ruby_version_is "3.4" and !"test".frozen? } do
51+
it "complain about modification of produced mutable strings" do
52+
-> { eval(<<~RUBY) }.should complain(/warning: literal string will be frozen in the future \(run with --debug-frozen-string-literal for more information\)/)
53+
"test" << "!"
54+
RUBY
55+
end
56+
57+
it "does not complain about modification if Warning[:deprecated] is false" do
58+
deprecated = Warning[:deprecated]
59+
Warning[:deprecated] = false
60+
-> { eval(<<~RUBY) }.should_not complain
61+
"test" << "!"
62+
RUBY
63+
ensure
64+
Warning[:deprecated] = deprecated
65+
end
66+
end
4767
end
4868

4969
it "if file has frozen_string_literal:true comment produce same frozen strings each time" do

0 commit comments

Comments
 (0)