From deb0b4cd3b0a881f1d226f2433b82f64d734c178 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 20 Jun 2017 15:28:12 -0700 Subject: Test on modern ruby Signed-off-by: Tim Smith --- .travis.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2ad91f4..8e495b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ +language: ruby sudo: false -before_install: +cache: bundler +dist: trusty + +before_install: - gem install bundler - bundle --version - gem update --system @@ -7,11 +11,11 @@ before_install: bundler_args: --without development_extras --jobs 3 --retry 3 script: rake compile; rake spec after_success: gem install yajl-ruby; gem install json; gem install psych; FORCE_FFI_YAJL="ext" ffi-yajl-bench -language: ruby matrix: include: - - rvm: 2.3.1 - - rvm: 2.2.5 + - rvm: 2.2.7 + - rvm: 2.3.4 + - rvm: 2.4.1 - rvm: ruby-head - rvm: rbx - rvm: jruby -- cgit v1.2.1 From 30b4ed8780f5ddd1d6bf3997d7515da8aae16040 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 20 Jun 2017 15:30:50 -0700 Subject: Format the readme Signed-off-by: Tim Smith --- README.md | 104 +++++++++++++++++++------------------------------------------- 1 file changed, 31 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index 6cf244f..8efcb7f 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,8 @@ - -[![Build Status](https://travis-ci.org/chef/ffi-yajl.png)](https://travis-ci.org/chef/ffi-yajl) [![Code Climate](https://codeclimate.com/github/chef/ffi-yajl.png)](https://codeclimate.com/github/chef/ffi-yajl) - # FFI YAJL -ffi-yajl is a Ruby adapter for the [yajl](http://lloyd.github.io/yajl/) -JSON parser/generator library. ffi-yajl supports multiple Ruby C -extension mechanisms, including both MRI native extensions and FFI in -order to be compatible with as many Ruby implementations as possible -while providing good performance where possible. +[![Build Status](https://travis-ci.org/chef/ffi-yajl.svg?branch=master)](https://travis-ci.org/chef/ffi-yajl) [![Gem Version](https://badge.fury.io/rb/ffi-yajl.svg)](https://badge.fury.io/rb/ffi-yajl) + +ffi-yajl is a Ruby adapter for the [yajl](http://lloyd.github.io/yajl/) JSON parser/generator library. ffi-yajl supports multiple Ruby C extension mechanisms, including both MRI native extensions and FFI in order to be compatible with as many Ruby implementations as possible while providing good performance where possible. ## How to Install @@ -25,20 +20,20 @@ gem 'ffi-yajl' ## Supported Ruby VMs: -* Ruby MRI 1.9.3/2.0.0/2.1.x/2.2.x -* rbx 2.2.x (possibly earlier) -* Jruby 1.7.x (possibly earlier) +- Ruby MRI 1.9.3/2.0.0/2.1.x/2.2.x +- rbx 2.2.x (possibly earlier) +- Jruby 1.7.x (possibly earlier) Ruby 1.8.7 support was dropped in 2.2.0 ## Supported Distros: -* Ubuntu 10.04 through 14.10 -* Debian 7.x -* RHEL/CentOS/Oracle 5.x/6.x/7.x -* Solaris 9/10/11 (gcc, sun compiler untested) -* AIX 6.x/7.x (gcc or xlc) -* Windows 2008r2/2012 (and Win2k/2k3 and consumer versions should work) +- Ubuntu 10.04 through 14.10 +- Debian 7.x +- RHEL/CentOS/Oracle 5.x/6.x/7.x +- Solaris 9/10/11 (gcc, sun compiler untested) +- AIX 6.x/7.x (gcc or xlc) +- Windows 2008r2/2012 (and Win2k/2k3 and consumer versions should work) ## Basic Usage @@ -68,81 +63,44 @@ hash = parser.parse( json ) ## Parser Options -* `:check_utf8` -* `:dont_validate_strings` -* `:symbolize_keys` (default = false): JSON keys are parsed into symbols instead of strings. -* `:symbolize_names` (default = false): Alias for `:symbolize_keys`. -* `:allow_trailing_garbage` -* `:allow_multiple_values` -* `:allow_partial_values` -* `:unique_key_checking` (default = false): Will raise an exception if keys - are repeated in hashes in the input JSON. Without this, repeated keys will - silently replace the previous key. +- `:check_utf8` +- `:dont_validate_strings` +- `:symbolize_keys` (default = false): JSON keys are parsed into symbols instead of strings. +- `:symbolize_names` (default = false): Alias for `:symbolize_keys`. +- `:allow_trailing_garbage` +- `:allow_multiple_values` +- `:allow_partial_values` +- `:unique_key_checking` (default = false): Will raise an exception if keys are repeated in hashes in the input JSON. Without this, repeated keys will silently replace the previous key. ## Encoder Options -* `:pretty` (default = false): Produces more human readable 'pretty' output. -* `:validate_utf8` (default = true): Will raise an exception when trying to - encode strings that are invalid UTF-8. When set to false this still will - produce valid UTF-8 JSON but will replace invalid characters. +- `:pretty` (default = false): Produces more human readable 'pretty' output. +- `:validate_utf8` (default = true): Will raise an exception when trying to encode strings that are invalid UTF-8\. When set to false this still will produce valid UTF-8 JSON but will replace invalid characters. ## Forcing FFI or C Extension -You can set the environment variable `FORCE_FFI_YAJL` to `ext` or `ffi` to -control if the C extension or FFI bindings are used. +You can set the environment variable `FORCE_FFI_YAJL` to `ext` or `ffi` to control if the C extension or FFI bindings are used. ## Yajl Library Packaging -This library prefers to use the embedded yajl 2.x C library packaged in the -libyajl2 gem. In order to use the operating system yajl library (which must be -yajl 2.x) the environment variable `USE_SYSTEM_LIBYAJL2` can be set before -installing or bundling libyajl2. This will force the libyajl2 gem to skip -compiling its embedded library and the ffi-yajl gem will fallback to using the -system yajl library. +This library prefers to use the embedded yajl 2.x C library packaged in the libyajl2 gem. In order to use the operating system yajl library (which must be yajl 2.x) the environment variable `USE_SYSTEM_LIBYAJL2` can be set before installing or bundling libyajl2\. This will force the libyajl2 gem to skip compiling its embedded library and the ffi-yajl gem will fallback to using the system yajl library. ## No JSON Gem Compatiblity layer -This library does not offer a feature to patch `#to_json` methods into all -the ruby classes similarly to the JSON gem or yajl-ruby's `yajl/json_gem` -compatibility API. The differences in encoding between the JSON gem and the -Yajl C library can produce different output on different systems and makes -testing brittle. Such a feature will not be included. It was removed in -this pull request and could be easily extracted to its own gem (we have -no interest in maintaining that gem): +This library does not offer a feature to patch `#to_json` methods into all the ruby classes similarly to the JSON gem or yajl-ruby's `yajl/json_gem` compatibility API. The differences in encoding between the JSON gem and the Yajl C library can produce different output on different systems and makes testing brittle. Such a feature will not be included. It was removed in this pull request and could be easily extracted to its own gem (we have no interest in maintaining that gem): -https://github.com/chef/ffi-yajl/pull/47/files + ## Why This Instead of X? -yajl is the only JSON library we've found that has error messages that -meet our requirements. The stdlib json gem and oj (at the time we -started this project) have error messages like "invalid token at byte -1234," which are probably fine for server use, but in -[chef](https://github.com/chef/chef) we frequently deal with -user-written JSON documents, which means we need a good user experience -when encountering malformed JSON. - -We previously used brianmario's -[yajl-ruby](https://github.com/brianmario/yajl-ruby) project, but we -wanted to be able to fallback to using FFI bindings to the C code (so we -could support non-MRI rubies) and we also needed some bug fixes in -yajl2, but the maintainer wasn't able to devote enough time to the -project to make these updates in a timeframe that worked for us. +yajl is the only JSON library we've found that has error messages that meet our requirements. The stdlib json gem and oj (at the time we started this project) have error messages like "invalid token at byte 1234," which are probably fine for server use, but in [chef](https://github.com/chef/chef) we frequently deal with user-written JSON documents, which means we need a good user experience when encountering malformed JSON. + +We previously used brianmario's [yajl-ruby](https://github.com/brianmario/yajl-ruby) project, but we wanted to be able to fallback to using FFI bindings to the C code (so we could support non-MRI rubies) and we also needed some bug fixes in yajl2, but the maintainer wasn't able to devote enough time to the project to make these updates in a timeframe that worked for us. ## Thanks -This was initially going to be a clean rewrite of an ffi ruby wrapper around -yajl2, but as it progressed more and more code was pulled in from brianmario's -existing yajl-ruby gem, particularly all the c extension code, lots of specs -and the benchmarks. And the process of writing this would have been much more -difficult without being able to draw heavily from already solved problems in -yajl-ruby. +This was initially going to be a clean rewrite of an ffi ruby wrapper around yajl2, but as it progressed more and more code was pulled in from brianmario's existing yajl-ruby gem, particularly all the c extension code, lots of specs and the benchmarks. And the process of writing this would have been much more difficult without being able to draw heavily from already solved problems in yajl-ruby. ## License -Given that this draws heavily from the yajl-ruby sources, and could be -considered a derivative work, the MIT License from that project has been -preserved and this source code has deliberately not been dual licensed under -Chef's typical Apache License. See the -[LICENSE](https://github.com/chef/ffi-yajl/blob/master/LICENSE) file in this -project. +Given that this draws heavily from the yajl-ruby sources, and could be considered a derivative work, the MIT License from that project has been preserved and this source code has deliberately not been dual licensed under Chef's typical Apache License. See the [LICENSE](https://github.com/chef/ffi-yajl/blob/master/LICENSE) file in this project. -- cgit v1.2.1 From 31c1e1a98f5bfbb8d292de20f4d132f5c6d10019 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 20 Jun 2017 15:36:23 -0700 Subject: Remove the test kitchen stuff that doesn't work Signed-off-by: Tim Smith --- .kitchen.yml | 21 ---------------- Gemfile | 4 --- bootstrap.sh | 79 ------------------------------------------------------------ 3 files changed, 104 deletions(-) delete mode 100644 .kitchen.yml delete mode 100755 bootstrap.sh diff --git a/.kitchen.yml b/.kitchen.yml deleted file mode 100644 index 441605e..0000000 --- a/.kitchen.yml +++ /dev/null @@ -1,21 +0,0 @@ -driver: - name: vagrant - customize: - memory: 1024 - cpus: 4 - -provisioner: - name: shell - data_path: . - -platforms: - - name: ubuntu-10.04 - - name: ubuntu-12.04 - - name: ubuntu-12.10 - - name: ubuntu-13.04 - - name: ubuntu-13.10 - - name: ubuntu-14.04 - - name: freebsd-9.2 - -suites: - - name: default diff --git a/Gemfile b/Gemfile index d16a96f..d5fe6d0 100644 --- a/Gemfile +++ b/Gemfile @@ -15,8 +15,4 @@ end group :development_extras do gem 'rubocop', '= 0.32.1' gem 'reek', '= 1.3.7' - gem 'test-kitchen', '~> 1.2' - gem 'kitchen-digitalocean' - gem 'kitchen-ec2' - gem 'kitchen-vagrant' end diff --git a/bootstrap.sh b/bootstrap.sh deleted file mode 100755 index b6d4ad5..0000000 --- a/bootstrap.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/sh -# -# bootstrap.sh file for test-kitchen shell provisioner to run tests on -# remote server. -# - -set -e -set -x - -machine=`uname -m` -os=`uname -s` - -if test -f "/etc/lsb-release" && grep -q DISTRIB_ID /etc/lsb-release; then - platform=`grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2 | tr '[A-Z]' '[a-z]'` - platform_version=`grep DISTRIB_RELEASE /etc/lsb-release | cut -d "=" -f 2` -fi - -if test "x$os" = "xFreeBSD"; then - platform="freebsd" - platform_version=`uname -r | sed 's/-.*//'` -fi - -compile_rubygems() { - cd /tmp - wget http://production.cf.rubygems.org/rubygems/rubygems-1.6.2.tgz -O - | tar zxf - - cd rubygems-1.6.2 && ruby setup.rb --no-format-executable - # i think this assumes running under bash - cd - -} - - -case $platform in - "ubuntu") - export DEBIAN_FRONTEND=noninteractive - apt-get update - apt-get -y -y install bc - ubuntu_before_12_04=`echo "$platform_version < 12.04" | bc` - ubuntu_before_14_04=`echo "$platform_version < 14.04" | bc` - if [ "x$ubuntu_before_12_04" = "x1" ]; then - apt-get -q -y install ruby1.8 ruby1.8-dev rubygems1.8 libopenssl-ruby1.8 - apt-get -q -y install git-core cmake build-essential wget - update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.8 500 - update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.8 500 - update-alternatives --config ruby - update-alternatives --config gem - compile_rubygems - elif [ "x$ubuntu_before_14_04" = "x1" ]; then - apt-get -q -y purge ruby1.8 ruby1.8-dev rubygems1.8 libopenssl-ruby1.8 - apt-get -q -y install ruby1.9.1 ruby1.9.1-dev rubygems1.9.1 libopenssl-ruby1.9.1 - apt-get -q -y install git cmake build-essential - update-alternatives --config ruby - update-alternatives --config gem - else - apt-get -q -y purge ruby1.8 - apt-get -q -y install ruby1.9.1 ruby1.9.1-dev rubygems1.9.1 libopenssl-ruby1.9.1 - apt-get -q -y install git cmake build-essential - fi - ;; - freebsd) - if pkg -N 2>&1 | grep "pkg is not installed"; then - export ASSUME_ALWAYS_YES=YES - pkg bootstrap - pkg2ng - fi - pkg install -y ruby - pkg install -y ruby19-gems - ;; - *) - echo "i don't know how to setup base o/s on platform $platform, hope it works!" - ;; -esac - -rm -f Gemfile.lock -gem install bundler --no-rdoc --no-ri - -cd /tmp/kitchen/data -bundle install --without development_extras -rake compile -rake spec -- cgit v1.2.1 From f3f92275f804f4c6cf93ee054af7d4ba3e50030a Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 20 Jun 2017 15:37:11 -0700 Subject: Require Ruby 2.2 and bump deps Signed-off-by: Tim Smith --- ffi-yajl.gemspec.shared | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ffi-yajl.gemspec.shared b/ffi-yajl.gemspec.shared index d198f0a..5bce91b 100644 --- a/ffi-yajl.gemspec.shared +++ b/ffi-yajl.gemspec.shared @@ -9,17 +9,16 @@ Gem::Specification.new do |s| s.summary = "Ruby FFI wrapper around YAJL 2.x" s.description = s.summary s.author = "Lamont Granquist" - s.email = "lamont@getchef.com" + s.email = "lamont@chef.io" s.homepage = "http://github.com/chef/ffi-yajl" - s.required_ruby_version = ">= 2.1" + s.required_ruby_version = ">= 2.2" - s.add_development_dependency "rake", "~> 10.1" - s.add_development_dependency "rspec", "~> 2.99" + s.add_development_dependency "rake", ">= 10.1" + s.add_development_dependency "rspec", "~> 3.0" s.add_development_dependency "pry", "~> 0.9" s.add_development_dependency "rake-compiler", "~> 1.0" - s.add_development_dependency "rack", "~> 1.0" # pinning for ruby 2.1.x - s.add_development_dependency "activesupport", "~> 4.0" # pinning for ruby 2.1.x + s.add_development_dependency "rack", "~> 2.0" s.add_dependency "libyajl2", "~> 1.2" s.bindir = "bin" -- cgit v1.2.1 From 672fce3aed2d68e7362dc5cfeb72df78f30eb3a2 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 20 Jun 2017 15:37:38 -0700 Subject: Switch from reek/rubocop to chefstyle Reek doesn't work with modern Rake Signed-off-by: Tim Smith --- .rubocop.yml | 68 +---------- Gemfile | 7 +- Rakefile | 141 ++++++++-------------- bin/ffi-yajl-bench | 14 +-- ext/ffi_yajl/ext/dlopen/extconf.rb | 10 +- ext/ffi_yajl/ext/encoder/extconf.rb | 24 ++-- ext/ffi_yajl/ext/parser/extconf.rb | 24 ++-- lib/ffi_yajl.rb | 14 +-- lib/ffi_yajl/benchmark.rb | 10 +- lib/ffi_yajl/benchmark/encode.rb | 16 +-- lib/ffi_yajl/benchmark/encode_json_and_marshal.rb | 18 +-- lib/ffi_yajl/benchmark/encode_json_and_yaml.rb | 22 ++-- lib/ffi_yajl/benchmark/encode_profile.rb | 10 +- lib/ffi_yajl/benchmark/http.rb | 24 ++-- lib/ffi_yajl/benchmark/parse.rb | 16 +-- lib/ffi_yajl/benchmark/parse_json_and_marshal.rb | 20 +-- lib/ffi_yajl/benchmark/parse_json_and_yaml.rb | 22 ++-- lib/ffi_yajl/benchmark/parse_profile.rb | 10 +- lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb | 8 +- lib/ffi_yajl/benchmark/parse_stream.rb | 18 +-- lib/ffi_yajl/encoder.rb | 4 +- lib/ffi_yajl/ext.rb | 18 +-- lib/ffi_yajl/ffi.rb | 16 +-- lib/ffi_yajl/ffi/encoder.rb | 18 +-- lib/ffi_yajl/ffi/parser.rb | 10 +- lib/ffi_yajl/map_library_name.rb | 6 +- lib/ffi_yajl/parser.rb | 4 +- spec/ffi_yajl/encoder_spec.rb | 20 +-- spec/ffi_yajl/map_library_name_spec.rb | 4 +- spec/ffi_yajl/parser_spec.rb | 14 +-- spec/spec_helper.rb | 8 +- 31 files changed, 254 insertions(+), 364 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e843ff7..1ed8c28 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,67 +1,3 @@ -AbcSize: - Enabled: false -AndOr: - Enabled: false -Lint/AssignmentInCondition: - Enabled: false -ClassAndModuleCamelCase: - Enabled: false -ClassLength: - Enabled: false -CommentAnnotation: - Enabled: false -CyclomaticComplexity: - Enabled: false -Documentation: - Enabled: false -DoubleNegation: - Enabled: false -Encoding: - Enabled: false -Eval: - Enabled: false -Style/FileName: +Lint/DuplicateMethods: Exclude: - - bin/ffi-yajl-bench -FormatString: - Enabled: false -Style/GuardClause: - Enabled: false -Lint/HandleExceptions: - Enabled: false -LineLength: - Enabled: false -MethodLength: - Enabled: false -ModuleLength: - Enabled: false -PerceivedComplexity: - Enabled: false -PercentLiteralDelimiters: - PreferredDelimiters: - '%': '{}' - '%q': '{}' - '%Q': '{}' - '%w': '{}' - '%W': '{}' - '%x': '{}' -RegexpLiteral: - Enabled: false -Style/Semicolon: - Enabled: false -SignalException: - Enabled: false -SingleSpaceBeforeFirstArg: - Enabled: false -SpaceInsideBrackets: - Enabled: false -SpaceInsideParens: - Enabled: false -StringLiterals: - Enabled: false -TrailingComma: - EnforcedStyleForMultiline: comma -UnusedMethodArgument: - Enabled: false -UnusedBlockArgument: - Enabled: false + - 'lib/ffi_yajl/ffi/encoder.rb' diff --git a/Gemfile b/Gemfile index d5fe6d0..3250298 100644 --- a/Gemfile +++ b/Gemfile @@ -3,16 +3,15 @@ source "https://rubygems.org" gemspec name: "ffi-yajl" platforms :rbx do - gem 'rubysl', '~> 2.0' + gem "rubysl", "~> 2.0" end group :development do # for testing loading concurrently with yajl-ruby, not on jruby # gem 'yajl-ruby', platforms: [ :ruby, :mswin, :mingw ] - gem 'github_changelog_generator' + gem "github_changelog_generator" end group :development_extras do - gem 'rubocop', '= 0.32.1' - gem 'reek', '= 1.3.7' + gem "chefstyle" end diff --git a/Rakefile b/Rakefile index 05a69d1..331b3fd 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,10 @@ $LOAD_PATH << File.expand_path(File.join(File.dirname( __FILE__ ), "lib")) -require 'rspec/core/rake_task' -require 'rubygems/package_task' -require 'rake/extensiontask' -require 'ffi_yajl/version' -require 'github_changelog_generator/task' +require "rspec/core/rake_task" +require "rubygems/package_task" +require "rake/extensiontask" +require "ffi_yajl/version" +require "github_changelog_generator/task" Dir[File.expand_path("../*gemspec", __FILE__)].reverse_each do |gemspec_path| gemspec = eval(IO.read(gemspec_path)) @@ -13,7 +13,7 @@ end GitHubChangelogGenerator::RakeTask.new :changelog do |config| config.issues = false - config.since_tag = '1.0.1' + config.since_tag = "1.0.1" config.exclude_labels = %w{duplicate question invalid wontfix changelog_skip} end @@ -42,26 +42,26 @@ task install: [:package] do end end -spec = Gem::Specification.load('ffi-yajl.gemspec') +spec = Gem::Specification.load("ffi-yajl.gemspec") Rake::ExtensionTask.new do |ext| - ext.name = 'encoder' - ext.lib_dir = 'lib/ffi_yajl/ext' - ext.ext_dir = 'ext/ffi_yajl/ext/encoder' + ext.name = "encoder" + ext.lib_dir = "lib/ffi_yajl/ext" + ext.ext_dir = "ext/ffi_yajl/ext/encoder" ext.gem_spec = spec end Rake::ExtensionTask.new do |ext| - ext.name = 'parser' - ext.lib_dir = 'lib/ffi_yajl/ext' - ext.ext_dir = 'ext/ffi_yajl/ext/parser' + ext.name = "parser" + ext.lib_dir = "lib/ffi_yajl/ext" + ext.ext_dir = "ext/ffi_yajl/ext/parser" ext.gem_spec = spec end Rake::ExtensionTask.new do |ext| - ext.name = 'dlopen' - ext.lib_dir = 'lib/ffi_yajl/ext' - ext.ext_dir = 'ext/ffi_yajl/ext/dlopen' + ext.name = "dlopen" + ext.lib_dir = "lib/ffi_yajl/ext" + ext.ext_dir = "ext/ffi_yajl/ext/dlopen" ext.gem_spec = spec end @@ -80,101 +80,56 @@ end namespace :spec do desc "Run all specs against ffi extension" RSpec::Core::RakeTask.new(:ffi) do |t| - ENV['FORCE_FFI_YAJL'] = "ffi" - t.pattern = FileList['spec/**/*_spec.rb'] + ENV["FORCE_FFI_YAJL"] = "ffi" + t.pattern = FileList["spec/**/*_spec.rb"] end if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/ desc "Run all specs again c extension" RSpec::Core::RakeTask.new(:ext) do |t| - ENV['FORCE_FFI_YAJL'] = "ext" - t.pattern = FileList['spec/**/*_spec.rb'] + ENV["FORCE_FFI_YAJL"] = "ext" + t.pattern = FileList["spec/**/*_spec.rb"] end end end -if RUBY_VERSION.to_f >= 1.9 - namespace :integration do - begin - require 'kitchen' - rescue LoadError - task :vagrant do - puts "test-kitchen gem is not installed" - end - task :cloud do - puts "test-kitchen gem is not installed" - end - else - desc 'Run Test Kitchen with Vagrant' - task :vagrant do - Kitchen.logger = Kitchen.default_file_logger - Kitchen::Config.new.instances.each do |instance| - instance.test(:always) - end - end - - desc 'Run Test Kitchen with cloud plugins' - task :cloud do - if ENV['TRAVIS_PULL_REQUEST'] != 'true' - ENV['KITCHEN_YAML'] = '.kitchen.cloud.yml' - sh "kitchen test --concurrency 4" - end - end - end - end - namespace :style do - desc 'Run Ruby style checks' - begin - require 'rubocop/rake_task' - rescue LoadError - task :rubocop do - puts "rubocop gem is not installed" - end - else - RuboCop::RakeTask.new(:rubocop) do |t| - t.fail_on_error = false - end - end - - desc 'Run Ruby smell checks' - begin - require 'reek/rake/task' - rescue LoadError - task :reek do - puts "reek gem is not installed" - end - else - Reek::Rake::Task.new(:reek) do |t| - t.fail_on_error = false - # t.config_files = '.reek.yml' - end - end - end -else - namespace :integration do +namespace :integration do + begin + require "kitchen" + rescue LoadError task :vagrant do - puts "test-kitchen unsupported on ruby 1.8" + puts "test-kitchen gem is not installed" end - task :cloud do - puts "test-kitchen unsupported on ruby 1.8" + else + desc "Run Test Kitchen with Vagrant" + task :vagrant do + Kitchen.logger = Kitchen.default_file_logger + Kitchen::Config.new.instances.each do |instance| + instance.test(:always) + end end end - namespace :style do +end +namespace :style do + desc "Run Ruby style checks" + begin + require "chefstyle" + require "rubocop/rake_task" + rescue LoadError task :rubocop do - puts "rubocop unsupported on ruby 1.8" + puts "chefstyle gem is not installed" end - task :reek do - puts "reek unsupported on ruby 1.8" + else + RuboCop::RakeTask.new(:rubocop) do |t| + t.fail_on_error = false end end end -desc 'Run all style checks' -task style: ['style:rubocop', 'style:reek'] +desc "Run all style checks" +task style: ["style:rubocop"] -desc 'Run style + spec tests by default on travis' +desc "Run style + spec tests by default on travis" task travis: %w{style spec} -desc 'Run style, spec and test kichen on travis' -task travis_all: ['style', 'spec', 'integration:cloud'] - -task default: ['style', 'spec', 'integration:vagrant'] +desc "Run style + spec tests by default" +task default: %w{style spec} diff --git a/bin/ffi-yajl-bench b/bin/ffi-yajl-bench index ceff62b..a861d1f 100755 --- a/bin/ffi-yajl-bench +++ b/bin/ffi-yajl-bench @@ -2,31 +2,31 @@ $LOAD_PATH << File.expand_path(File.join(File.dirname( File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ ), "../lib")) -require 'optparse' -require 'ffi_yajl/benchmark' +require "optparse" +require "ffi_yajl/benchmark" opts = {} optparse = OptionParser.new do |o| o.banner = "Usage: ffi-yajl-bench" opts[:profile] = false - o.on( '-p', '--profile', 'Run perftools.rb profiling' ) do + o.on( "-p", "--profile", "Run perftools.rb profiling" ) do opts[:profile] = true end - o.on( '-F', '--ffi', 'Force using FFI' ) do + o.on( "-F", "--ffi", "Force using FFI" ) do opts[:ffi] = true end - o.on( '-E', '--ext', 'Force using C ext' ) do + o.on( "-E", "--ext", "Force using C ext" ) do opts[:ext] = true end end optparse.parse! -ENV['FORCE_FFI_YAJL'] = 'ffi' if opts[:ffi] -ENV['FORCE_FFI_YAJL'] = 'ext' if opts[:ext] +ENV["FORCE_FFI_YAJL"] = "ffi" if opts[:ffi] +ENV["FORCE_FFI_YAJL"] = "ext" if opts[:ext] if opts[:profile] FFI_Yajl::Benchmark::ParseProfileRubyProf.new.run diff --git a/ext/ffi_yajl/ext/dlopen/extconf.rb b/ext/ffi_yajl/ext/dlopen/extconf.rb index f35d0cb..803d326 100644 --- a/ext/ffi_yajl/ext/dlopen/extconf.rb +++ b/ext/ffi_yajl/ext/dlopen/extconf.rb @@ -1,8 +1,8 @@ # rubocop:disable Style/GlobalVars -require 'mkmf' -require 'rubygems' +require "mkmf" +require "rubygems" -RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC'] +RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"] puts $CFLAGS puts $LDFLAGS @@ -11,6 +11,6 @@ have_header("dlfcn.h") have_library("dl", "dlopen") -dir_config 'dlopen' +dir_config "dlopen" -create_makefile 'ffi_yajl/ext/dlopen' +create_makefile "ffi_yajl/ext/dlopen" diff --git a/ext/ffi_yajl/ext/encoder/extconf.rb b/ext/ffi_yajl/ext/encoder/extconf.rb index e46080a..e13c0a1 100644 --- a/ext/ffi_yajl/ext/encoder/extconf.rb +++ b/ext/ffi_yajl/ext/encoder/extconf.rb @@ -1,9 +1,9 @@ # rubocop:disable Style/GlobalVars -require 'mkmf' -require 'rubygems' -require 'libyajl2' +require "mkmf" +require "rubygems" +require "libyajl2" -RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC'] +RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"] # pick up the vendored libyajl2 out of the libyajl2 gem $CFLAGS = " -I#{Libyajl2.include_path} #{$CFLAGS}" @@ -16,7 +16,7 @@ puts $CFLAGS puts $LDFLAGS # except if you're doing an unoptimized gcc install we're going to help you out a bit -if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc|clang/ +if RbConfig::MAKEFILE_CONFIG["CC"] =~ /gcc|clang/ $CFLAGS << " -O3" unless $CFLAGS[/-O\d/] # how many people realize that -Wall is a compiler-specific flag??? # apparently not many based on reading lots of shitty extconf.rb's out there @@ -34,32 +34,32 @@ end # NOTE: find_library has the side effect of adding -lyajl to the flags which we are deliberately # avoiding doing with the libyajl2-gem (allowing it to be lazily loaded with dlopen) -if !windows? && !find_header('yajl/yajl_tree.h') +if !windows? && !find_header("yajl/yajl_tree.h") puts "libyajl2 headers not found in libyajl2-gem, searching for system libraries..." HEADER_DIRS = [ "/opt/local/include", # MacPorts "/usr/local/include", # /usr/local - RbConfig::CONFIG['includedir'], # Ruby + RbConfig::CONFIG["includedir"], # Ruby "/usr/include", # (default) ] LIB_DIRS = [ "/opt/local/lib", # MacPorts "/usr/local/lib", # /usr/local + Homebrew - RbConfig::CONFIG['libdir'], # Ruby + RbConfig::CONFIG["libdir"], # Ruby "/usr/lib", # (default) ] # add --with-yajl-dir, --with-yajl-include, --with-yajl-lib - dir_config('yajl', HEADER_DIRS, LIB_DIRS) + dir_config("yajl", HEADER_DIRS, LIB_DIRS) # here we use find_library in order to deliberately link with -lyajl as a useful side-effect - unless find_header('yajl/yajl_tree.h') && find_library('yajl', 'yajl_complete_parse') + unless find_header("yajl/yajl_tree.h") && find_library("yajl", "yajl_complete_parse") abort "libyajl2 is missing. please install libyajl2" end end -dir_config 'encoder' +dir_config "encoder" -create_makefile 'ffi_yajl/ext/encoder' +create_makefile "ffi_yajl/ext/encoder" diff --git a/ext/ffi_yajl/ext/parser/extconf.rb b/ext/ffi_yajl/ext/parser/extconf.rb index 6f8526e..86ee50f 100644 --- a/ext/ffi_yajl/ext/parser/extconf.rb +++ b/ext/ffi_yajl/ext/parser/extconf.rb @@ -1,9 +1,9 @@ # rubocop:disable Style/GlobalVars -require 'mkmf' -require 'rubygems' -require 'libyajl2' +require "mkmf" +require "rubygems" +require "libyajl2" -RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC'] +RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"] # pick up the vendored libyajl2 out of the libyajl2 gem $CFLAGS = "-I#{Libyajl2.include_path} #{$CFLAGS}" @@ -16,7 +16,7 @@ puts $CFLAGS puts $LDFLAGS # except if you're doing an unoptimized gcc install we're going to help you out a bit -if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc|clang/ +if RbConfig::MAKEFILE_CONFIG["CC"] =~ /gcc|clang/ $CFLAGS << " -O3" unless $CFLAGS[/-O\d/] # how many people realize that -Wall is a compiler-specific flag??? # apparently not many based on reading lots of shitty extconf.rb's out there @@ -34,32 +34,32 @@ end # NOTE: find_library has the side effect of adding -lyajl to the flags which we are deliberately # avoiding doing with the libyajl2-gem (allowing it to be lazily loaded with dlopen) -if !windows? && !find_header('yajl/yajl_tree.h') +if !windows? && !find_header("yajl/yajl_tree.h") puts "libyajl2 headers not found in libyajl2-gem, searching for system libraries..." HEADER_DIRS = [ "/opt/local/include", # MacPorts "/usr/local/include", # /usr/local - RbConfig::CONFIG['includedir'], # Ruby + RbConfig::CONFIG["includedir"], # Ruby "/usr/include", # (default) ] LIB_DIRS = [ "/opt/local/lib", # MacPorts "/usr/local/lib", # /usr/local + Homebrew - RbConfig::CONFIG['libdir'], # Ruby + RbConfig::CONFIG["libdir"], # Ruby "/usr/lib", # (default) ] # add --with-yajl-dir, --with-yajl-include, --with-yajl-lib - dir_config('yajl', HEADER_DIRS, LIB_DIRS) + dir_config("yajl", HEADER_DIRS, LIB_DIRS) # here we use find_library in order to deliberately link with -lyajl as a useful side-effect - unless find_header('yajl/yajl_tree.h') && find_library('yajl', 'yajl_complete_parse') + unless find_header("yajl/yajl_tree.h") && find_library("yajl", "yajl_complete_parse") abort "libyajl2 is missing. please install libyajl2" end end -dir_config 'parser' +dir_config "parser" -create_makefile 'ffi_yajl/ext/parser' +create_makefile "ffi_yajl/ext/parser" diff --git a/lib/ffi_yajl.rb b/lib/ffi_yajl.rb index 49cf97f..1111775 100644 --- a/lib/ffi_yajl.rb +++ b/lib/ffi_yajl.rb @@ -34,17 +34,17 @@ # dropped, so don't bother asking for that. # - Then we try the c-ext and rescue into ffi that fails # -if ENV['FORCE_FFI_YAJL'] == "ext" - require 'ffi_yajl/ext' -elsif ENV['FORCE_FFI_YAJL'] == "ffi" - require 'ffi_yajl/ffi' +if ENV["FORCE_FFI_YAJL"] == "ext" + require "ffi_yajl/ext" +elsif ENV["FORCE_FFI_YAJL"] == "ffi" + require "ffi_yajl/ffi" elsif RUBY_PLATFORM == "java" - require 'ffi_yajl/ffi' + require "ffi_yajl/ffi" else begin - require 'ffi_yajl/ext' + require "ffi_yajl/ext" rescue LoadError warn "failed to load the ffi-yajl c-extension, falling back to ffi interface" - require 'ffi_yajl/ffi' + require "ffi_yajl/ffi" end end diff --git a/lib/ffi_yajl/benchmark.rb b/lib/ffi_yajl/benchmark.rb index e8944ca..1372133 100644 --- a/lib/ffi_yajl/benchmark.rb +++ b/lib/ffi_yajl/benchmark.rb @@ -20,8 +20,8 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -require 'ffi_yajl/benchmark/encode.rb' -require 'ffi_yajl/benchmark/encode_profile.rb' -require 'ffi_yajl/benchmark/parse.rb' -require 'ffi_yajl/benchmark/parse_profile.rb' -require 'ffi_yajl/benchmark/parse_profile_ruby_prof.rb' +require "ffi_yajl/benchmark/encode.rb" +require "ffi_yajl/benchmark/encode_profile.rb" +require "ffi_yajl/benchmark/parse.rb" +require "ffi_yajl/benchmark/parse_profile.rb" +require "ffi_yajl/benchmark/parse_profile_ruby_prof.rb" diff --git a/lib/ffi_yajl/benchmark/encode.rb b/lib/ffi_yajl/benchmark/encode.rb index fc03c06..17e12cc 100644 --- a/lib/ffi_yajl/benchmark/encode.rb +++ b/lib/ffi_yajl/benchmark/encode.rb @@ -1,26 +1,26 @@ # Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario # See MIT-LICENSE -require 'rubygems' -require 'benchmark' -require 'stringio' +require "rubygems" +require "benchmark" +require "stringio" if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/ begin - require 'yajl' + require "yajl" rescue LoadError puts "INFO: yajl-ruby not installed" end else puts "INFO: skipping yajl-ruby on jruby" end -require 'ffi_yajl' +require "ffi_yajl" begin - require 'json' + require "json" rescue LoadError puts "INFO: json gem not installed" end begin - require 'oj' + require "oj" rescue LoadError puts "INFO: oj gem not installed" end @@ -31,7 +31,7 @@ module FFI_Yajl def run # filename = ARGV[0] || 'benchmark/subjects/ohai.json' filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json")) - hash = File.open(filename, 'rb') { |f| FFI_Yajl::Parser.parse(f.read) } + hash = File.open(filename, "rb") { |f| FFI_Yajl::Parser.parse(f.read) } times = ARGV[1] ? ARGV[1].to_i : 1000 puts "Starting benchmark encoding #{filename} #{times} times\n\n" diff --git a/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb b/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb index e9d19bc..4269056 100644 --- a/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb +++ b/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb @@ -1,18 +1,18 @@ -$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..') -$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') +$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..") +$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib") -require 'rubygems' -require 'benchmark' -require 'yajl' -require 'stringio' +require "rubygems" +require "benchmark" +require "yajl" +require "stringio" begin - require 'json' + require "json" rescue LoadError end times = ARGV[0] ? ARGV[0].to_i : 1000 -filename = 'benchmark/subjects/ohai.json' -json = File.new(filename, 'r') +filename = "benchmark/subjects/ohai.json" +json = File.new(filename, "r") hash = Yajl::Parser.new.parse(json) json.close diff --git a/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb b/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb index 33dbbb2..72310c1 100644 --- a/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb +++ b/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb @@ -1,18 +1,18 @@ -$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..') -$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') +$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..") +$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib") -require 'rubygems' -require 'benchmark' -require 'yajl' +require "rubygems" +require "benchmark" +require "yajl" begin - require 'json' + require "json" rescue LoadError end -require 'yaml' +require "yaml" # JSON Section -filename = 'benchmark/subjects/ohai.json' -json = File.new(filename, 'r') +filename = "benchmark/subjects/ohai.json" +json = File.new(filename, "r") hash = Yajl::Parser.new.parse(json) json.close @@ -33,8 +33,8 @@ Benchmark.bmbm do |x| end # YAML Section -filename = 'benchmark/subjects/ohai.yml' -yml = File.new(filename, 'r') +filename = "benchmark/subjects/ohai.yml" +yml = File.new(filename, "r") data = YAML.load_stream(yml) yml.close diff --git a/lib/ffi_yajl/benchmark/encode_profile.rb b/lib/ffi_yajl/benchmark/encode_profile.rb index 36b92c7..468f88b 100644 --- a/lib/ffi_yajl/benchmark/encode_profile.rb +++ b/lib/ffi_yajl/benchmark/encode_profile.rb @@ -1,15 +1,15 @@ # Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario # See MIT-LICENSE -require 'rubygems' -require 'ffi_yajl' +require "rubygems" +require "ffi_yajl" begin - require 'perftools' + require "perftools" rescue LoadError puts "INFO: perftools.rb gem not installed" end -ENV['CPUPROFILE_FREQUENCY'] = "4000" +ENV["CPUPROFILE_FREQUENCY"] = "4000" module FFI_Yajl class Benchmark @@ -18,7 +18,7 @@ module FFI_Yajl return unless defined?(PerfTools) filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json")) - hash = File.open(filename, 'rb') { |f| FFI_Yajl::Parser.parse(f.read) } + hash = File.open(filename, "rb") { |f| FFI_Yajl::Parser.parse(f.read) } times = 1000 puts "Starting profiling encoding #{filename} #{times} times\n\n" diff --git a/lib/ffi_yajl/benchmark/http.rb b/lib/ffi_yajl/benchmark/http.rb index b94a46c..0b19387 100644 --- a/lib/ffi_yajl/benchmark/http.rb +++ b/lib/ffi_yajl/benchmark/http.rb @@ -1,17 +1,17 @@ -$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..') -$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') +$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..") +$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib") -require 'rubygems' -require 'benchmark' -require 'yajl/http_stream' -require 'yajl/gzip' -require 'yajl/deflate' -require 'yajl/bzip2' unless defined?(Bzip2) -require 'json' -require 'uri' -require 'net/http' +require "rubygems" +require "benchmark" +require "yajl/http_stream" +require "yajl/gzip" +require "yajl/deflate" +require "yajl/bzip2" unless defined?(Bzip2) +require "json" +require "uri" +require "net/http" -uri = URI.parse('http://search.twitter.com/search.json?q=github') +uri = URI.parse("http://search.twitter.com/search.json?q=github") # uri = URI.parse('http://localhost/yajl-ruby.git/benchmark/subjects/contacts.json') times = ARGV[0] ? ARGV[0].to_i : 1 diff --git a/lib/ffi_yajl/benchmark/parse.rb b/lib/ffi_yajl/benchmark/parse.rb index 6aacc94..ad0091c 100644 --- a/lib/ffi_yajl/benchmark/parse.rb +++ b/lib/ffi_yajl/benchmark/parse.rb @@ -1,10 +1,10 @@ -require 'rubygems' -require 'benchmark' -require 'yajl' -require 'ffi_yajl' +require "rubygems" +require "benchmark" +require "yajl" +require "ffi_yajl" if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/ begin - require 'yajl' + require "yajl" rescue LoadError puts "INFO: yajl-ruby not installed" end @@ -12,11 +12,11 @@ else puts "INFO: skipping yajl-ruby on jruby" end begin - require 'json' + require "json" rescue LoadError end begin - require 'oj' + require "oj" rescue LoadError end @@ -25,7 +25,7 @@ module FFI_Yajl class Parse def run filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "item.json")) - json = File.new(filename, 'r') + json = File.new(filename, "r") json_str = json.read times = ARGV[1] ? ARGV[1].to_i : 10_000 diff --git a/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb b/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb index cd07d46..1148ebc 100644 --- a/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb +++ b/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb @@ -1,19 +1,19 @@ -$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..') -$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') +$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..") +$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib") -require 'rubygems' -require 'benchmark' -require 'yajl' +require "rubygems" +require "benchmark" +require "yajl" begin - require 'json' + require "json" rescue LoadError end # JSON section -filename = 'benchmark/subjects/ohai.json' -marshal_filename = 'benchmark/subjects/ohai.marshal_dump' -json = File.new(filename, 'r') -marshal_file = File.new(marshal_filename, 'r') +filename = "benchmark/subjects/ohai.json" +marshal_filename = "benchmark/subjects/ohai.marshal_dump" +json = File.new(filename, "r") +marshal_file = File.new(marshal_filename, "r") hash = {} diff --git a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb b/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb index 6e479ce..b55d916 100644 --- a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb +++ b/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb @@ -1,18 +1,18 @@ -$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..') -$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') +$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..") +$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib") -require 'rubygems' -require 'benchmark' -require 'yajl' +require "rubygems" +require "benchmark" +require "yajl" begin - require 'json' + require "json" rescue LoadError end -require 'yaml' +require "yaml" # JSON section -filename = 'benchmark/subjects/ohai.json' -json = File.new(filename, 'r') +filename = "benchmark/subjects/ohai.json" +json = File.new(filename, "r") times = ARGV[0] ? ARGV[0].to_i : 1000 puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n" @@ -39,8 +39,8 @@ end json.close # YAML section -filename = 'benchmark/subjects/ohai.yml' -yaml = File.new(filename, 'r') +filename = "benchmark/subjects/ohai.yml" +yaml = File.new(filename, "r") puts "Starting benchmark parsing #{File.size(filename)} bytes of YAML data #{times} times\n\n" Benchmark.bmbm do |x| diff --git a/lib/ffi_yajl/benchmark/parse_profile.rb b/lib/ffi_yajl/benchmark/parse_profile.rb index 6ef00ac..4b396b4 100644 --- a/lib/ffi_yajl/benchmark/parse_profile.rb +++ b/lib/ffi_yajl/benchmark/parse_profile.rb @@ -1,15 +1,15 @@ # Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario # See MIT-LICENSE -require 'rubygems' -require 'ffi_yajl' +require "rubygems" +require "ffi_yajl" begin - require 'perftools' + require "perftools" rescue LoadError puts "INFO: perftools.rb gem not installed" end -ENV['CPUPROFILE_FREQUENCY'] = "4000" +ENV["CPUPROFILE_FREQUENCY"] = "4000" module FFI_Yajl class Benchmark @@ -18,7 +18,7 @@ module FFI_Yajl return if defined?(PerfTools) filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json")) - json = File.new(filename, 'r').read + json = File.new(filename, "r").read times = 1000 puts "Starting profiling encoding #{filename} #{times} times\n\n" diff --git a/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb b/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb index 51696c5..2c4021a 100644 --- a/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb +++ b/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb @@ -1,15 +1,15 @@ # Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario # See MIT-LICENSE -require 'rubygems' -require 'ffi_yajl' +require "rubygems" +require "ffi_yajl" module FFI_Yajl class Benchmark class ParseProfileRubyProf def run begin - require 'ruby-prof' + require "ruby-prof" rescue LoadError puts "INFO: perftools.rb gem not installed" end @@ -17,7 +17,7 @@ module FFI_Yajl return if defined?(RubyProf) filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json")) - json = File.new(filename, 'r').read + json = File.new(filename, "r").read times = 1000 puts "Starting profiling encoding #{filename} #{times} times\n\n" diff --git a/lib/ffi_yajl/benchmark/parse_stream.rb b/lib/ffi_yajl/benchmark/parse_stream.rb index 679eb92..9ca0050 100644 --- a/lib/ffi_yajl/benchmark/parse_stream.rb +++ b/lib/ffi_yajl/benchmark/parse_stream.rb @@ -1,20 +1,20 @@ -$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..') -$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') +$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..") +$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib") -require 'rubygems' -require 'benchmark' -require 'yajl' +require "rubygems" +require "benchmark" +require "yajl" begin - require 'json' + require "json" rescue LoadError end begin - require 'active_support' + require "active_support" rescue LoadError end -filename = 'benchmark/subjects/twitter_stream.json' -json = File.new(filename, 'r') +filename = "benchmark/subjects/twitter_stream.json" +json = File.new(filename, "r") times = ARGV[0] ? ARGV[0].to_i : 100 puts "Starting benchmark parsing JSON stream (#{File.size(filename)} bytes of JSON data with 430 JSON separate strings) #{times} times\n\n" diff --git a/lib/ffi_yajl/encoder.rb b/lib/ffi_yajl/encoder.rb index 3b07e95..97f3e66 100644 --- a/lib/ffi_yajl/encoder.rb +++ b/lib/ffi_yajl/encoder.rb @@ -47,7 +47,7 @@ module FFI_Yajl if str.respond_to?(:scrub) str.scrub! else - str.encode!("UTF-16le", undef: :replace, invalid: :replace).encode!('UTF-8') + str.encode!("UTF-16le", undef: :replace, invalid: :replace).encode!("UTF-8") end end str @@ -68,7 +68,7 @@ module FFI_Yajl if token.respond_to?(:scrub) token.scrub! else - token.encode!("UTF-16le", undef: :replace, invalid: :replace).encode!('UTF-8') + token.encode!("UTF-16le", undef: :replace, invalid: :replace).encode!("UTF-8") end case status when 1 # yajl_gen_keys_must_be_strings diff --git a/lib/ffi_yajl/ext.rb b/lib/ffi_yajl/ext.rb index ed17e59..f7bbcfd 100644 --- a/lib/ffi_yajl/ext.rb +++ b/lib/ffi_yajl/ext.rb @@ -20,16 +20,16 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -require 'rubygems' +require "rubygems" -require 'ffi_yajl/encoder' -require 'ffi_yajl/parser' -require 'ffi_yajl/ext/dlopen' -require 'ffi_yajl/map_library_name' +require "ffi_yajl/encoder" +require "ffi_yajl/parser" +require "ffi_yajl/ext/dlopen" +require "ffi_yajl/map_library_name" # needed so the encoder c-code can find these symbols -require 'stringio' -require 'date' +require "stringio" +require "date" module FFI_Yajl extend FFI_Yajl::MapLibraryName @@ -38,12 +38,12 @@ module FFI_Yajl dlopen_yajl_library class Parser - require 'ffi_yajl/ext/parser' + require "ffi_yajl/ext/parser" include FFI_Yajl::Ext::Parser end class Encoder - require 'ffi_yajl/ext/encoder' + require "ffi_yajl/ext/encoder" include FFI_Yajl::Ext::Encoder end end diff --git a/lib/ffi_yajl/ffi.rb b/lib/ffi_yajl/ffi.rb index 3b83bae..7211c79 100644 --- a/lib/ffi_yajl/ffi.rb +++ b/lib/ffi_yajl/ffi.rb @@ -20,18 +20,18 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -require 'rubygems' +require "rubygems" -require 'libyajl2' +require "libyajl2" begin - require 'ffi' + require "ffi" rescue LoadError $stderr.puts "FATAL: to use the ffi extension instead of the compiled C extension, the ffi gem must be installed" $stderr.puts " (it is optional, so you must include it in your bundle manually)" exit 1 end -require 'ffi_yajl/map_library_name' +require "ffi_yajl/map_library_name" module FFI_Yajl extend ::FFI::Library @@ -137,17 +137,17 @@ module FFI_Yajl attach_function :yajl_gen_clear, [:yajl_gen], :void end -require 'ffi_yajl/encoder' -require 'ffi_yajl/parser' +require "ffi_yajl/encoder" +require "ffi_yajl/parser" module FFI_Yajl class Parser - require 'ffi_yajl/ffi/parser' + require "ffi_yajl/ffi/parser" include FFI_Yajl::FFI::Parser end class Encoder - require 'ffi_yajl/ffi/encoder' + require "ffi_yajl/ffi/encoder" include FFI_Yajl::FFI::Encoder end end diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb index 304c85f..f35f3c4 100644 --- a/lib/ffi_yajl/ffi/encoder.rb +++ b/lib/ffi_yajl/ffi/encoder.rb @@ -20,8 +20,8 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -require 'date' -require 'stringio' +require "date" +require "stringio" module FFI_Yajl module FFI @@ -73,7 +73,7 @@ class Hash end else if ( status = FFI_Yajl.yajl_gen_map_open(yajl_gen) ) != 0 - FFI_Yajl::Encoder.raise_error_for_status(status, '{') + FFI_Yajl::Encoder.raise_error_for_status(status, "{") end each do |key, value| # Perf Fix: mutate state hash rather than creating new copy @@ -83,7 +83,7 @@ class Hash value.ffi_yajl(yajl_gen, state) end if ( status = FFI_Yajl.yajl_gen_map_close(yajl_gen) ) != 0 - FFI_Yajl::Encoder.raise_error_for_status(status, '}') + FFI_Yajl::Encoder.raise_error_for_status(status, "}") end end end @@ -98,13 +98,13 @@ class Array end else if ( status = FFI_Yajl.yajl_gen_array_open(yajl_gen) ) != 0 - FFI_Yajl::Encoder.raise_error_for_status(status, '[') + FFI_Yajl::Encoder.raise_error_for_status(status, "[") end each do |value| value.ffi_yajl(yajl_gen, state) end if ( status = FFI_Yajl.yajl_gen_array_close(yajl_gen) ) != 0 - FFI_Yajl::Encoder.raise_error_for_status(status, ']') + FFI_Yajl::Encoder.raise_error_for_status(status, "]") end end end @@ -155,7 +155,7 @@ class FalseClass end end -class Fixnum +class Integer def ffi_yajl(yajl_gen, state) str = to_s if str == "NaN" || str == "Infinity" || str == "-Infinity" @@ -173,7 +173,7 @@ class Fixnum end end -class Bignum +class Integer def ffi_yajl(yajl_gen, state) str = to_s if str == "NaN" || str == "Infinity" || str == "-Infinity" @@ -265,7 +265,7 @@ end # I feel dirty class Object def ffi_yajl(yajl_gen, state) - if !state[:processing_key] && self.respond_to?(:to_json) + if !state[:processing_key] && respond_to?(:to_json) str = to_json(state[:json_opts]) # #yajl_gen_number outputs a string without quotes around it status = FFI_Yajl.yajl_gen_number(yajl_gen, str, str.bytesize) diff --git a/lib/ffi_yajl/ffi/parser.rb b/lib/ffi_yajl/ffi/parser.rb index 67df934..7c98d59 100644 --- a/lib/ffi_yajl/ffi/parser.rb +++ b/lib/ffi_yajl/ffi/parser.rb @@ -65,7 +65,7 @@ module FFI_Yajl end @number_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t ]) do |ctx, stringval, stringlen| s = stringval.slice(0, stringlen) - s.force_encoding('UTF-8') if defined? Encoding + s.force_encoding("UTF-8") if defined? Encoding # XXX: I can't think of a better way to do this right now. need to call to_f if and only if its a float. v = ( s =~ /[\.eE]/ ) ? s.to_f : s.to_i set_value(v) @@ -77,7 +77,7 @@ module FFI_Yajl end @string_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, stringval, stringlen| s = stringval.slice(0, stringlen) - s.force_encoding('UTF-8') if defined? Encoding + s.force_encoding("UTF-8") if defined? Encoding set_value(s) 1 end @@ -88,7 +88,7 @@ module FFI_Yajl end @map_key_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, key, keylen| s = key.slice(0, keylen) - s.force_encoding('UTF-8') if defined? Encoding + s.force_encoding("UTF-8") if defined? Encoding self.key = @opts[:symbolize_keys] ? s.to_sym : s 1 end @@ -143,12 +143,12 @@ module FFI_Yajl ::FFI_Yajl.yajl_config(yajl_handle, :yajl_allow_partial_values, :int, 1) end - if ( ::FFI_Yajl.yajl_parse(yajl_handle, str, str.bytesize) != :yajl_status_ok ) + if ::FFI_Yajl.yajl_parse(yajl_handle, str, str.bytesize) != :yajl_status_ok # FIXME: dup the error and call yajl_free_error? error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.bytesize) raise ::FFI_Yajl::ParseError, error end - if ( ::FFI_Yajl.yajl_complete_parse(yajl_handle) != :yajl_status_ok ) + if ::FFI_Yajl.yajl_complete_parse(yajl_handle) != :yajl_status_ok # FIXME: dup the error and call yajl_free_error? error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.bytesize) raise ::FFI_Yajl::ParseError, error diff --git a/lib/ffi_yajl/map_library_name.rb b/lib/ffi_yajl/map_library_name.rb index 249116e..6ec3c0c 100644 --- a/lib/ffi_yajl/map_library_name.rb +++ b/lib/ffi_yajl/map_library_name.rb @@ -20,7 +20,7 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -require 'libyajl2' +require "libyajl2" # Mixin for use in finding the right yajl library on the system. The 'caller' # needs to also mixin either the FFI module or the DLopen module. Those are @@ -36,7 +36,7 @@ module FFI_Yajl # @api private # @return Array lower case ruby host_os string def host_os - RbConfig::CONFIG['host_os'].downcase + RbConfig::CONFIG["host_os"].downcase end # Array of yajl library names on the platform. Some platforms like Windows @@ -103,7 +103,7 @@ module FFI_Yajl rescue LoadError end end - ffi_lib 'yajl' unless found + ffi_lib "yajl" unless found end end end diff --git a/lib/ffi_yajl/parser.rb b/lib/ffi_yajl/parser.rb index 6029691..2f1dbf7 100644 --- a/lib/ffi_yajl/parser.rb +++ b/lib/ffi_yajl/parser.rb @@ -65,10 +65,10 @@ module FFI_Yajl raise ArgumentError, "options check_utf8 and dont_validate_strings are both true which conflict" end - yajl_opts[:yajl_allow_comments] = true + yajl_opts[:yajl_allow_comments] = true if @opts.key?(:allow_comments) - yajl_opts[:yajl_allow_comments] = @opts[:allow_comments] + yajl_opts[:yajl_allow_comments] = @opts[:allow_comments] end yajl_opts[:yajl_dont_validate_strings] = (@opts[:check_utf8] == false || @opts[:dont_validate_strings]) diff --git a/spec/ffi_yajl/encoder_spec.rb b/spec/ffi_yajl/encoder_spec.rb index 724277b..7a76c0a 100644 --- a/spec/ffi_yajl/encoder_spec.rb +++ b/spec/ffi_yajl/encoder_spec.rb @@ -21,8 +21,8 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -require 'spec_helper' -require 'date' +require "spec_helper" +require "date" describe "FFI_Yajl::Encoder" do let(:options) { {} } @@ -30,7 +30,7 @@ describe "FFI_Yajl::Encoder" do let(:encoder) { FFI_Yajl::Encoder.new(options) } it "encodes hashes in keys as strings", ruby_gte_193: true do - ruby = { { 'a' => 'b' } => 2 } + ruby = { { "a" => "b" } => 2 } expect(encoder.encode(ruby)).to eq('{"{\"a\"=>\"b\"}":2}') end @@ -126,23 +126,23 @@ describe "FFI_Yajl::Encoder" do end it "can encode Date objects" do - ruby = Date.parse('2001-02-03') + ruby = Date.parse("2001-02-03") expect(encoder.encode(ruby)).to eq( '"2001-02-03"' ) end it "can encode StringIOs" do - ruby = { "foo" => StringIO.new('THING') } + ruby = { "foo" => StringIO.new("THING") } expect(encoder.encode(ruby)).to eq("{\"foo\":\"THING\"}") end context "when encoding Time objects in UTC timezone" do before do - @saved_tz = ENV['TZ'] - ENV['TZ'] = 'UTC' + @saved_tz = ENV["TZ"] + ENV["TZ"] = "UTC" end after do - ENV['TZ'] = @saved_tz + ENV["TZ"] = @saved_tz end it "encodes them correctly" do @@ -152,7 +152,7 @@ describe "FFI_Yajl::Encoder" do end it "can encode DateTime objects" do - ruby = DateTime.parse('2001-02-03T04:05:06.1+07:00') + ruby = DateTime.parse("2001-02-03T04:05:06.1+07:00") expect(encoder.encode(ruby)).to eq( '"2001-02-03T04:05:06+07:00"' ) end @@ -191,7 +191,7 @@ describe "FFI_Yajl::Encoder" do end context "when validate_utf8 is off" do - let(:options) { { validate_utf8: false } } + let(:options) { { validate_utf8: false } } it "does not raise an error" do expect { encoder.encode(ruby) }.not_to raise_error diff --git a/spec/ffi_yajl/map_library_name_spec.rb b/spec/ffi_yajl/map_library_name_spec.rb index 0b5e9cb..b16483f 100644 --- a/spec/ffi_yajl/map_library_name_spec.rb +++ b/spec/ffi_yajl/map_library_name_spec.rb @@ -20,7 +20,7 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -require 'spec_helper' +require "spec_helper" class Test extend FFI_Yajl::MapLibraryName @@ -107,7 +107,7 @@ describe "FFI_Yajl::MapLibraryName" do allow(File).to receive(:file?).with(path).and_return(true) allow(Test).to receive(:ffi_lib).with(path).and_raise(LoadError) end - allow(Test).to receive(:ffi_lib).with('yajl').and_return(nil) + allow(Test).to receive(:ffi_lib).with("yajl").and_return(nil) Test.send(:ffi_open_yajl_library) end end diff --git a/spec/ffi_yajl/parser_spec.rb b/spec/ffi_yajl/parser_spec.rb index 750567f..be392c8 100644 --- a/spec/ffi_yajl/parser_spec.rb +++ b/spec/ffi_yajl/parser_spec.rb @@ -21,12 +21,12 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -require 'spec_helper' +require "spec_helper" describe "FFI_Yajl::Parser" do shared_examples_for "correct json parsing" do context "when json has 23456789012E666" do - let(:json) { '{"key": 23456789012E666}' } + let(:json) { '{"key": 23456789012E666}' } it "should return infinity" do infinity = (1.0 / 0) @@ -271,10 +271,10 @@ describe "FFI_Yajl::Parser" do Encoding.default_internal = @saved_encoding end it "encodes keys to UTF-8" do - expect(parser.keys.first.encoding).to eql(Encoding.find('utf-8')) + expect(parser.keys.first.encoding).to eql(Encoding.find("utf-8")) end it "encodes values to UTF-8" do - expect(parser.values.first.encoding).to eql(Encoding.find('utf-8')) + expect(parser.values.first.encoding).to eql(Encoding.find("utf-8")) end end @@ -349,7 +349,7 @@ describe "FFI_Yajl::Parser" do # NOTE: we are choosing to be compatible with yajl-ruby here vs. JSON # gem and libyajl C behavior (which is to throw an exception in this case) context "when the JSON is empty string" do - let(:json) { '' } + let(:json) { "" } it "returns nil" do expect(parser).to be_nil @@ -475,7 +475,7 @@ describe "FFI_Yajl::Parser" do # NOTE: parsing floats with 8 million digits on windows has some kind of huge # perf issues likely in ruby and/or the underlying windows libs context "when parsing big floats", ruby_gte_193: true, unix_only: true do - let(:json) { '[0.' + '1' * 2**23 + ']' } + let(:json) { "[0." + "1" * 2**23 + "]" } it "parses" do expect { parser }.not_to raise_error @@ -483,7 +483,7 @@ describe "FFI_Yajl::Parser" do end context "when parsing long hash keys with symbolize_keys option", ruby_gte_193: true do - let(:json) { '{"' + 'a' * 2**23 + '": 0}' } + let(:json) { '{"' + "a" * 2**23 + '": 0}' } let(:options) { { symbolize_keys: true } } it "parses" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9ec853d..48e2de5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,18 +26,18 @@ $LOAD_PATH << File.expand_path(File.join(File.dirname( __FILE__ ), "../lib")) # linked in the same process). this should work, see: # http://stackoverflow.com/questions/3232822/linking-with-multiple-versions-of-a-library begin - require 'yajl' + require "yajl" rescue LoadError - puts 'WARN: yajl cannot be loaded, expected if this is jruby' + puts "WARN: yajl cannot be loaded, expected if this is jruby" end -require 'ffi_yajl' +require "ffi_yajl" RSpec.configure do |conf| conf.filter_run_excluding unix_only: true unless RUBY_PLATFORM !~ /mswin|mingw|windows/ conf.filter_run_excluding ruby_gte_193: true unless RUBY_VERSION.to_f >= 2.0 || RUBY_VERSION =~ /^1\.9\.3/ - conf.order = 'random' + conf.order = "random" conf.expect_with :rspec do |rspec| rspec.syntax = :expect -- cgit v1.2.1 From e9bfeeb2475d73ddb6b8d771559bf0fdcbd5240e Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 20 Jun 2017 15:46:23 -0700 Subject: Update travis test to run Signed-off-by: Tim Smith --- .travis.yml | 2 -- Rakefile | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8e495b2..e15f11f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: ruby sudo: false -cache: bundler dist: trusty before_install: @@ -9,7 +8,6 @@ before_install: - gem update --system - gem --version bundler_args: --without development_extras --jobs 3 --retry 3 -script: rake compile; rake spec after_success: gem install yajl-ruby; gem install json; gem install psych; FORCE_FFI_YAJL="ext" ffi-yajl-bench matrix: include: diff --git a/Rakefile b/Rakefile index 331b3fd..216cae1 100644 --- a/Rakefile +++ b/Rakefile @@ -132,4 +132,4 @@ desc "Run style + spec tests by default on travis" task travis: %w{style spec} desc "Run style + spec tests by default" -task default: %w{style spec} +task default: %w{compile style spec} -- cgit v1.2.1 From 5582e48635d95161013846fc76a7e76bb8bf879c Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 20 Jun 2017 15:48:37 -0700 Subject: All non-standard rubies to fail Signed-off-by: Tim Smith --- .travis.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.travis.yml b/.travis.yml index e15f11f..55b80b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,21 @@ matrix: jdk: oraclejdk8 - rvm: jruby-head jdk: openjdk7 + allow_failures: + - rvm: ruby-head + - rvm: rbx + - rvm: jruby + jdk: oraclejdk7 + - rvm: jruby + jdk: oraclejdk8 + - rvm: jruby + jdk: openjdk7 + - rvm: jruby-head + jdk: oraclejdk7 + - rvm: jruby-head + jdk: oraclejdk8 + - rvm: jruby-head + jdk: openjdk7 branches: only: -- cgit v1.2.1