Skip to content

Commit 028bc68

Browse files
byrooteregon
andcommitted
Make the spec suite compatible with --enable-frozen-string-literal
Extracted from: ruby/ruby#10235 Ref: https://bugs.ruby-lang.org/issues/20205 Ruby will gradually move towards enabling frozen string literals by default. Making the ruby spec suite compatible is a good first step. Co-authored-by: Benoit Daloze <[email protected]>
1 parent f23d158 commit 028bc68

File tree

210 files changed

+753
-689
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+753
-689
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ jobs:
1010
matrix:
1111
os: [ ubuntu, macos, windows ]
1212
ruby: [ 3.0.6, 3.1.4, 3.2.2, 3.3.0 ]
13+
rubyopt: [""]
14+
include:
15+
- os: ubuntu
16+
ruby: 3.3.0
17+
rubyopt: "--enable-frozen-string-literal"
18+
1319
runs-on: ${{ matrix.os }}-latest
1420
steps:
1521
- name: git config autocrlf
@@ -28,6 +34,7 @@ jobs:
2834
if: matrix.os == 'ubuntu'
2935
env:
3036
CHECK_LEAKS: true
37+
RUBYOPT: "${{ matrix.rubyopt }}"
3138
run: ../mspec/bin/mspec -j --timeout 30
3239

3340
- name: Run specs (macOS)

core/argf/readpartial_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
it "clears output buffer even if EOFError is raised because @argf is at end" do
3131
begin
32-
output = "to be cleared"
32+
output = +"to be cleared"
3333

3434
argf [@file1_name] do
3535
@argf.read

core/argf/shared/getc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
it "reads each char of files" do
1111
argf [@file1, @file2] do
12-
chars = ""
12+
chars = +""
1313
@chars.size.times { chars << @argf.send(@method) }
1414
chars.should == @chars
1515
end

core/argf/shared/read.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
it "treats second argument as an output buffer" do
1717
argf [@file1_name] do
18-
buffer = ""
18+
buffer = +""
1919
@argf.send(@method, @file1.size, buffer)
2020
buffer.should == @file1
2121
end
2222
end
2323

2424
it "clears output buffer before appending to it" do
2525
argf [@file1_name] do
26-
buffer = "to be cleared"
26+
buffer = +"to be cleared"
2727
@argf.send(@method, @file1.size, buffer)
2828
buffer.should == @file1
2929
end

core/array/fill_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
it "does not replicate the filler" do
2323
ary = [1, 2, 3, 4]
24-
str = "x"
24+
str = +"x"
2525
ary.fill(str).should == [str, str, str, str]
2626
str << "y"
2727
ary.should == [str, str, str, str]

core/array/fixtures/encoded_strings.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,36 @@
22
module ArraySpecs
33
def self.array_with_usascii_and_7bit_utf8_strings
44
[
5-
'foo'.force_encoding('US-ASCII'),
5+
'foo'.dup.force_encoding('US-ASCII'),
66
'bar'
77
]
88
end
99

1010
def self.array_with_usascii_and_utf8_strings
1111
[
12-
'foo'.force_encoding('US-ASCII'),
12+
'foo'.dup.force_encoding('US-ASCII'),
1313
'báz'
1414
]
1515
end
1616

1717
def self.array_with_7bit_utf8_and_usascii_strings
1818
[
1919
'bar',
20-
'foo'.force_encoding('US-ASCII')
20+
'foo'.dup.force_encoding('US-ASCII')
2121
]
2222
end
2323

2424
def self.array_with_utf8_and_usascii_strings
2525
[
2626
'báz',
2727
'bar',
28-
'foo'.force_encoding('US-ASCII')
28+
'foo'.dup.force_encoding('US-ASCII')
2929
]
3030
end
3131

3232
def self.array_with_usascii_and_utf8_strings
3333
[
34-
'foo'.force_encoding('US-ASCII'),
34+
'foo'.dup.force_encoding('US-ASCII'),
3535
'bar',
3636
'báz'
3737
]
@@ -41,7 +41,7 @@ def self.array_with_utf8_and_7bit_binary_strings
4141
[
4242
'bar',
4343
'báz',
44-
'foo'.force_encoding('BINARY')
44+
'foo'.dup.force_encoding('BINARY')
4545
]
4646
end
4747

@@ -55,14 +55,14 @@ def self.array_with_utf8_and_binary_strings
5555

