diff --git a/.travis.yml b/.travis.yml index 236192b..b6ebdae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,15 @@ language: ruby rvm: - 2.1.0 - 2.2.0 - 2.3.0 +- 2.4.0 env: global: - secure: A03DrflHssgYH/ekZlQUbp93B2aaFszXiiSQDxv1mm9oabuQuAQn+aGZmp1v1eA8SdSVu2PAeWNAUXFTAkgIbxRFUScsdbMyG2hdDiAie9t581PRdcRgcPWDPAoigj1xTgI9dbBTljlIJXQZ6+DuI3SpajfV8rksxRjqlgE5aec= - secure: fcBXclhQt2XL2iXQC6b3WVa6KGiWqboZK6AWFq2u1o53WK3Wz7eeG2OJwYakJvr23h4U2vvsTbMRT8fen6HXnywOHqPm83qQ6YdukoO5ky95s0zNFtVNn8Nj+ulZveb+zb+DlzXwuOUTSaBfgY0bN3XR12lM9b8qLy5UlZNGlNI= notifications: irc: "chat.freenode.net#kubuntu-ci" before_install: - sudo apt-get -qq update - sudo apt-get install -y gnupg2 diff --git a/lib/requirement_checker.rb b/lib/requirement_checker.rb index c2ba63c..8efcc85 100644 --- a/lib/requirement_checker.rb +++ b/lib/requirement_checker.rb @@ -1,48 +1,53 @@ class RequirementChecker - COMPATIBLE_RUBIES = %w(2.1.0 2.2.0 2.3.0) + # NOTE: The versions are restricted upwards because behavior changes in the + # language can result in unexpected outcome when using releaseme. i.e. + # you may end up with a broken or malformed tar. To prevent this, a change + # here must be followed by running `rake test` to pass the entire test suite! + # Also see the section on bumping versions in the REAMDE. + COMPATIBLE_RUBIES = %w(2.1.0 2.2.0 2.3.0 2.4.0) REQUIRED_BINARIES = %w(svn git tar xz msgfmt gpg2) def initialize @ruby_version = RUBY_VERSION end def check err = false unless ruby_compatible? puts "- Ruby #{COMPATIBLE_RUBIES.join(' or ')} required." puts " Currently using: #{@ruby_version}" err = true end missing_binaries.each do |m| puts "- Missing binary: #{m}." err = true end fail 'Not all requirements met.' if err end private def ruby_compatible? COMPATIBLE_RUBIES.each do |v| return true if compatible?(v) end false end def missing_binaries missing_binaries = [] REQUIRED_BINARIES.each do |r| missing_binaries << missing(r) end missing_binaries.compact end def compatible?(a) Gem::Dependency.new('', "~> #{a}").match?('', @ruby_version) end def missing(bin) return bin unless system("type #{bin} > /dev/null 2>&1") nil end end diff --git a/test/test_requirement_checker.rb b/test/test_requirement_checker.rb index ddbb7b6..52db9eb 100644 --- a/test/test_requirement_checker.rb +++ b/test/test_requirement_checker.rb @@ -1,75 +1,77 @@ require 'fileutils' require_relative 'lib/testme' require_relative '../lib/requirement_checker' class TestRequirementChecker < Testme def assert_ruby_version_compatible(version) checker = RequirementChecker.new checker.instance_variable_set(:@ruby_version, version) assert(checker.send(:ruby_compatible?), "Ruby version #{version} NOT compatible but should be") end def assert_ruby_version_not_compatible(version) checker = RequirementChecker.new checker.instance_variable_set(:@ruby_version, version) assert(!checker.send(:ruby_compatible?), "Ruby version #{version} compatible but should not be") assert_raise { checker.check } end def with_path(path) orig_path = ENV.fetch('PATH') ENV['PATH'] = path yield ensure ENV['PATH'] = orig_path if orig_path end def test_versions compatibles = %w( 2.1 2.1.0 2.1.1 2.2 2.2.0 2.2.1 2.3 2.3.1 + 2.4 + 2.4.1 ) compatibles.each { |i| assert_ruby_version_compatible(i) } incompatibles = %w( 1.9.0 2.0 2.0.99 - 2.4 - 2.4.1 + 2.5 + 2.5.1 ) incompatibles.each { |i| assert_ruby_version_not_compatible(i) } end def all_binaries RequirementChecker.const_get(:REQUIRED_BINARIES) end def test_missing_binaries with_path('') do checker = RequirementChecker.new missing_binaries = checker.send(:missing_binaries) expected_missing_binaries = all_binaries assert_equal(expected_missing_binaries, missing_binaries) assert_raise { checker.check } end end def test_existing_binaries FileUtils.touch(all_binaries) FileUtils.chmod('+x', all_binaries) with_path(Dir.pwd) do missing_binaries = RequirementChecker.new.send(:missing_binaries) assert_equal([], missing_binaries) end end end