mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-09 02:45:33 +00:00
Merge master
This commit is contained in:
22
test/fixtures/Python/run_tests.module
vendored
Normal file
22
test/fixtures/Python/run_tests.module
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
import sys, os
|
||||
|
||||
# Set the current working directory to the directory where this script is located
|
||||
os.chdir(os.path.abspath(os.path.dirname(sys.argv[0])))
|
||||
|
||||
#### Set the name of the application here and moose directory relative to the application
|
||||
app_name = 'stork'
|
||||
|
||||
MODULE_DIR = os.path.abspath('..')
|
||||
MOOSE_DIR = os.path.abspath(os.path.join(MODULE_DIR, '..'))
|
||||
#### See if MOOSE_DIR is already in the environment instead
|
||||
if os.environ.has_key("MOOSE_DIR"):
|
||||
MOOSE_DIR = os.environ['MOOSE_DIR']
|
||||
|
||||
sys.path.append(os.path.join(MOOSE_DIR, 'python'))
|
||||
import path_tool
|
||||
path_tool.activate_module('TestHarness')
|
||||
|
||||
from TestHarness import TestHarness
|
||||
# Run the tests!
|
||||
TestHarness.buildAndRun(sys.argv, app_name, MOOSE_DIR)
|
||||
1505
test/fixtures/Shell/mintleaf.module
vendored
Normal file
1505
test/fixtures/Shell/mintleaf.module
vendored
Normal file
File diff suppressed because it is too large
Load Diff
4
test/helper.rb
Normal file
4
test/helper.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
require "bundler/setup"
|
||||
require "test/unit"
|
||||
require "mocha/setup"
|
||||
require "linguist"
|
||||
@@ -1,9 +1,4 @@
|
||||
require 'linguist/file_blob'
|
||||
require 'linguist/samples'
|
||||
|
||||
require 'test/unit'
|
||||
require 'mocha/setup'
|
||||
require 'mime/types'
|
||||
require_relative "./helper"
|
||||
|
||||
class TestBlob < Test::Unit::TestCase
|
||||
include Linguist
|
||||
@@ -470,6 +465,25 @@ class TestBlob < Test::Unit::TestCase
|
||||
assert blob.language, "No language for #{sample[:path]}"
|
||||
assert_equal sample[:language], blob.language.name, blob.name
|
||||
end
|
||||
|
||||
# Test language detection for files which shouldn't be used as samples
|
||||
root = File.expand_path('../fixtures', __FILE__)
|
||||
Dir.entries(root).each do |language|
|
||||
next unless File.file?(language)
|
||||
|
||||
# Each directory contains test files of a language
|
||||
dirname = File.join(root, language)
|
||||
Dir.entries(dirname).each do |filename|
|
||||
next unless File.file?(filename)
|
||||
|
||||
# By default blob search the file in the samples;
|
||||
# thus, we need to give it the absolute path
|
||||
filepath = File.join(dirname, filename)
|
||||
blob = blob(filepath)
|
||||
assert blob.language, "No language for #{filepath}"
|
||||
assert_equal language, blob.language.name, blob.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_minified_files_not_safe_to_highlight
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
require 'linguist/classifier'
|
||||
require 'linguist/language'
|
||||
require 'linguist/samples'
|
||||
require 'linguist/tokenizer'
|
||||
|
||||
require 'test/unit'
|
||||
require_relative "./helper"
|
||||
|
||||
class TestClassifier < Test::Unit::TestCase
|
||||
include Linguist
|
||||
|
||||
10
test/test_file_blob.rb
Normal file
10
test/test_file_blob.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
require 'linguist/file_blob'
|
||||
require 'test/unit'
|
||||
|
||||
class TestFileBlob < Test::Unit::TestCase
|
||||
def test_extensions
|
||||
assert_equal [".gitignore"], Linguist::FileBlob.new(".gitignore").extensions
|
||||
assert_equal [".xml"], Linguist::FileBlob.new("build.xml").extensions
|
||||
assert_equal [".html.erb", ".erb"], Linguist::FileBlob.new("dotted.dir/index.html.erb").extensions
|
||||
end
|
||||
end
|
||||
@@ -1,9 +1,4 @@
|
||||
require 'linguist/heuristics'
|
||||
require 'linguist/language'
|
||||
require 'linguist/samples'
|
||||
require 'linguist/file_blob'
|
||||
|
||||
require 'test/unit'
|
||||
require_relative "./helper"
|
||||
|
||||
class TestHeuristcs < Test::Unit::TestCase
|
||||
include Linguist
|
||||
@@ -132,4 +127,14 @@ class TestHeuristcs < Test::Unit::TestCase
|
||||
results = Heuristics.disambiguate_sc(fixture("Scala/node11.sc"))
|
||||
assert_equal Language["Scala"], results.first
|
||||
end
|
||||
|
||||
def test_fs_by_heuristics
|
||||
languages = ["F#", "Forth", "GLSL"]
|
||||
languages.each do |language|
|
||||
all_fixtures(language).each do |fixture|
|
||||
results = Heuristics.disambiguate_fs(fixture("#{language}/#{File.basename(fixture)}"))
|
||||
assert_equal Language[language], results.first
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'linguist/language'
|
||||
require 'test/unit'
|
||||
require 'yaml'
|
||||
require_relative "./helper"
|
||||
|
||||
class TestLanguage < Test::Unit::TestCase
|
||||
include Linguist
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'linguist/md5'
|
||||
|
||||
require 'test/unit'
|
||||
require_relative "./helper"
|
||||
|
||||
class TestMD5 < Test::Unit::TestCase
|
||||
include Linguist
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
require 'test/unit'
|
||||
require 'yaml'
|
||||
require_relative "./helper"
|
||||
|
||||
class TestPedantic < Test::Unit::TestCase
|
||||
filename = File.expand_path("../../lib/linguist/languages.yml", __FILE__)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'linguist/repository'
|
||||
require 'linguist/lazy_blob'
|
||||
require 'test/unit'
|
||||
require_relative "./helper"
|
||||
|
||||
class TestRepository < Test::Unit::TestCase
|
||||
def rugged_repository
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
require 'linguist/samples'
|
||||
require 'linguist/language'
|
||||
require 'tempfile'
|
||||
require 'yajl'
|
||||
require 'test/unit'
|
||||
require_relative "./helper"
|
||||
require "tempfile"
|
||||
|
||||
class TestSamples < Test::Unit::TestCase
|
||||
include Linguist
|
||||
@@ -34,23 +31,29 @@ class TestSamples < Test::Unit::TestCase
|
||||
assert_equal data['languages_total'], data['languages'].inject(0) { |n, (_, c)| n += c }
|
||||
assert_equal data['tokens_total'], data['language_tokens'].inject(0) { |n, (_, c)| n += c }
|
||||
assert_equal data['tokens_total'], data['tokens'].inject(0) { |n, (_, ts)| n += ts.inject(0) { |m, (_, c)| m += c } }
|
||||
assert !data["interpreters"].empty?
|
||||
end
|
||||
|
||||
# Check that there aren't samples with extensions that aren't explicitly defined in languages.yml
|
||||
def test_parity
|
||||
extensions = Samples.cache['extnames']
|
||||
languages_yml = File.expand_path("../../lib/linguist/languages.yml", __FILE__)
|
||||
languages = YAML.load_file(languages_yml)
|
||||
|
||||
languages.each do |name, options|
|
||||
# Check that there aren't samples with extensions or interpreters that
|
||||
# aren't explicitly defined in languages.yml
|
||||
languages_yml = File.expand_path("../../lib/linguist/languages.yml", __FILE__)
|
||||
YAML.load_file(languages_yml).each do |name, options|
|
||||
define_method "test_samples_have_parity_with_languages_yml_for_#{name}" do
|
||||
options['extensions'] ||= []
|
||||
|
||||
if extnames = extensions[name]
|
||||
if extnames = Samples.cache['extnames'][name]
|
||||
extnames.each do |extname|
|
||||
next if extname == '.script!'
|
||||
assert options['extensions'].include?(extname), "#{name} has a sample with extension (#{extname}) that isn't explicitly defined in languages.yml"
|
||||
end
|
||||
end
|
||||
|
||||
options['interpreters'] ||= []
|
||||
if interpreters = Samples.cache['interpreters'][name]
|
||||
interpreters.each do |interpreter|
|
||||
# next if extname == '.script!'
|
||||
assert options['interpreters'].include?(interpreter), "#{name} has a sample with an interpreter (#{interpreter}) that isn't explicitly defined in languages.yml"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -79,4 +82,9 @@ class TestSamples < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_shebang
|
||||
assert_equal "crystal", Linguist.interpreter_from_shebang("#!/usr/bin/env bin/crystal")
|
||||
assert_equal "python2", Linguist.interpreter_from_shebang("#!/usr/bin/python2.4")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'linguist/tokenizer'
|
||||
|
||||
require 'test/unit'
|
||||
require_relative "./helper"
|
||||
|
||||
class TestTokenizer < Test::Unit::TestCase
|
||||
include Linguist
|
||||
|
||||
Reference in New Issue
Block a user