From b8c79f5ce6b37f13ab95f6635fb96655c7118ae4 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Mon, 18 Mar 2024 09:22:46 +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 `typeprof` is tested as part of ruby-core CI, it needs to be compatible with the `--enable-frozen-string-literal` option. --- .github/workflows/main.yml | 5 ++++- lib/typeprof/type.rb | 4 ++-- test/typeprof/cli_test.rb | 6 +++--- test/typeprof/test_helper.rb | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 07afb5207..797df826b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,6 +22,9 @@ jobs: fail-fast: false matrix: ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }} + include: + - ruby-version: 3.3 + rubyopt: "--enable-frozen-string-literal" runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -35,5 +38,5 @@ jobs: - run: bundle exec typeprof --version - name: Run the test suite run: | - bundle exec rake TESTOPT=-v + bundle exec rake TESTOPT=-v RUBYOPT="${{ matrix.rubyopt }}" if: ${{ !startsWith(matrix.ruby, 'truffle') }} diff --git a/lib/typeprof/type.rb b/lib/typeprof/type.rb index aada65b8b..c6d9c16b6 100644 --- a/lib/typeprof/type.rb +++ b/lib/typeprof/type.rb @@ -861,7 +861,7 @@ class Signature include Utils::StructuralEquality def screen_name(iseq, scratch) - fargs_str = "(" + fargs_str = +"(" sig_help = {} add_farg = -> farg, name, help: false, key: sig_help.size do name = "`#{ name }`" if RBS::Parser::KEYWORDS.key?(name.to_s) @@ -917,7 +917,7 @@ def screen_name(iseq, scratch) fargs_str << ")" - fargs_str = "" if fargs_str == "()" + fargs_str = +"" if fargs_str == "()" # Dirty Hack: Stop the iteration at most once! # I'll remove this hack if RBS removes the limitation of nesting blocks diff --git a/test/typeprof/cli_test.rb b/test/typeprof/cli_test.rb index a67ec9e18..f5ed84acc 100644 --- a/test/typeprof/cli_test.rb +++ b/test/typeprof/cli_test.rb @@ -7,7 +7,7 @@ class CLITest < Test::Unit::TestCase rb_file = File.join(__dir__, "../../smoke/simple.rb") rb_files = [rb_file, rb_file] rbs_files = [] - output = StringIO.new("") + output = StringIO.new(+"") options = {} options[:show_untyped] = true options[:show_errors] = true @@ -37,7 +37,7 @@ def foo: (Integer n) -> String rb_file = File.join(__dir__, "../../smoke/any1.rb") rb_files = [rb_file] rbs_files = [] - output = StringIO.new("") + output = StringIO.new(+"") options = {} options[:exclude_untyped] = true options[:show_untyped] = true @@ -67,7 +67,7 @@ class Object rb_file = File.join(__dir__, "../../smoke/simple.rb") rb_files = [rb_file] rbs_files = [["test.rbs", "class Bar < Foo\nend"]] - output = StringIO.new("") + output = StringIO.new(+"") options = {} options[:show_untyped] = true options[:show_errors] = true diff --git a/test/typeprof/test_helper.rb b/test/typeprof/test_helper.rb index 088fae63d..44eb407d4 100644 --- a/test/typeprof/test_helper.rb +++ b/test/typeprof/test_helper.rb @@ -24,7 +24,7 @@ def run(gem_rbs_features: [], **options) rb_files = [@name] rbs_files = [@rbs_path].compact - output = StringIO.new("") + output = StringIO.new(+"") options[:show_untyped] = true unless options.key?(:show_untyped) options[:show_errors] = true unless options.key?(:show_errors) options[:show_indicator] = false unless options.key?(:show_indicator)