Skip to content

Commit

Permalink
test_default_gems.rb: Stop using git ls-files
Browse files Browse the repository at this point in the history
Just validate syntax and the result class instead.

Not only `git ls-files` doesn't make sence under ruby's repository,
some gemspec files hardcode `2>/dev/null`, which doesn't work of
course on other than Unix-like platforms.
  • Loading branch information
nobu committed May 4, 2023
1 parent 2f9f44f commit caa2180
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/ruby/test_default_gems.rb
Expand Up @@ -2,22 +2,26 @@
require 'rubygems'

class TestDefaultGems < Test::Unit::TestCase
def self.load(file)
code = File.read(file, mode: "r:UTF-8:-", &:read)

# - `git ls-files` is useless under ruby's repository
# - `2>/dev/null` works only on Unix-like platforms
code.gsub!(/`git.*?`/, '""')

eval(code, binding, file)
end

def test_validate_gemspec
srcdir = File.expand_path('../../..', __FILE__)
specs = 0
Dir.chdir(srcdir) do
unless system("git", "rev-parse", %i[out err]=>IO::NULL)
omit "git not found"
end
Dir.glob("#{srcdir}/{lib,ext}/**/*.gemspec").map do |src|
specs += 1
assert_nothing_raised do
raise("invalid spec in #{src}") unless Gem::Specification.load(src)
end
assert_kind_of(Gem::Specification, self.class.load(src), "invalid spec in #{src}")
end
end
assert specs > 0, "gemspecs not found"
assert_operator specs, :>, 0, "gemspecs not found"
end

end

0 comments on commit caa2180

Please sign in to comment.