| 
									
										
										
										
											2017-06-02 19:15:40 +02:00
										 |  |  | require "cmd/style" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe "brew style" do | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |   around do |example| | 
					
						
							| 
									
										
										
										
											2017-06-02 19:15:40 +02:00
										 |  |  |     begin | 
					
						
							|  |  |  |       FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew" | 
					
						
							| 
									
										
										
										
											2017-10-09 18:27:02 +02:00
										 |  |  |       FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop_audit.yml" | 
					
						
							| 
									
										
										
										
											2018-11-12 04:46:47 +01:00
										 |  |  |       FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop_shared.yml", HOMEBREW_LIBRARY/".rubocop_shared.yml" | 
					
						
							| 
									
										
										
										
											2017-06-02 19:15:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       example.run | 
					
						
							|  |  |  |     ensure | 
					
						
							|  |  |  |       FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew" | 
					
						
							| 
									
										
										
										
											2017-10-09 18:27:02 +02:00
										 |  |  |       FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_audit.yml" | 
					
						
							| 
									
										
										
										
											2018-11-12 04:46:47 +01:00
										 |  |  |       FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_shared.yml" | 
					
						
							| 
									
										
										
										
											2017-06-02 19:15:40 +02:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "Homebrew::check_style_json" do | 
					
						
							|  |  |  |     let(:dir) { mktmpdir } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns RubocopResults when RuboCop reports offenses" do | 
					
						
							|  |  |  |       formula = dir/"my-formula.rb" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       formula.write <<~'EOS' | 
					
						
							| 
									
										
										
										
											2017-06-02 19:15:40 +02:00
										 |  |  |         class MyFormula < Formula | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-05 23:19:18 -04:00
										 |  |  |       rubocop_result = Homebrew::Style.check_style_json([formula]) | 
					
						
							| 
									
										
										
										
											2017-06-02 19:15:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(rubocop_result.file_offenses(formula.realpath.to_s).map(&:message)) | 
					
						
							| 
									
										
										
										
											2018-01-20 23:21:25 -08:00
										 |  |  |         .to include("Extra empty line detected at class body beginning.") | 
					
						
							| 
									
										
										
										
											2017-06-02 19:15:40 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-08-28 23:09:44 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     it "corrected offense output format" do | 
					
						
							|  |  |  |       formula = dir/"my-formula-2.rb" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       formula.write <<~EOS | 
					
						
							|  |  |  |         class MyFormula2 < Formula | 
					
						
							|  |  |  |           desc "Test formula" | 
					
						
							|  |  |  |           homepage "https://foo.org" | 
					
						
							|  |  |  |           url "https://foo.org/foo-1.7.5.tgz" | 
					
						
							|  |  |  |           sha256 "cc692fb9dee0cc288757e708fc1a3b6b56ca1210ca181053a371cb11746969da" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           depends_on "foo" | 
					
						
							|  |  |  |           depends_on "bar-config" => :build | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           test do | 
					
						
							|  |  |  |             assert_equal 5, 5
 | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |       options = { fix: true, only_cops: ["NewFormulaAudit/DependencyOrder"], realpath: true } | 
					
						
							|  |  |  |       rubocop_result = Homebrew::Style.check_style_json([formula], options) | 
					
						
							|  |  |  |       offense_string = rubocop_result.file_offenses(formula.realpath).first.to_s | 
					
						
							|  |  |  |       expect(offense_string).to match(/\[Corrected\]/) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-06-02 19:15:40 +02:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-06-11 15:10:59 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe "Homebrew::check_style_and_print" do | 
					
						
							|  |  |  |     let(:dir) { mktmpdir } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns false for conforming file with only audit-level violations" do | 
					
						
							|  |  |  |       # This file is known to use non-rocket hashes and other things that trigger audit, | 
					
						
							|  |  |  |       # but not regular, cop violations | 
					
						
							|  |  |  |       target_file = HOMEBREW_LIBRARY_PATH/"utils.rb" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       rubocop_result = Homebrew::Style.check_style_and_print([target_file]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(rubocop_result).to eq false | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-06-02 19:15:40 +02:00
										 |  |  | end |