Skip to content

Commit 951fbb5

Browse files
authored
fix: Ensure compatibility with frozen string literals (googleapis#21648)
1 parent dcc9f35 commit 951fbb5

File tree

12 files changed

+32
-26
lines changed

12 files changed

+32
-26
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ jobs:
3131
- os: windows-latest
3232
ruby: "3.4"
3333
task: "--include-spec"
34+
- os: ubuntu-latest
35+
ruby: "3.4"
36+
task: "--include-spec --include-yardoc --include-build"
37+
rubyopt: "--enable-frozen-string-literal --debug-frozen-string-literal"
3438
fail-fast: false
3539
runs-on: ${{ matrix.os }}
3640
steps:
@@ -52,6 +56,8 @@ jobs:
5256
if [ -d /opt/hostedtoolcache/Ruby ]; then
5357
chmod -R o-w /opt/hostedtoolcache/Ruby
5458
fi
55-
- name: Test ${{ matrix.task }}
59+
- name: Test ${{ matrix.task }} ${{ matrix.rubyopt }}
5660
run: |
5761
toys ci -v --only ${{ matrix.task }} --github-event-name=${{ github.event_name }} --github-event-payload=${{ github.event_path }}
62+
env:
63+
RUBYOPT: "${{ matrix.rubyopt }}"

google-apis-core/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ group :development do
1111
gem 'rubocop', '>= 0.49.0', '< 0.93.2'
1212
gem 'launchy', '~> 2.4'
1313
gem 'dotenv', '~> 2.0'
14-
gem 'fakefs', '>= 1.0', '< 3', require: "fakefs/safe"
14+
gem 'fakefs', '>= 1.0', '< 4', require: "fakefs/safe"
1515
gem 'google-id-token', '~> 1.3'
1616
gem 'os', '~> 0.9'
1717
gem 'rmail', '~> 1.1'

google-apis-core/lib/google/apis/core/composite_io.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def initialize(*ios)
4242
end
4343

4444
def read(length = nil, buf = nil)
45-
buf = buf ? buf.replace('') : ''
45+
buf = buf ? buf.replace('') : +''
4646

4747
begin
4848
io = @ios[@index]

google-apis-core/lib/google/apis/core/download.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def prepare!
4646
@download_io = File.open(download_dest, 'wb')
4747
@close_io_on_finish = true
4848
else
49-
@download_io = StringIO.new('', 'wb')
49+
@download_io = StringIO.new(+'', 'wb')
5050
@close_io_on_finish = false
5151
end
5252
super

google-apis-core/lib/google/apis/core/http_command.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def success(result, &block)
283283
# @yield [nil, err] if block given
284284
# @raise [StandardError] if no block
285285
def error(err, rethrow: false, &block)
286-
logger.debug { sprintf('Error - %s', PP.pp(err, '')) }
286+
logger.debug { sprintf('Error - %s', PP.pp(err, +'')) }
287287
if err.is_a?(HTTPClient::BadResponseError)
288288
begin
289289
res = err.res
@@ -385,15 +385,15 @@ class RedactingSingleLine < PP::SingleLine
385385
end
386386

387387
def safe_pretty_representation obj
388-
out = ""
388+
out = +""
389389
printer = RedactingPP.new out, 79
390390
printer.guard_inspect_key { printer.pp obj }
391391
printer.flush
392392
out << "\n"
393393
end
394394

395395
def safe_single_line_representation obj
396-
out = ""
396+
out = +""
397397
printer = RedactingSingleLine.new out
398398
printer.guard_inspect_key { printer.pp obj }
399399
printer.flush

google-apis-core/lib/google/apis/core/multipart.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def initialize(value, header = {})
3131
end
3232

3333
def to_io(boundary)
34-
part = ''
34+
part = +''
3535
part << "--#{boundary}\r\n"
3636
part << "Content-Type: application/json\r\n"
3737
@header.each do |(k, v)|
@@ -59,15 +59,15 @@ def initialize(io, header = {})
5959
end
6060

6161
def to_io(boundary)
62-
head = ''
62+
head = +''
6363
head << "--#{boundary}\r\n"
6464
@header.each do |(k, v)|
6565
head << "#{k}: #{v}\r\n"
6666
end
6767
head << "Content-Length: #{@length}\r\n" unless @length.nil?
6868
head << "Content-Transfer-Encoding: binary\r\n"
6969
head << "\r\n"
70-
Google::Apis::Core::CompositeIO.new(StringIO.new(head), @io, StringIO.new("\r\n"))
70+
Google::Apis::Core::CompositeIO.new(StringIO.new(head), @io, StringIO.new(+"\r\n"))
7171
end
7272
end
7373

@@ -126,7 +126,7 @@ def add_upload(upload_io, content_type: nil, content_id: nil)
126126
# @return [IO]
127127
# IO stream
128128
def assemble
129-
@parts << StringIO.new("--#{@boundary}--\r\n\r\n")
129+
@parts << StringIO.new(+"--#{@boundary}--\r\n\r\n")
130130
Google::Apis::Core::CompositeIO.new(*@parts)
131131
end
132132
end

google-apis-core/lib/google/apis/errors.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def backtrace
4343
end
4444

4545
def inspect
46-
extra = ""
46+
extra = +""
4747
extra << " status_code: #{status_code.inspect}" unless status_code.nil?
4848
extra << " header: #{header.inspect}" unless header.nil?
4949
extra << " body: #{body.inspect}" unless body.nil?

google-apis-core/spec/google/apis/core/batch_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
let(:post_with_io_command) do
3737
command = Google::Apis::Core::HttpCommand.new(:post, 'https://www.googleapis.com/zoo/animals/3')
38-
command.body = StringIO.new('Goodbye!')
38+
command.body = StringIO.new(+'Goodbye!')
3939
command.header['Content-Type'] = 'text/plain'
4040
command
4141
end

google-apis-core/spec/google/apis/core/composite_io_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
context 'with StringIOs' do
5353
let(:io) do
5454
Google::Apis::Core::CompositeIO.new(
55-
StringIO.new("Hello "),
56-
StringIO.new("Cruel "),
57-
StringIO.new("World"))
55+
StringIO.new(+"Hello "),
56+
StringIO.new(+"Cruel "),
57+
StringIO.new(+"World"))
5858
end
5959
include_examples 'should act like IO'
6060
end

