Skip to content

Commit

Permalink
Make the test suite compatible with --enable-frozen-string-literal
Browse files Browse the repository at this point in the history
Ref: https://bugs.ruby-lang.org/issues/20205
Ref: voxpupuli/json-schema#508

Since `rbs` is tested as part of ruby-core CI, it needs to be compatible
with the `--enable-frozen-string-literal` option.
  • Loading branch information
byroot committed Mar 15, 2024
1 parent c3e4171 commit 9fb3f79
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ jobs:
fail-fast: false
matrix:
ruby: ['3.0', '3.1', '3.2', '3.3', head]
rubyopt: [""]
job:
- test
include:
- ruby: head
job: stdlib_test rubocop
- ruby: "3.3"
job: stdlib_test
- ruby: "3.3"
job: test
rubyopt: "--enable-frozen-string-literal"
- ruby: "3.3"
job: stdlib_test
rubyopt: "--enable-frozen-string-literal"
- ruby: "3.3"
job: lexer compile confirm_lexer
- ruby: "3.3"
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ GEM
remote: https://rubygems.org/
specs:
abbrev (0.1.2)
addressable (2.8.5)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
base64 (0.2.0)
Expand All @@ -29,7 +29,7 @@ GEM
rainbow (>= 3.0, < 4.0)
strong_json (>= 1.1, < 2.2)
json (2.7.1)
json-schema (4.1.1)
json-schema (4.2.0)
addressable (>= 2.8)
language_server-protocol (3.17.0.3)
marcel (1.0.2)
Expand All @@ -47,7 +47,7 @@ GEM
power_assert (2.0.3)
psych (4.0.6)
stringio
public_suffix (5.0.3)
public_suffix (5.0.4)
racc (1.7.3)
rainbow (3.1.1)
rake (13.1.0)
Expand Down
6 changes: 3 additions & 3 deletions test/stdlib/ARGF_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def test_read
assert_send_type "(::int length) -> ::String",
ARGF.class.new(__FILE__), :read, 1
assert_send_type "(::int length, ::string outbuf) -> ::String",
ARGF.class.new(__FILE__), :read, 1, ""
ARGF.class.new(__FILE__), :read, 1, +""
assert_send_type "(::int length) -> nil",
ARGF.class.new(Tempfile.new), :read, 1
end
Expand All @@ -272,7 +272,7 @@ def test_read_nonblock
assert_send_type "(::int maxlen) -> ::String",
ARGF.class.new(__FILE__), :read_nonblock, 1
assert_send_type "(::int maxlen, ::string buf) -> ::String",
ARGF.class.new(__FILE__), :read_nonblock, 1, ""
ARGF.class.new(__FILE__), :read_nonblock, 1, +""
end

def test_readbyte
Expand All @@ -289,7 +289,7 @@ def test_readpartial
assert_send_type "(::int maxlen) -> ::String",
ARGF.class.new(__FILE__), :readpartial, 1
assert_send_type "(::int maxlen, ::string buf) -> ::String",
ARGF.class.new(__FILE__), :readpartial, 1, ""
ARGF.class.new(__FILE__), :readpartial, 1, +""
end

def test_rewind
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib/Array_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def test_pack
[1,2,3], :pack, ToStr.new("ccc")

assert_send_type "(String, buffer: String) -> String",
[1,2,3], :pack, "ccc", buffer: ""
[1,2,3], :pack, "ccc", buffer: +""
assert_send_type "(String, buffer: nil) -> String",
[1,2,3], :pack, "ccc", buffer: nil
refute_send_type "(ToStr, buffer: ToStr) -> String",
Expand Down
4 changes: 2 additions & 2 deletions test/stdlib/Encoding_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_source_encoding_name

def error_object
ec = Encoding::Converter.new('UTF-8', 'ISO-8859-1')
ec.primitive_convert("\xf1abcd", '')
ec.primitive_convert(+"\xf1abcd", +'')
ec.last_error
end
end
Expand Down Expand Up @@ -271,7 +271,7 @@ def test_source_encoding_name

def error_object
ec = Encoding::Converter.new('EUC-JP', 'ISO-8859-1')
ec.primitive_convert("\xa4\xa2", '')
ec.primitive_convert(+"\xa4\xa2", +'')
ec.last_error
end
end
2 changes: 1 addition & 1 deletion test/stdlib/Enumerable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def test_grepv
end

def test_inject
assert_send_type "(String init, Symbol method) -> untyped", TestEnumerable.new, :inject, '', :<<
assert_send_type "(String init, Symbol method) -> untyped", TestEnumerable.new, :inject, +'', :<<
assert_send_type "(Symbol method) -> String", TestEnumerable.new, :inject, :+
assert_send_type("(Integer initial) { (Integer, String) -> Integer } -> Integer", TestEnumerable.new, :inject, 0) do |memo, item|
memo ^ item.hash
Expand Down
8 changes: 4 additions & 4 deletions test/stdlib/IO_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ def test_read
assert_send_type "(nil) -> String",
io, :read, nil
assert_send_type "(Integer, String) -> String",
io, :read, 0, "buffer"
io, :read, 0, +"buffer"
assert_send_type "(Integer, String) -> nil",
io, :read, 1, "buffer"
io, :read, 1, +"buffer"
assert_send_type "(nil, String) -> String",
io, :read, nil, "buffer"
io, :read, nil, +"buffer"
end
end

Expand All @@ -275,7 +275,7 @@ def test_readpartial
assert_send_type "(Integer) -> String",
io, :readpartial, 10
assert_send_type "(Integer, String) -> String",
io, :readpartial, 10, "buffer"
io, :readpartial, 10, +"buffer"
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/stdlib/ObjectSpace_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def test_count_objects

def test_define_finalizer
assert_send_type "(top, ^(Integer) -> void) -> [Integer, Proc]",
ObjectSpace, :define_finalizer, "abc", ->(id) { "id: #{id}" }
ObjectSpace, :define_finalizer, +"abc", ->(id) { "id: #{id}" }
assert_send_type "(top) { (Integer) -> void } -> [Integer, Proc]",
ObjectSpace, :define_finalizer, "abc" do |id| "id: #{id}" end
ObjectSpace, :define_finalizer, +"abc" do |id| "id: #{id}" end
end

def test_each_object
Expand Down Expand Up @@ -53,7 +53,7 @@ def test_garbage_collect

def test_undefine_finalizer
assert_send_type "(String) -> String",
ObjectSpace, :undefine_finalizer, "abc"
ObjectSpace, :undefine_finalizer, +"abc"
assert_send_type "(Array) -> Array",
ObjectSpace, :undefine_finalizer, []
end
Expand Down
4 changes: 2 additions & 2 deletions test/stdlib/StringIO_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def test_closed_read?
end

def test_close_write
io = StringIO.new('example')
io = StringIO.new(+'example')
io.close_write
end

def test_closed_write?
io = StringIO.new('example')
io = StringIO.new(+'example')
io.closed_write?
io.close_write
io.closed_write?
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/String_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: false
require_relative 'test_helper'

# TODO: encode, encode!, byteslice
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Writer
attr_reader :buffer

def initialize
@buffer = ""
@buffer = +""
end

def write(*vals)
Expand Down

0 comments on commit 9fb3f79

Please sign in to comment.