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
…casperisfine)

[git-p4: depot-paths = "//src/minitest/dev/": change = 14084]
  • Loading branch information
zenspider committed Mar 19, 2024
1 parent 31d8e0e commit 287b35d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
ruby: ruby
- os: macos-latest
ruby: ruby
- os: ubuntu-latest
ruby: ruby
rubyopt: "--enable-frozen-string-literal"

steps:
- name: repo checkout
Expand Down Expand Up @@ -76,5 +79,5 @@ jobs:

- name: rake test:isolated
run: |
rake test:isolated
rake test:isolated RUBYOPT="${{ matrix.rubyopt }}"
timeout-minutes: 3
2 changes: 1 addition & 1 deletion test/minitest/metametameta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def with_stderr err
def run_tu_with_fresh_reporter flags = %w[--seed 42]
options = Minitest.process_args flags

@output = StringIO.new("".encode('UTF-8'))
@output = StringIO.new("".encode(Encoding::UTF_8))

self.reporter = Minitest::CompositeReporter.new
reporter << Minitest::SummaryReporter.new(@output, options)
Expand Down
8 changes: 4 additions & 4 deletions test/minitest/test_minitest_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def test_assert_equal_string_encodings_both_different
EOM

assert_triggered msg do
x = "bad-utf8-\xF1.txt".force_encoding "ASCII"
x = "bad-utf8-\xF1.txt".dup.force_encoding Encoding::ASCII
y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
@tc.assert_equal x, y
end
Expand Down Expand Up @@ -1646,14 +1646,14 @@ def test_mu_pp_for_diff
end

def test_mu_pp_for_diff_str_bad_encoding
str = "\666".force_encoding Encoding::UTF_8
str = "\666".dup.force_encoding Encoding::UTF_8
exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""

assert_mu_pp_for_diff exp, str, :raw
end

def test_mu_pp_for_diff_str_bad_encoding_both
str = "\666A\\n\nB".force_encoding Encoding::UTF_8
str = "\666A\\n\nB".dup.force_encoding Encoding::UTF_8
exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6A\\\\n\\nB\""

assert_mu_pp_for_diff exp, str, :raw
Expand Down Expand Up @@ -1700,7 +1700,7 @@ def test_mu_pp_for_diff_str_normal
end

def test_mu_pp_str_bad_encoding
str = "\666".force_encoding Encoding::UTF_8
str = "\666".dup.force_encoding Encoding::UTF_8
exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""

assert_mu_pp exp, str, :raw
Expand Down
18 changes: 9 additions & 9 deletions test/minitest/test_minitest_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def obj.call
end

def test_stub_yield_self
obj = "foo"
obj = +"foo"

val = obj.stub :to_s, "bar" do |s|
s.to_s
Expand Down Expand Up @@ -956,7 +956,7 @@ def test_stub_lambda_block_args_6_2
def test_stub_lambda_block_call_5
@assertion_count += 1
rs = nil
io = StringIO.new "", "w"
io = StringIO.new(+"", "w")
File.stub5 :open, lambda { |p, m, &blk| blk and blk.call io } do
File.open "foo.txt", "r" do |f|
rs = f && f.write("woot")
Expand All @@ -971,7 +971,7 @@ def test_stub_lambda_block_call_6

@assertion_count += 1
rs = nil
io = StringIO.new "", "w"
io = StringIO.new(+"", "w")
File.stub6 :open, lambda { |p, m, &blk| blk.call io } do
File.open "foo.txt", "r" do |f|
rs = f.write("woot")
Expand All @@ -984,7 +984,7 @@ def test_stub_lambda_block_call_6
def test_stub_lambda_block_call_args_5
@assertion_count += 1
rs = nil
io = StringIO.new "", "w"
io = StringIO.new(+"", "w")
File.stub5(:open, lambda { |p, m, &blk| blk and blk.call io }, :WTF?) do
File.open "foo.txt", "r" do |f|
rs = f.write("woot")
Expand All @@ -999,7 +999,7 @@ def test_stub_lambda_block_call_args_6

@assertion_count += 1
rs = nil
io = StringIO.new "", "w"
io = StringIO.new(+"", "w")
File.stub6(:open, lambda { |p, m, &blk| blk.call io }, :WTF?) do
File.open "foo.txt", "r" do |f|
rs = f.write("woot")
Expand All @@ -1014,7 +1014,7 @@ def test_stub_lambda_block_call_args_6_2

@assertion_count += 2
rs = nil
io = StringIO.new "", "w"
io = StringIO.new(+"", "w")
@tc.assert_raises ArgumentError do
File.stub6_2(:open, lambda { |p, m, &blk| blk.call io }, :WTF?) do
File.open "foo.txt", "r" do |f|
Expand Down Expand Up @@ -1064,7 +1064,7 @@ def test_stub_value_block_6
def test_stub_value_block_args_5
@assertion_count += 2
rs = nil
io = StringIO.new "", "w"
io = StringIO.new(+"", "w")
File.stub5 :open, :value, io do
result = File.open "foo.txt", "r" do |f|
rs = f.write("woot")
Expand Down Expand Up @@ -1092,7 +1092,7 @@ def test_stub_value_block_args_6

@assertion_count += 2
rs = nil
io = StringIO.new "", "w"
io = StringIO.new(+"", "w")
assert_deprecated do
File.stub6 :open, :value, io do
result = File.open "foo.txt", "r" do |f|
Expand All @@ -1110,7 +1110,7 @@ def test_stub_value_block_args_6_2

@assertion_count += 2
rs = nil
io = StringIO.new "", "w"
io = StringIO.new(+"", "w")
@tc.assert_raises ArgumentError do
File.stub6_2 :open, :value, io do
result = File.open "foo.txt", "r" do |f|
Expand Down
2 changes: 1 addition & 1 deletion test/minitest/test_minitest_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def new_composite_reporter

def setup
super
self.io = StringIO.new("")
self.io = StringIO.new(+"")
self.r = new_composite_reporter
end

Expand Down
2 changes: 1 addition & 1 deletion test/minitest/test_minitest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_this_is_not_ascii_assertion
end

def test_this_is_non_ascii_failure_message
fail 'ЁЁЁ'.force_encoding('ASCII-8BIT')
fail 'ЁЁЁ'.dup.force_encoding(Encoding::BINARY)
end
end

Expand Down

0 comments on commit 287b35d

Please sign in to comment.