Skip to content

Commit

Permalink
Convert tthe gem to frozen string literals
Browse files Browse the repository at this point in the history
While running tests for sorbet/sorbet#7778
I noticed some deprecation warnings coming from this gem.

Ruby 3.4 will have chilled string literals, as a first step toward
frozen string literals becoming the default.

Ref: https://bugs.ruby-lang.org/issues/20205
  • Loading branch information
byroot committed Mar 22, 2024
1 parent 7b6f0a1 commit abed200
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# frozen_string_literal: true
source 'https://rubygems.org'
gemspec
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'bundler/gem_tasks'
require 'bundler/setup'
require 'rake/testtask'
Expand Down
5 changes: 3 additions & 2 deletions lib/subprocess.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'thread'
require 'set'

Expand Down Expand Up @@ -428,7 +429,7 @@ def drain_fd(fd, buf=nil)
def communicate(input=nil, timeout_s=nil)
raise ArgumentError if !input.nil? && @stdin.nil?

stdout, stderr = "", ""
stdout, stderr = +"", +""

# NB: Always force encoding to binary so we handle unicode or binary input
# correctly across multiple write_nonblock calls, since we manually slice
Expand Down Expand Up @@ -508,7 +509,7 @@ def communicate(input=nil, timeout_s=nil)

if block_given? && !(stderr.empty? && stdout.empty?)
yield stdout, stderr
stdout, stderr = "", ""
stdout, stderr = +"", +""
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/subprocess/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Subprocess
VERSION = '1.5.6'
end
1 change: 1 addition & 0 deletions subprocess.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'subprocess/version'
Expand Down
5 changes: 3 additions & 2 deletions test/test_subprocess.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding: utf-8
# frozen_string_literal: true
require 'rubygems'
gem 'minitest'
require 'minitest/autorun'
Expand Down Expand Up @@ -436,7 +437,7 @@ def call_multiwrite_script(&block)

it 'preserves encoding across IO selection cycles with a block given' do
process = Subprocess::Process.new(['bash', '-c', script], :stdout => Subprocess::PIPE)
stdout = ""
stdout = +""

process.communicate do |out, _err|
stdout << out
Expand All @@ -450,7 +451,7 @@ def call_multiwrite_script(&block)
assert_equal(Encoding::UTF_8, message.encoding)

process = Subprocess::Process.new(['cat'], :stdin => Subprocess::PIPE, :stdout => Subprocess::PIPE)
stdout = ""
stdout = +""
process.communicate(message) do |out, _err|
stdout << out
end
Expand Down

0 comments on commit abed200

Please sign in to comment.