ffi-yajl 2.3.1-universal-java → 2.3.3-universal-java

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile DELETED
@@ -1,139 +0,0 @@
1
- $LOAD_PATH << File.expand_path(File.join(File.dirname( __FILE__ ), "lib"))
2
-
3
- require "rspec/core/rake_task"
4
- require "rubygems/package_task"
5
- require "rake/extensiontask"
6
- require "ffi_yajl/version"
7
-
8
- Dir[File.expand_path("../*gemspec", __FILE__)].reverse_each do |gemspec_path|
9
- gemspec = eval(IO.read(gemspec_path))
10
- Gem::PackageTask.new(gemspec).define
11
- end
12
-
13
- begin
14
- require "github_changelog_generator/task"
15
- GitHubChangelogGenerator::RakeTask.new :changelog do |config|
16
- config.issues = false
17
- config.since_tag = "1.0.1"
18
- config.exclude_labels = %w{duplicate question invalid wontfix changelog_skip}
19
- end
20
- rescue LoadError
21
- puts "no github-changelog-generator"
22
- end
23
-
24
- desc "Build it and ship it"
25
- task ship: [:clean, :gem] do
26
- sh("git tag #{FFI_Yajl::VERSION}")
27
- sh("git push --tags")
28
- Dir[File.expand_path("../pkg/*.gem", __FILE__)].reverse_each do |built_gem|
29
- sh("gem push #{built_gem}")
30
- end
31
- end
32
-
33
- unix_gemspec = eval(File.read("ffi-yajl.gemspec"))
34
-
35
- task :clean do
36
- sh "rm -f Gemfile.lock"
37
- sh "rm -rf pkg/* tmp/* .bundle lib/ffi_yajl/ext/*"
38
- end
39
-
40
- desc "install the gem locally"
41
- task install: [:package] do
42
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
43
- sh %{gem install pkg/#{unix_gemspec.name}-#{unix_gemspec.version}-universal-java.gem}
44
- else
45
- sh %{gem install pkg/#{unix_gemspec.name}-#{unix_gemspec.version}.gem}
46
- end
47
- end
48
-
49
- spec = Gem::Specification.load("ffi-yajl.gemspec")
50
-
51
- Rake::ExtensionTask.new do |ext|
52
- ext.name = "encoder"
53
- ext.lib_dir = "lib/ffi_yajl/ext"
54
- ext.ext_dir = "ext/ffi_yajl/ext/encoder"
55
- ext.gem_spec = spec
56
- end
57
-
58
- Rake::ExtensionTask.new do |ext|
59
- ext.name = "parser"
60
- ext.lib_dir = "lib/ffi_yajl/ext"
61
- ext.ext_dir = "ext/ffi_yajl/ext/parser"
62
- ext.gem_spec = spec
63
- end
64
-
65
- Rake::ExtensionTask.new do |ext|
66
- ext.name = "dlopen"
67
- ext.lib_dir = "lib/ffi_yajl/ext"
68
- ext.ext_dir = "ext/ffi_yajl/ext/dlopen"
69
- ext.gem_spec = spec
70
- end
71
-
72
- #
73
- # test tasks
74
- #
75
-
76
- desc "Run all specs against both extensions"
77
- task :spec do
78
- Rake::Task["spec:ffi"].invoke
79
- if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/
80
- Rake::Task["spec:ext"].invoke
81
- end
82
- end
83
-
84
- namespace :spec do
85
- desc "Run all specs against ffi extension"
86
- RSpec::Core::RakeTask.new(:ffi) do |t|
87
- ENV["FORCE_FFI_YAJL"] = "ffi"
88
- t.pattern = FileList["spec/**/*_spec.rb"]
89
- end
90
- if !defined?(RUBY_ENGINE) || RUBY_ENGINE !~ /jruby/
91
- desc "Run all specs again c extension"
92
- RSpec::Core::RakeTask.new(:ext) do |t|
93
- ENV["FORCE_FFI_YAJL"] = "ext"
94
- t.pattern = FileList["spec/**/*_spec.rb"]
95
- end
96
- end
97
- end
98
-
99
- namespace :integration do
100
- begin
101
- require "kitchen"
102
- rescue LoadError
103
- task :vagrant do
104
- puts "test-kitchen gem is not installed"
105
- end
106
- else
107
- desc "Run Test Kitchen with Vagrant"
108
- task :vagrant do
109
- Kitchen.logger = Kitchen.default_file_logger
110
- Kitchen::Config.new.instances.each do |instance|
111
- instance.test(:always)
112
- end
113
- end
114
- end
115
- end
116
- namespace :style do
117
- desc "Run Ruby style checks"
118
- begin
119
- require "chefstyle"
120
- require "rubocop/rake_task"
121
- rescue LoadError
122
- task :rubocop do
123
- puts "chefstyle gem is not installed"
124
- end
125
- else
126
- RuboCop::RakeTask.new(:rubocop) do |t|
127
- t.fail_on_error = false
128
- end
129
- end
130
- end
131
-
132
- desc "Run all style checks"
133
- task style: ["style:rubocop"]
134
-
135
- desc "Run style + spec tests by default on travis"
136
- task travis: %w{style spec}
137
-
138
- desc "Run style + spec tests by default"
139
- task default: %w{compile style spec}
@@ -1,221 +0,0 @@
1
- # encoding: UTF-8
2
- # Copyright (c) 2015 Lamont Granquist
3
- # Copyright (c) 2015 Chef Software, Inc.
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining
6
- # a copy of this software and associated documentation files (the
7
- # "Software"), to deal in the Software without restriction, including
8
- # without limitation the rights to use, copy, modify, merge, publish,
9
- # distribute, sublicense, and/or sell copies of the Software, and to
10
- # permit persons to whom the Software is furnished to do so, subject to
11
- # the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be
14
- # included in all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
-
24
- require "spec_helper"
25
- require "date"
26
-
27
- describe "FFI_Yajl::Encoder" do
28
- let(:options) { {} }
29
-
30
- let(:encoder) { FFI_Yajl::Encoder.new(options) }
31
-
32
- it "encodes hashes in keys as strings", ruby_gte_193: true do
33
- ruby = { { "a" => "b" } => 2 }
34
- expect(encoder.encode(ruby)).to eq('{"{\"a\"=>\"b\"}":2}')
35
- end
36
-
37
- it "encodes arrays in keys as strings", ruby_gte_193: true do
38
- ruby = { [0, 1] => 2 }
39
- expect(encoder.encode(ruby)).to eq('{"[0, 1]":2}')
40
- end
41
-
42
- it "encodes nil in keys as strings" do
43
- ruby = { nil => 2 }
44
- expect(encoder.encode(ruby)).to eq('{"":2}')
45
- end
46
-
47
- it "encodes true in keys as strings" do
48
- ruby = { true => 2 }
49
- expect(encoder.encode(ruby)).to eq('{"true":2}')
50
- end
51
-
52
- it "encodes false in keys as strings" do
53
- ruby = { false => 2 }
54
- expect(encoder.encode(ruby)).to eq('{"false":2}')
55
- end
56
-
57
- it "encodes fixnums in keys as strings" do
58
- ruby = { 1 => 2 }
59
- expect(encoder.encode(ruby)).to eq('{"1":2}')
60
- end
61
-
62
- it "encodes floats in keys as strings" do
63
- ruby = { 1.1 => 2 }
64
- expect(encoder.encode(ruby)).to eq('{"1.1":2}')
65
- end
66
-
67
- it "encodes bignums in keys as strings" do
68
- ruby = { 12_345_678_901_234_567_890 => 2 }
69
- expect(encoder.encode(ruby)).to eq('{"12345678901234567890":2}')
70
- end
71
-
72
- it "encodes objects in keys as strings" do
73
- o = Object.new
74
- ruby = { o => 2 }
75
- expect(encoder.encode(ruby)).to eq(%{{"#{o}":2}})
76
- end
77
-
78
- it "encodes an object in a key which has a #to_json method as strings" do
79
- class Thing
80
- def to_json(*a)
81
- "{}"
82
- end
83
- end
84
- o = Thing.new
85
- ruby = { o => 2 }
86
- expect(encoder.encode(ruby)).to eq(%{{"#{o}":2}})
87
- end
88
-
89
- # XXX: 127 == YAJL_MAX_DEPTH hardcodedness, zero control for us, it isn't even a twiddleable #define
90
- it "raises an exception for deeply nested arrays" do
91
- root = []
92
- a = root
93
- 127.times { |_| a << []; a = a[0] }
94
- expect { encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
95
- end
96
-
97
- it "raises an exception for deeply nested hashes" do
98
- root = {}
99
- a = root
100
- 127.times { |_| a["a"] = {}; a = a["a"] }
101
- expect { encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
102
- end
103
-
104
- it "encodes symbols in keys as strings" do
105
- ruby = { thing: 1 }
106
- expect(encoder.encode(ruby)).to eq('{"thing":1}')
107
- end
108
-
109
- it "encodes symbols in values as strings" do
110
- ruby = { "thing" => :one }
111
- expect(encoder.encode(ruby)).to eq('{"thing":"one"}')
112
- end
113
-
114
- it "can encode 32-bit unsigned ints" do
115
- ruby = { "gid" => 4_294_967_294 }
116
- expect(encoder.encode(ruby)).to eq('{"gid":4294967294}')
117
- end
118
-
119
- context "when the encoder has nil passed in for options" do
120
- let(:encoder) { FFI_Yajl::Encoder.new(nil) }
121
-
122
- it "does not throw an exception" do
123
- ruby = { "foo" => "bar" }
124
- expect(encoder.encode(ruby)).to eq("{\"foo\":\"bar\"}")
125
- end
126
- end
127
-
128
- it "can encode Date objects" do
129
- ruby = Date.parse("2001-02-03")
130
- expect(encoder.encode(ruby)).to eq( '"2001-02-03"' )
131
- end
132
-
133
- it "can encode StringIOs" do
134
- ruby = { "foo" => StringIO.new("THING") }
135
- expect(encoder.encode(ruby)).to eq("{\"foo\":\"THING\"}")
136
- end
137
-
138
- context "when encoding Time objects in UTC timezone" do
139
- before do
140
- @saved_tz = ENV["TZ"]
141
- ENV["TZ"] = "UTC"
142
- end
143
-
144
- after do
145
- ENV["TZ"] = @saved_tz
146
- end
147
-
148
- it "encodes them correctly" do
149
- ruby = Time.local(2001, 02, 02, 21, 05, 06)
150
- expect(encoder.encode(ruby)).to eq( '"2001-02-02 21:05:06 +0000"' )
151
- end
152
- end
153
-
154
- it "can encode DateTime objects" do
155
- ruby = DateTime.parse("2001-02-03T04:05:06.1+07:00")
156
- expect(encoder.encode(ruby)).to eq( '"2001-02-03T04:05:06+07:00"' )
157
- end
158
-
159
- describe "testing .to_json for Objects" do
160
- class NoToJson; end
161
- class HasToJson
162
- def to_json(*args)
163
- "{}"
164
- end
165
- end
166
-
167
- it "calls .to_s for objects without .to_json" do
168
- expect(encoder.encode(NoToJson.new)).to match(/^"#<NoToJson:\w+>"$/)
169
- end
170
-
171
- it "calls .to_json for objects wit .to_json" do
172
- expect(encoder.encode(HasToJson.new)).to eq("{}")
173
- end
174
- end
175
-
176
- context "when encoding invalid utf-8" do
177
- ruby = {
178
- "automatic" => {
179
- "etc" => {
180
- "passwd" => {
181
- "root" => { "dir" => "/root", "gid" => 0, "uid" => 0, "shell" => "/bin/sh", "gecos" => "Elan Ruusam\xc3\xa4e" },
182
- "glen" => { "dir" => "/home/glen", "gid" => 500, "uid" => 500, "shell" => "/bin/bash", "gecos" => "Elan Ruusam\xE4e" },
183
- "helmüt" => { "dir" => "/home/helmüt", "gid" => 500, "uid" => 500, "shell" => "/bin/bash", "gecos" => "Hañs Helmüt" },
184
- },
185
- },
186
- },
187
- }
188
-
189
- it "raises an error on invalid json" do
190
- expect { encoder.encode(ruby) }.to raise_error(FFI_Yajl::EncodeError, /Invalid UTF-8 string 'Elan Ruusam.*': cannot encode to UTF-8/)
191
- end
192
-
193
- context "when validate_utf8 is off" do
194
- let(:options) { { validate_utf8: false } }
195
-
196
- it "does not raise an error" do
197
- expect { encoder.encode(ruby) }.not_to raise_error
198
- end
199
-
200
- it "returns utf8" do
201
- expect( encoder.encode(ruby).encoding ).to eq(Encoding::UTF_8)
202
- end
203
-
204
- it "returns valid utf8" do
205
- expect( encoder.encode(ruby).valid_encoding? ).to be true
206
- end
207
-
208
- it "does not mangle valid utf8" do
209
- json = encoder.encode(ruby)
210
- expect(json).to match(/Hañs Helmüt/)
211
- end
212
-
213
- it "does not grow after a round trip" do
214
- json = encoder.encode(ruby)
215
- ruby2 = FFI_Yajl::Parser.parse(json)
216
- json2 = encoder.encode(ruby2)
217
- expect(json).to eql(json2)
218
- end
219
- end
220
- end
221
- end
@@ -1,115 +0,0 @@
1
- # Copyright (c) 2015 Lamont Granquist
2
- # Copyright (c) 2015 Chef Software, Inc.
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
-
23
- require "spec_helper"
24
-
25
- class Test
26
- extend FFI_Yajl::MapLibraryName
27
- end
28
-
29
- host_os_library_name_mapping = {
30
- "mingw" => [ "libyajl.so", "yajl.dll" ],
31
- "mswin" => [ "libyajl.so", "yajl.dll" ],
32
- "cygwin" => [ "libyajl.so", "cygyajl.dll" ],
33
- "darwin" => [ "libyajl.bundle", "libyajl.dylib" ],
34
- "solaris2" => [ "libyajl.so" ],
35
- "linux" => [ "libyajl.so" ],
36
- "aix" => [ "libyajl.so" ],
37
- "hpux" => [ "libyajl.so" ],
38
- "netbsd" => [ "libyajl.so" ],
39
- "openbsd" => [ "libyajl.so" ],
40
- "freebsd" => [ "libyajl.so" ],
41
- }
42
-
43
- describe "FFI_Yajl::MapLibraryName" do
44
- let(:libyajl2_opt_path) { "/libyajl2/lib" }
45
- before do
46
- allow(Libyajl2).to receive(:opt_path).and_return(libyajl2_opt_path)
47
- end
48
-
49
- host_os_library_name_mapping.each do |host_os, library_names|
50
- context "#library_names" do
51
- it "maps #{host_os} correctly" do
52
- allow(Test).to receive(:host_os).and_return(host_os)
53
- expect(Test.send(:library_names)).to eq(library_names)
54
- end
55
- end
56
-
57
- context "#expanded_library_names" do
58
- it "maps #{host_os} correctly" do
59
- allow(Test).to receive(:host_os).and_return(host_os)
60
- expanded_library_names = []
61
- library_names.each do |library_name|
62
- path = File.expand_path(File.join(libyajl2_opt_path, library_name))
63
- expanded_library_names.push(path)
64
- expect(File).to receive(:file?).with(path).and_return(true)
65
- end
66
- expect(Test.send(:expanded_library_names)).to eq(expanded_library_names)
67
- end
68
- end
69
-
70
- context "#dlopen_yajl_library" do
71
- it "should call dlopen against an expanded library name if it finds it on #{host_os}" do
72
- allow(Test).to receive(:host_os).and_return(host_os)
73
- library_names.each do |library_name|
74
- path = File.expand_path(File.join(libyajl2_opt_path, library_name))
75
- allow(File).to receive(:file?).with(path).and_return(true)
76
- allow(Test).to receive(:dlopen).with(path).and_return(nil)
77
- end
78
- Test.send(:dlopen_yajl_library)
79
- end
80
- it "if dlopen calls all raise it should still use the short names on #{host_os}" do
81
- allow(Test).to receive(:host_os).and_return(host_os)
82
- library_names.each do |library_name|
83
- path = File.expand_path(File.join(libyajl2_opt_path, library_name))
84
- allow(File).to receive(:file?).with(path).and_return(true)
85
- allow(Test).to receive(:dlopen).with(path).and_raise(ArgumentError)
86
- end
87
- allow(Test).to receive(:dlopen).with(library_names.first).and_return(nil)
88
- Test.send(:dlopen_yajl_library)
89
- end
90
- end
91
-
92
- context "ffi_open_yajl_library" do
93
- it "should call ffi_lib against an expanded library name if it finds it on #{host_os}" do
94
- allow(Test).to receive(:host_os).and_return(host_os)
95
- library_names.each do |library_name|
96
- path = File.expand_path(File.join(libyajl2_opt_path, library_name))
97
- allow(File).to receive(:file?).with(path).and_return(true)
98
- allow(Test).to receive(:ffi_lib).with(path).and_return(nil)
99
- end
100
- Test.send(:ffi_open_yajl_library)
101
- end
102
-
103
- it "if dlopen calls all raise it should still use 'yajl' on #{host_os}" do
104
- allow(Test).to receive(:host_os).and_return(host_os)
105
- library_names.each do |library_name|
106
- path = File.expand_path(File.join(libyajl2_opt_path, library_name))
107
- allow(File).to receive(:file?).with(path).and_return(true)
108
- allow(Test).to receive(:ffi_lib).with(path).and_raise(LoadError)
109
- end
110
- allow(Test).to receive(:ffi_lib).with("yajl").and_return(nil)
111
- Test.send(:ffi_open_yajl_library)
112
- end
113
- end
114
- end
115
- end