spec icon indicating copy to clipboard operation
spec copied to clipboard

Make the spec suite compatible with `--enable-frozen-string-literal`

Open casperisfine opened this issue 1 year ago • 1 comments

Extracted from: https://github.com/ruby/ruby/pull/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.

casperisfine avatar Mar 13 '24 18:03 casperisfine

Alright I think it's going green now.

For some specs like most of everything in core/string I just went with a # frozen_string_literal: false as many of these tests involved string mutation anyway, but for other parts I tried not to rely on it too much as to not "calcify" the spec suite, and properly test compatibility with --enable-frozen-string-literals.

The overwhelming majority of the diff is just some extra + or .dup.

casperisfine avatar Mar 13 '24 19:03 casperisfine

I made a separate PR to get a better diff for review: https://github.com/ruby/spec/pull/1143 @andrykonchin Could you take a look to get another pair of eyes on it?

I'll merge this PR because I went through like 99% of the diff so I think it's all correct, just maybe some extra + left. Maybe we should also remove more # frozen_string_literal: false to have a more consistent default in ruby/spec, although I already removed basically all except in String specs for mutable methods + a few extra specs which make more sense with false.

eregon avatar Mar 14 '24 16:03 eregon