Skip to content

Commit

Permalink
add test coverage for VersionInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Apr 28, 2019
1 parent d48f500 commit 4df37a2
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/test_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require "helper"
require "rbconfig"
require "json"

module TestVersionInfoTests
#
# This module is mixed into test classes below so that the tests
# are validated when `nokogiri.rb` is required and when
# `nokogiri/version.rb` is required. See #1896 for background.
#
def test_version_info_for_xerces
skip "xerces is only used for JRuby" unless Nokogiri.jruby?
assert_equal @version_info["xerces"], Nokogiri::VERSION_INFO["xerces"]
end

def test_version_info_for_nekohtml
skip "nekohtml is only used for JRuby" unless Nokogiri.jruby?
assert_equal @version_info["nekohtml"], Nokogiri::VERSION_INFO["nekohtml"]
end

def test_version_info_for_libxml
skip "libxml2 is only used for CRuby" unless Nokogiri.uses_libxml?
assert_equal @version_info["libxml"]["compiled"], Nokogiri::LIBXML_VERSION
end
end

class TestVersionInfo
RUBYEXEC = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["RUBY_INSTALL_NAME"])
ROOTDIR = File.expand_path(File.join(File.dirname(__FILE__), ".."))

class Base < Nokogiri::TestCase
def setup
super
version_info = Dir.chdir(ROOTDIR) do
`#{RUBYEXEC} -Ilib -rjson -r#{@require_me} -e 'puts Nokogiri::VERSION_INFO.to_json'`
end
@version_info = JSON.parse version_info
end
end

class RequireNokogiri < TestVersionInfo::Base
include TestVersionInfoTests

def setup
@require_me = "nokogiri"
super
end
end

class RequireVersionFileOnly < TestVersionInfo::Base
include TestVersionInfoTests

def setup
@require_me = "nokogiri/version"
super
end
end
end

0 comments on commit 4df37a2

Please sign in to comment.