| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  | require "compilers" | 
					
						
							|  |  |  | require "software_spec" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe CompilerSelector do | 
					
						
							|  |  |  |   subject { described_class.new(software_spec, versions, compilers) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-26 17:13:14 +00:00
										 |  |  |   let(:compilers) { [:clang, :gnu] } | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  |   let(:software_spec) { SoftwareSpec.new } | 
					
						
							|  |  |  |   let(:cc) { :clang } | 
					
						
							|  |  |  |   let(:versions) do | 
					
						
							|  |  |  |     double( | 
					
						
							| 
									
										
										
										
											2019-01-26 17:13:14 +00:00
										 |  |  |       llvm_build_version:  Version::NULL, | 
					
						
							|  |  |  |       clang_build_version: Version.create("600"), | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |   before do | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  |     allow(versions).to receive(:non_apple_gcc_version) do |name| | 
					
						
							|  |  |  |       case name | 
					
						
							| 
									
										
										
										
											2019-01-08 19:13:46 +00:00
										 |  |  |       when "gcc-7" then Version.create("7.1") | 
					
						
							|  |  |  |       when "gcc-6" then Version.create("6.1") | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  |       else Version::NULL | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#compiler" do | 
					
						
							|  |  |  |     it "defaults to cc" do | 
					
						
							|  |  |  |       expect(subject.compiler).to eq(cc) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns clang if it fails with non-Apple gcc" do | 
					
						
							| 
									
										
										
										
											2019-01-08 19:13:46 +00:00
										 |  |  |       software_spec.fails_with(gcc: "7") | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  |       expect(subject.compiler).to eq(:clang) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-08 19:13:46 +00:00
										 |  |  |     it "still returns gcc-7 if it fails with gcc without a specific version" do | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  |       software_spec.fails_with(:clang) | 
					
						
							| 
									
										
										
										
											2019-01-08 19:13:46 +00:00
										 |  |  |       expect(subject.compiler).to eq("gcc-7") | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-31 21:42:05 +08:00
										 |  |  |     it "returns gcc-6 if gcc formula offers gcc-6" do | 
					
						
							|  |  |  |       software_spec.fails_with(:clang) | 
					
						
							|  |  |  |       allow(Formulary).to receive(:factory).with("gcc").and_return(double(version: "6.0")) | 
					
						
							|  |  |  |       expect(subject.compiler).to eq("gcc-6") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-12 23:47:55 +02:00
										 |  |  |     it "raises an error when gcc or llvm is missing" do | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  |       software_spec.fails_with(:clang) | 
					
						
							| 
									
										
										
										
											2019-01-08 19:13:46 +00:00
										 |  |  |       software_spec.fails_with(gcc: "7") | 
					
						
							|  |  |  |       software_spec.fails_with(gcc: "6") | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect { subject.compiler }.to raise_error(CompilerSelectionError) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |