Skip to content

Commit

Permalink
Update to be frozen string literal safe
Browse files Browse the repository at this point in the history
  • Loading branch information
npezza93 committed Oct 10, 2024
1 parent c3815c2 commit efed3fa
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
bundler-cache: true
- name: Run tests
run: bundle exec rake test:units
env:
RUBYOPT: ${{ startsWith(matrix.ruby, 'head') && '--enable=frozen-string-literal' || '' }}

test-legacy:
runs-on: ubuntu-20.04
Expand Down
4 changes: 2 additions & 2 deletions lib/sshkit/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def colorize(obj, color, mode=nil)
return string unless COLOR_CODES.key?(color)

result = mode == :bold ? "\e[1;" : "\e[0;"
result << COLOR_CODES.fetch(color).to_s
result << ";49m#{string}\e[0m"

"#{result}#{COLOR_CODES.fetch(color)};49m#{string}\e[0m"
end

# Returns `true` if the underlying output is a tty, or if the SSHKIT_COLOR
Expand Down
10 changes: 8 additions & 2 deletions lib/sshkit/deprecation_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ def log(message)
return if @out.nil?
warning_msg = "[Deprecated] #{message}\n"
caller_line = caller.find { |line| !line.include?('lib/sshkit') }
warning_msg << " (Called from #{caller_line})\n" unless caller_line.nil?
@out << warning_msg unless @previous_warnings.include?(warning_msg)
warning_msg = "#{warning_msg} (Called from #{caller_line})\n" unless caller_line.nil?
unless @previous_warnings.include?(warning_msg)
if @out.frozen?
@out = "#{@out}#{warning_msg}"
else
@out << warning_msg
end
end
@previous_warnings << warning_msg
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/unit/backends/test_abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ def test_within_home
end

def test_background_logs_deprecation_warnings
deprecation_out = ''
deprecation_out = []
SSHKit.config.deprecation_output = deprecation_out

ExampleBackend.new do
background :ls
end.run

lines = deprecation_out.lines.to_a
lines = deprecation_out.join.lines.to_a

assert_equal 2, lines.length

Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ def test_on_stderr
end

def test_deprecated_stdtream_accessors
deprecation_out = ''
deprecation_out = []
SSHKit.config.deprecation_output = deprecation_out

c = Command.new(:whoami)
c.stdout='a test'
assert_equal('a test', c.stdout)
c.stderr='another test'
assert_equal('another test', c.stderr)
deprecation_lines = deprecation_out.lines.to_a
deprecation_lines = deprecation_out.join.lines.to_a

assert_equal 8, deprecation_lines.size
assert_equal(
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def setup
end

def test_deprecation_output
output = ''
output = []
SSHKit.config.deprecation_output = output
SSHKit.config.deprecation_logger.log('Test')
assert_equal "[Deprecated] Test\n", output.lines.first
assert_equal "[Deprecated] Test\n", output.join.lines.first
end

def test_default_deprecation_output
Expand Down

0 comments on commit efed3fa

Please sign in to comment.