diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27f0ac8c..487ab6ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/lib/sshkit/color.rb b/lib/sshkit/color.rb index 91109874..74e2df9a 100644 --- a/lib/sshkit/color.rb +++ b/lib/sshkit/color.rb @@ -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 diff --git a/lib/sshkit/deprecation_logger.rb b/lib/sshkit/deprecation_logger.rb index bddc6c68..46101228 100644 --- a/lib/sshkit/deprecation_logger.rb +++ b/lib/sshkit/deprecation_logger.rb @@ -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 diff --git a/test/unit/backends/test_abstract.rb b/test/unit/backends/test_abstract.rb index 0ec8f8d7..0267cc02 100644 --- a/test/unit/backends/test_abstract.rb +++ b/test/unit/backends/test_abstract.rb @@ -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 diff --git a/test/unit/test_command.rb b/test/unit/test_command.rb index 30964a16..d5fe9d26 100644 --- a/test/unit/test_command.rb +++ b/test/unit/test_command.rb @@ -211,7 +211,7 @@ def test_on_stderr end def test_deprecated_stdtream_accessors - deprecation_out = '' + deprecation_out = [] SSHKit.config.deprecation_output = deprecation_out c = Command.new(:whoami) @@ -219,7 +219,7 @@ def test_deprecated_stdtream_accessors 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( diff --git a/test/unit/test_configuration.rb b/test/unit/test_configuration.rb index e470daab..49a46fd2 100644 --- a/test/unit/test_configuration.rb +++ b/test/unit/test_configuration.rb @@ -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