Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert the gem to frozen string literals #75

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 4 additions & 3 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 @@ -169,7 +170,7 @@ class NonZeroExit < StandardError
# @param [::Process::Status] status The status returned by `waitpid`.
def initialize(cmd, status)
@command, @status = cmd.join(' '), status
message = "Command #{command} "
message = +"Command #{command} "
if status.exited?
message << "returned non-zero exit status #{status.exitstatus}"
elsif status.signaled?
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
Loading