5656
def self.array_with_usascii_and_7bit_binary_strings
5757
[
58-
'bar'.force_encoding('US-ASCII'),
59-
'foo'.force_encoding('BINARY')
58+
'bar'.dup.force_encoding('US-ASCII'),
59+
'foo'.dup.force_encoding('BINARY')
6060
]
6161
end
6262

6363
def self.array_with_usascii_and_binary_strings
6464
[
65-
'bar'.force_encoding('US-ASCII'),
65+
'bar'.dup.force_encoding('US-ASCII'),
6666
[255].pack('C').force_encoding('BINARY')
6767
]
6868
end

core/array/pack/buffer_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
it "adds result at the end of buffer content" do
1414
n = [ 65, 66, 67 ] # result without buffer is "ABC"
1515

16-
buffer = ""
16+
buffer = +""
1717
n.pack("ccc", buffer: buffer).should == "ABC"
1818

19-
buffer = "123"
19+
buffer = +"123"
2020
n.pack("ccc", buffer: buffer).should == "123ABC"
2121

22-
buffer = "12345"
22+
buffer = +"12345"
2323
n.pack("ccc", buffer: buffer).should == "12345ABC"
2424
end
2525

@@ -31,19 +31,19 @@
3131
context "offset (@) is specified" do
3232
it 'keeps buffer content if it is longer than offset' do
3333
n = [ 65, 66, 67 ]
34-
buffer = "123456"
34+
buffer = +"123456"
3535
n.pack("@3ccc", buffer: buffer).should == "123ABC"
3636
end
3737

3838
it "fills the gap with \\0 if buffer content is shorter than offset" do
3939
n = [ 65, 66, 67 ]
40-
buffer = "123"
40+
buffer = +"123"
4141
n.pack("@6ccc", buffer: buffer).should == "123\0\0\0ABC"
4242
end
4343

4444
it 'does not keep buffer content if it is longer than offset + result' do
4545
n = [ 65, 66, 67 ]
46-
buffer = "1234567890"
46+
buffer = +"1234567890"
4747
n.pack("@3ccc", buffer: buffer).should == "123ABC"
4848
end
4949
end

core/array/pack/shared/string.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
f = pack_format("*")
4141
[ [["\u{3042 3044 3046 3048}", 0x2000B].pack(f+"U"), Encoding::BINARY],
4242
[["abcde\xd1", "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY],
43-
[["a".force_encoding("ascii"), "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY],
43+
[["a".dup.force_encoding("ascii"), "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY],
4444
# under discussion [ruby-dev:37294]
4545
[["\u{3042 3044 3046 3048}", 1].pack(f+"N"), Encoding::BINARY]
4646
].should be_computed_by(:encoding)

core/array/shared/inspect.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
end
2020

2121
it "does not call #to_s on a String returned from #inspect" do
22-
str = "abc"
22+
str = +"abc"
2323
str.should_not_receive(:to_s)
2424

2525
[str].send(@method).should == '["abc"]'
@@ -98,8 +98,8 @@
9898
end
9999

100100
it "does not raise if inspected result is not default external encoding" do
101-
utf_16be = mock("utf_16be")
102-
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
101+
utf_16be = mock(+"utf_16be")
102+
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode(Encoding::UTF_16BE))
103103

104104
[utf_16be].send(@method).should == '["utf_16be \u3042"]'
105105
end

core/complex/inspect_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
it "calls #inspect on real and imaginary" do
1919
real = NumericSpecs::Subclass.new
20-
real.should_receive(:inspect).and_return("1")
20+
# + because of https://bugs.ruby-lang.org/issues/20337
21+
real.should_receive(:inspect).and_return(+"1")
2122
imaginary = NumericSpecs::Subclass.new
2223
imaginary.should_receive(:inspect).and_return("2")
2324
imaginary.should_receive(:<).any_number_of_times.and_return(false)
@@ -26,7 +27,8 @@
2627

2728
it "adds an `*' before the `i' if the last character of the imaginary part is not numeric" do
2829
real = NumericSpecs::Subclass.new
29-
real.should_receive(:inspect).and_return("(1)")
30+
# + because of https://bugs.ruby-lang.org/issues/20337
31+
real.should_receive(:inspect).and_return(+"(1)")
3032
imaginary = NumericSpecs::Subclass.new
3133
imaginary.should_receive(:inspect).and_return("(2)")
3234
imaginary.should_receive(:<).any_number_of_times.and_return(false)

0 commit comments

Comments
 (0)