From 42c5f9ee7b5f2627ce4e4cd836e98bf65c6bb733 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Fri, 15 Mar 2024 09:35:12 +0100 Subject: [PATCH] Make the test suite compatible with `--enable-frozen-string-literal` Ref: https://bugs.ruby-lang.org/issues/20205 Ref: https://github.com/voxpupuli/json-schema/pull/508 Since `rbs` is tested as part of ruby-core CI, it needs to be compatible with the `--enable-frozen-string-literal` option. --- .github/workflows/ruby.yml | 7 +++++++ Gemfile | 2 +- Gemfile.lock | 15 ++++++++++----- test/stdlib/ARGF_test.rb | 6 +++--- test/stdlib/Array_test.rb | 2 +- test/stdlib/Encoding_test.rb | 4 ++-- test/stdlib/Enumerable_test.rb | 2 +- test/stdlib/IO_test.rb | 8 ++++---- test/stdlib/ObjectSpace_test.rb | 6 +++--- test/stdlib/StringIO_test.rb | 4 ++-- test/stdlib/String_test.rb | 1 + test/stdlib/test_helper.rb | 2 +- 12 files changed, 36 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 9f2ad2c15..3bd5e606f 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -14,6 +14,7 @@ jobs: fail-fast: false matrix: ruby: ['3.0', '3.1', '3.2', '3.3', head] + rubyopt: [""] job: - test include: @@ -21,6 +22,12 @@ jobs: 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" diff --git a/Gemfile b/Gemfile index 18d07a259..b59d45750 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ gem "rspec" gem "rubocop" gem "rubocop-rubycw" gem "json" -gem "json-schema" +gem "json-schema", github: "voxpupuli/json-schema" gem 'stackprof' gem "goodcheck" gem "dbm" diff --git a/Gemfile.lock b/Gemfile.lock index 7d2f6ae43..640a927c1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: https://github.com/voxpupuli/json-schema.git + revision: 7e4c49a86cc2f88d24de1c8040dcfc22009fc21c + specs: + json-schema (4.1.1) + addressable (>= 2.8) + PATH remote: . specs: @@ -13,7 +20,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) @@ -29,8 +36,6 @@ GEM rainbow (>= 3.0, < 4.0) strong_json (>= 1.1, < 2.2) json (2.7.1) - json-schema (4.1.1) - addressable (>= 2.8) language_server-protocol (3.17.0.3) marcel (1.0.2) minitest (5.22.2) @@ -47,7 +52,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) @@ -109,7 +114,7 @@ DEPENDENCIES fileutils goodcheck json - json-schema + json-schema! minitest mutex_m net-smtp diff --git a/test/stdlib/ARGF_test.rb b/test/stdlib/ARGF_test.rb index bc9f2a92a..dc7c3a8c9 100644 --- a/test/stdlib/ARGF_test.rb +++ b/test/stdlib/ARGF_test.rb @@ -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 @@ -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 @@ -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 diff --git a/test/stdlib/Array_test.rb b/test/stdlib/Array_test.rb index 0dbc7abc2..4c2342d68 100644 --- a/test/stdlib/Array_test.rb +++ b/test/stdlib/Array_test.rb @@ -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", diff --git a/test/stdlib/Encoding_test.rb b/test/stdlib/Encoding_test.rb index 030dc2f29..27faf8b27 100644 --- a/test/stdlib/Encoding_test.rb +++ b/test/stdlib/Encoding_test.rb @@ -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 @@ -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 diff --git a/test/stdlib/Enumerable_test.rb b/test/stdlib/Enumerable_test.rb index 76d1d8520..83f5aad91 100644 --- a/test/stdlib/Enumerable_test.rb +++ b/test/stdlib/Enumerable_test.rb @@ -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 diff --git a/test/stdlib/IO_test.rb b/test/stdlib/IO_test.rb index 371d7695f..e68894151 100644 --- a/test/stdlib/IO_test.rb +++ b/test/stdlib/IO_test.rb @@ -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 @@ -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 diff --git a/test/stdlib/ObjectSpace_test.rb b/test/stdlib/ObjectSpace_test.rb index 3ae6be4c0..fd16696cb 100644 --- a/test/stdlib/ObjectSpace_test.rb +++ b/test/stdlib/ObjectSpace_test.rb @@ -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 @@ -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 diff --git a/test/stdlib/StringIO_test.rb b/test/stdlib/StringIO_test.rb index 72881bfab..a66a3664f 100644 --- a/test/stdlib/StringIO_test.rb +++ b/test/stdlib/StringIO_test.rb @@ -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? diff --git a/test/stdlib/String_test.rb b/test/stdlib/String_test.rb index a3338e89a..dcc4ec74d 100644 --- a/test/stdlib/String_test.rb +++ b/test/stdlib/String_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative 'test_helper' # TODO: encode, encode!, byteslice diff --git a/test/stdlib/test_helper.rb b/test/stdlib/test_helper.rb index 1f23d3478..30240312a 100644 --- a/test/stdlib/test_helper.rb +++ b/test/stdlib/test_helper.rb @@ -85,7 +85,7 @@ class Writer attr_reader :buffer def initialize - @buffer = "" + @buffer = +"" end def write(*vals)