Adding linguist_vendored? and linguist_generated? to include overrides from .gitattributes

This commit is contained in:
Arfon Smith
2014-09-24 19:57:30 -05:00
parent 178d4756ef
commit f87436d499
3 changed files with 39 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
require 'linguist/repository'
require 'linguist/lazy_blob'
require 'test/unit'
require 'pry'
class TestRepository < Test::Unit::TestCase
def rugged_repository
@rugged ||= Rugged::Repository.new(File.expand_path("../../.git", __FILE__))
@@ -47,13 +48,15 @@ class TestRepository < Test::Unit::TestCase
assert_equal linguist_repo.cache, new_repo.cache
end
def test_git_attributes
# See https://github.com/github/linguist/blob/525304738ebdb7ab3b7d2bf9a7514cc428faa273/.gitattributes
def test_repo_git_attributes
# See https://github.com/github/linguist/blob/3770a90251c8a940367300c9f6f97bb64b369bf8/.gitattributes
#
# It looks like this:
# test/*.rb linguist-ignore
# lib/linguist.rb linguist-lang=Java
attr_commit = '525304738ebdb7ab3b7d2bf9a7514cc428faa273'
# test/*.rb linguist-vendored
# lib/linguist.rb linguist-language=Java
# lib/linguist/classifier.rb linguist-generated
attr_commit = '178d4756efb647d5f8607d74fe47a852329d7516'
repo = linguist_repo(attr_commit)
assert repo.breakdown_by_file.has_key?("Java")
@@ -62,7 +65,27 @@ class TestRepository < Test::Unit::TestCase
assert repo.breakdown_by_file.has_key?("Ruby")
assert !repo.breakdown_by_file["Ruby"].empty?
repo.breakdown_by_file["Ruby"].each do |file|
assert !file.start_with?("test/")
assert !file.start_with?("test/"), "Failing for #{file}"
end
end
def test_linguist_generated?
attr_commit = '178d4756efb647d5f8607d74fe47a852329d7516'
file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'lib/linguist/classifier.rb')
# overridden in .gitattributes
assert file.linguist_generated?
# from lib/linguist/generated.rb
assert !file.generated?
end
def test_linguist_vendored?
attr_commit = '178d4756efb647d5f8607d74fe47a852329d7516'
file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'test/test_md5.rb')
# overridden .gitattributes
assert file.linguist_vendored?
# from lib/linguist/vendor.yml
assert !file.vendored?
end
end