mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Add Rake task to fetch ace_modes, and skip test if there's no internet
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -4,3 +4,4 @@ benchmark/ | |||||||
| lib/linguist/samples.json | lib/linguist/samples.json | ||||||
| /grammars | /grammars | ||||||
| /node_modules | /node_modules | ||||||
|  | test/fixtures/ace_modes.json | ||||||
|   | |||||||
							
								
								
									
										26
									
								
								Rakefile
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								Rakefile
									
									
									
									
									
								
							| @@ -3,13 +3,15 @@ require 'rake/clean' | |||||||
| require 'rake/testtask' | require 'rake/testtask' | ||||||
| require 'yaml' | require 'yaml' | ||||||
| require 'yajl' | require 'yajl' | ||||||
|  | require 'open-uri' | ||||||
|  | require 'json' | ||||||
|  |  | ||||||
| task :default => :test | task :default => :test | ||||||
|  |  | ||||||
| Rake::TestTask.new | Rake::TestTask.new | ||||||
|  |  | ||||||
| # Extend test task to check for samples | # Extend test task to check for samples and fetch latest Ace modes | ||||||
| task :test => :check_samples | task :test => [:check_samples, :fetch_ace_modes] | ||||||
|  |  | ||||||
| desc "Check that we have samples.json generated" | desc "Check that we have samples.json generated" | ||||||
| task :check_samples do | task :check_samples do | ||||||
| @@ -18,6 +20,26 @@ task :check_samples do | |||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | desc "Fetch the latest Ace modes from its GitHub repository" | ||||||
|  | task :fetch_ace_modes do | ||||||
|  |   ACE_FIXTURE_PATH = File.join('test', 'fixtures', 'ace_modes.json') | ||||||
|  |  | ||||||
|  |   File.delete(ACE_FIXTURE_PATH) if File.exist?(ACE_FIXTURE_PATH) | ||||||
|  |  | ||||||
|  |   begin | ||||||
|  |     ace_github_modes = (open("https://api.github.com/repos/ajaxorg/ace/contents/lib/ace/mode").read) | ||||||
|  |     File.write(ACE_FIXTURE_PATH, ace_github_modes) | ||||||
|  |   rescue => e | ||||||
|  |     case e | ||||||
|  |     when OpenURI::HTTPError | ||||||
|  |     when SocketError | ||||||
|  |       # no internet? no problem. | ||||||
|  |     else | ||||||
|  |       raise e | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  | end | ||||||
|  |  | ||||||
| task :samples do | task :samples do | ||||||
|   require 'linguist/samples' |   require 'linguist/samples' | ||||||
|   json = Yajl.dump(Linguist::Samples.data, :pretty => true) |   json = Yajl.dump(Linguist::Samples.data, :pretty => true) | ||||||
|   | |||||||
| @@ -371,7 +371,10 @@ class TestLanguage < Test::Unit::TestCase | |||||||
|   end |   end | ||||||
|  |  | ||||||
|   def test_all_languages_have_a_valid_ace_mode |   def test_all_languages_have_a_valid_ace_mode | ||||||
|     ace_github_modes = JSON.parse `curl https://api.github.com/repos/ajaxorg/ace/contents/lib/ace/mode` |     ace_fixture_path = File.join('test', 'fixtures', 'ace_modes.json') | ||||||
|  |     skip("No ace_modes.json file") unless File.exist?(ace_fixture_path) | ||||||
|  |  | ||||||
|  |     ace_github_modes = JSON.parse(File.read(ace_fixture_path)) | ||||||
|     existing_ace_modes = ace_github_modes.map do |ace_github_mode| |     existing_ace_modes = ace_github_modes.map do |ace_github_mode| | ||||||
|       File.basename(ace_github_mode["name"], ".js") if ace_github_mode["name"]  !~ /_highlight_rules|_test|_worker/ |       File.basename(ace_github_mode["name"], ".js") if ace_github_mode["name"]  !~ /_highlight_rules|_test|_worker/ | ||||||
|     end.compact.uniq.sort.map(&:downcase) |     end.compact.uniq.sort.map(&:downcase) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user