| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
gemspec = Gem::Specification.find_all_by_name("nokogiri").sort_by(&:version).last |
| 18 |
raise "could not find installed gem" unless gemspec |
| 19 |
|
| 20 |
require "bundler/inline" |
| 21 |
|
| 22 |
gemfile do |
| 23 |
source "https://rubygems.org" |
| 24 |
gem "minitest" |
| 25 |
gem "nokogiri" |
| 26 |
end |
| 27 |
|
| 28 |
require "nokogiri" |
| 29 |
require "yaml" |
| 30 |
|
| 31 |
puts "---------- Nokogiri version info ----------" |
| 32 |
puts Nokogiri::VERSION_INFO.to_yaml |
| 33 |
puts |
| 34 |
|
| 35 |
if ARGV.include?("-v") |
| 36 |
puts "---------- Nokogiri installed gemspec ----------" |
| 37 |
puts gemspec.to_ruby |
| 38 |
puts |
| 39 |
end |
| 40 |
|
| 41 |
require "minitest/autorun" |
| 42 |
|
| 43 |
puts "Testing #{gemspec.full_name} installed in #{gemspec.base_dir}" |
| 44 |
describe gemspec.full_name do |
| 45 |
let(:ruby_maj_min) { Gem::Version.new(RUBY_VERSION).segments[0..1].join(".") } |
| 46 |
let(:nokogiri_lib_dir) { File.join(gemspec.gem_dir, "lib/nokogiri") } |
| 47 |
let(:nokogiri_ext_dir) { File.join(gemspec.gem_dir, "ext/nokogiri") } |
| 48 |
let(:nokogiri_include_dir) { File.join(nokogiri_ext_dir, "include") } |
| 49 |
|
| 50 |
|
| 51 |
let(:nokogiri_header_files) { ["nokogiri.h"] } |
| 52 |
let(:packaged_library_header_files) { ["libxml2/libxml/tree.h", "libxslt/xslt.h", "libexslt/exslt.h"] } |
| 53 |
|
| 54 |
let(:headers_dirs) { Nokogiri::VERSION_INFO["nokogiri"]["cppflags"].map { |f| f.gsub(/^-I/, "") } } |
| 55 |
|
| 56 |
it "loads the same version as the spec we've loaded" do |
| 57 |
assert_equal(Nokogiri::VERSION, gemspec.version.to_s) |
| 58 |
end |
| 59 |
|
| 60 |
describe "cruby" do |
| 61 |
it "installs nokogiri headers" do |
| 62 |
nokogiri_header_files.each do |header| |
| 63 |
assert( |
| 64 |
File.file?(File.join(nokogiri_ext_dir, header)), |
| 65 |
"expected #{header} to be installed in #{nokogiri_ext_dir}", |
| 66 |
) |
| 67 |
|
| 68 |
found = false |
| 69 |
headers_dirs.each do |header_dir| |
| 70 |
found = true if File.file?(File.join(header_dir, "nokogiri.h")) |
| 71 |
end |
| 72 |
assert(found, "expected to find nokogiri.h in one of: #{headers_dirs.inspect}") |
| 73 |
end |
| 74 |
end |
| 75 |
|
| 76 |
describe "native platform" do |
| 77 |
it "declares packaged, precompiled libraries" do |
| 78 |
assert(Nokogiri::VersionInfo.instance.libxml2_using_packaged?) |
| 79 |
assert(Nokogiri::VERSION_INFO["libxml"].key?("source")) |
| 80 |
assert_equal("packaged", Nokogiri::VERSION_INFO["libxml"]["source"]) |
| 81 |
|
| 82 |
assert(Nokogiri::VersionInfo.instance.libxml2_precompiled?) |
| 83 |
assert(Nokogiri::VERSION_INFO["libxml"].key?("precompiled")) |
| 84 |
assert(Nokogiri::VERSION_INFO["libxml"]["precompiled"]) |
| 85 |
end |
| 86 |
end if gemspec.platform.is_a?(Gem::Platform) && gemspec.platform.cpu |
| 87 |
|
| 88 |
describe "library" do |
| 89 |
describe "packaged" do |
| 90 |
describe "for third-party library linking" do |
| 91 |
it "installs packaged libraries' headers" do |
| 92 |
packaged_library_header_files.each do |header| |
| 93 |
assert( |
| 94 |
File.file?(File.join(nokogiri_include_dir, header)), |
| 95 |
"expected #{header} to be installed in #{nokogiri_include_dir}", |
| 96 |
) |
| 97 |
end |
| 98 |
end |
| 99 |
end |
| 100 |
|
| 101 |
it "points to packaged libraries' headers" do |
| 102 |
packaged_library_header_files.each do |header| |
| 103 |
found = false |
| 104 |
headers_dirs.each do |header_dir| |
| 105 |
found = true if File.file?(File.join(header_dir, header)) |
| 106 |
end |
| 107 |
assert(found, "expected to find #{header} in one of: #{headers_dirs.inspect}") |
| 108 |
end |
| 109 |
end |
| 110 |
|
| 111 |
it "has ldflags pointing to the shared object file" do |
| 112 |
ldflags = Nokogiri::VERSION_INFO["nokogiri"]["ldflags"] |
| 113 |
if RUBY_PLATFORM.match?(/mingw|mswin/) |
| 114 |
if gemspec.platform.is_a?(Gem::Platform) && gemspec.platform.cpu |
| 115 |
assert_includes(ldflags, "-L#{File.join(nokogiri_lib_dir, ruby_maj_min)}") |
| 116 |
else |
| 117 |
assert_includes(ldflags, "-L#{nokogiri_lib_dir}") |
| 118 |
end |
| 119 |
assert_includes(ldflags, "-l:nokogiri.so") |
| 120 |
else |
| 121 |
assert_empty(ldflags) |
| 122 |
end |
| 123 |
end |
| 124 |
end if Nokogiri::VersionInfo.instance.libxml2_using_packaged? |
| 125 |
|
| 126 |
describe "using system libraries" do |
| 127 |
it "doesn't declare where headers are installed" do |
| 128 |
refute(Nokogiri::VERSION_INFO["libxml"].key?("libxml2_path")) |
| 129 |
end |
| 130 |
|
| 131 |
it "does not install packaged libraries' headers" do |
| 132 |
packaged_library_header_files.each do |header| |
| 133 |
dir = File.join(nokogiri_include_dir, File.dirname(header)) |
| 134 |
refute(File.directory?(dir), "expected directory #{dir} to not exist") |
| 135 |
end |
| 136 |
end |
| 137 |
end unless Nokogiri::VersionInfo.instance.libxml2_using_packaged? |
| 138 |
end |
| 139 |
end unless gemspec.platform == Gem::Platform.new("java") |
| 140 |
end |