ruby / spec

The Ruby Spec Suite aka ruby/spec
MIT License
588 stars 384 forks source link

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

Closed casperisfine closed 4 months ago

casperisfine commented 4 months ago

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 commented 4 months ago

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.

eregon commented 4 months ago

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.