google-apis-core/spec/google/apis/core/service_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@
305305
expect do |b|
306306
service.batch_upload do |service|
307307
command = service.send(:make_upload_command, :post, 'zoo/animals', {})
308-
command.upload_source = StringIO.new('test')
308+
command.upload_source = StringIO.new(+'test')
309309
command.upload_content_type = 'text/plain'
310310
service.send(:execute_or_queue_command, command, &b)
311311
end
@@ -316,7 +316,7 @@
316316
expect do |b|
317317
service.batch_upload do |service|
318318
command = service.send(:make_upload_command, :post, 'zoo/animals', {})
319-
command.upload_source = StringIO.new('test')
319+
command.upload_source = StringIO.new(+'test')
320320
command.upload_content_type = 'text/plain'
321321
expect(command).to be_an_instance_of(Google::Apis::Core::MultipartUploadCommand)
322322
service.send(:execute_or_queue_command, command, &b)
@@ -328,7 +328,7 @@
328328
Google::Apis::RequestOptions.default.authorization = 'a token'
329329
service.batch_upload do |service|
330330
command = service.send(:make_upload_command, :post, 'zoo/animals', {})
331-
command.upload_source = StringIO.new('test')
331+
command.upload_source = StringIO.new(+'test')
332332
command.upload_content_type = 'text/plain'
333333
service.send(:execute_or_queue_command, command)
334334
end

0 commit comments

Comments
 (0)