Skip to content

Commit

Permalink
Merge #701
Browse files Browse the repository at this point in the history
701: Get tests passing with frozen-string-literals enabled. r=badboy

This one simple change ensure that all string literals can be frozen (as per the optional feature in MRI 2.3 and onwards). @twalpole has (again) beaten me to such a patch (in #590), though mine (again) does not add the pragma comment to all files. Getting their or my PRs merged in would be excellent :)

As an alternative to the pragma comment, I would recommend adding the following to your .travis.yml file to ensure regressions aren't introduced:

```yml
before_script:
- if (ruby -e "exit RUBY_VERSION.to_f >= 2.4"); then export RUBYOPT="--enable-frozen-string-literal"; fi; echo $RUBYOPT
```

This will add the flag when the tests are run on MRI 2.4 or newer (while the feature was introduced in 2.3, it doesn't seem to work reliably until 2.4). Please note: tests will currently fail when this flag is set unless test-unit is also updated (as noted in test-unit/test-unit#149).
  • Loading branch information
not-a-robot[bot] committed Jul 17, 2017
2 parents ea9f1d2 + 8033911 commit de03ea0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ rvm:
- 2.1
- 2.2
- 2.3.0
- 2.4.1
- jruby-18mode
- jruby-19mode
- jruby-9.0.5.0
Expand All @@ -16,6 +17,9 @@ gemfile: ".travis/Gemfile"

sudo: false

before_script:
- if (ruby -e "exit RUBY_VERSION.to_f >= 2.4"); then export RUBYOPT="--enable-frozen-string-literal"; fi; echo $RUBYOPT

env:
global:
- VERBOSE=true
Expand Down
6 changes: 6 additions & 0 deletions .travis/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ when "synchrony"
gem "hiredis"
gem "em-synchrony"
end

if RUBY_VERSION.to_f < 1.9
gem 'test-unit', '3.1.5'
else
gem 'test-unit', '>= 3.2.5'
end
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
source 'https://rubygems.org'

gemspec

if RUBY_VERSION.to_f < 1.9
gem 'test-unit', '3.1.5'
else
gem 'test-unit', '>= 3.2.5'
end
2 changes: 1 addition & 1 deletion lib/redis/connection/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def initialize(*args)
super(*args)

@timeout = @write_timeout = nil
@buffer = ""
@buffer = "".dup
end

def timeout=(timeout)
Expand Down
2 changes: 1 addition & 1 deletion redis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }

s.add_development_dependency("rake", "<11.0.0")
s.add_development_dependency("test-unit", "3.1.5")
s.add_development_dependency("test-unit", ">= 3.1.5")
end

0 comments on commit de03ea0

Please sign in to comment.