| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |   subject(:selector) { 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") | 
					
						
							| 
									
										
										
										
											2021-02-03 21:28:11 +01:00
										 |  |  |       when "gcc-5" then Version.create("5.1") | 
					
						
							| 
									
										
										
										
											2021-03-30 03:00:35 +01:00
										 |  |  |       when "gcc-4.9" then Version.create("4.9.1") | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  |       else Version::NULL | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#compiler" do | 
					
						
							|  |  |  |     it "defaults to cc" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(selector.compiler).to eq(cc) | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  |     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") | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(selector.compiler).to eq(:clang) | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  |     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) | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(selector.compiler).to eq("gcc-7") | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-03 21:28:11 +01:00
										 |  |  |     it "returns gcc-6 if gcc formula offers gcc-6 on mac", :needs_macos do | 
					
						
							| 
									
										
										
										
											2019-03-31 21:42:05 +08:00
										 |  |  |       software_spec.fails_with(:clang) | 
					
						
							| 
									
										
										
										
											2021-03-30 03:00:35 +01:00
										 |  |  |       allow(Formulary).to receive(:factory).with("gcc").and_return(double(version: Version.new("6.0"))) | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(selector.compiler).to eq("gcc-6") | 
					
						
							| 
									
										
										
										
											2019-03-31 21:42:05 +08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-03 21:28:11 +01:00
										 |  |  |     it "returns gcc-5 if gcc formula offers gcc-5 on linux", :needs_linux do | 
					
						
							|  |  |  |       software_spec.fails_with(:clang) | 
					
						
							| 
									
										
										
										
											2021-03-30 03:00:35 +01:00
										 |  |  |       allow(Formulary).to receive(:factory).with("gcc@5").and_return(double(version: Version.new("5.0"))) | 
					
						
							| 
									
										
										
										
											2021-02-03 21:28:11 +01:00
										 |  |  |       expect(selector.compiler).to eq("gcc-5") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-30 03:00:35 +01:00
										 |  |  |     it "returns gcc-6 if gcc formula offers gcc-5 and fails with gcc-5 and gcc-7 on linux", :needs_linux do | 
					
						
							| 
									
										
										
										
											2021-02-03 21:28:11 +01:00
										 |  |  |       software_spec.fails_with(:clang) | 
					
						
							|  |  |  |       software_spec.fails_with(gcc: "5") | 
					
						
							|  |  |  |       software_spec.fails_with(gcc: "7") | 
					
						
							| 
									
										
										
										
											2021-03-30 03:00:35 +01:00
										 |  |  |       allow(Formulary).to receive(:factory).with("gcc@5").and_return(double(version: Version.new("5.0"))) | 
					
						
							| 
									
										
										
										
											2021-02-03 21:28:11 +01:00
										 |  |  |       expect(selector.compiler).to eq("gcc-6") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-30 03:00:35 +01:00
										 |  |  |     it "returns gcc-7 if gcc formula offers gcc-5 and fails with gcc <= 6 on linux", :needs_linux do | 
					
						
							|  |  |  |       software_spec.fails_with(:clang) | 
					
						
							|  |  |  |       software_spec.fails_with(:gcc) { version "6" } | 
					
						
							|  |  |  |       allow(Formulary).to receive(:factory).with("gcc@5").and_return(double(version: Version.new("5.0"))) | 
					
						
							|  |  |  |       expect(selector.compiler).to eq("gcc-7") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns gcc-7 if gcc-7 is version 7.1 but spec fails with gcc-7 <= 7.0" do | 
					
						
							|  |  |  |       software_spec.fails_with(:clang) | 
					
						
							|  |  |  |       software_spec.fails_with(gcc: "7") { version "7.0" } | 
					
						
							|  |  |  |       expect(selector.compiler).to eq("gcc-7") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns gcc-6 if gcc-7 is version 7.1 but spec fails with gcc-7 <= 7.1" do | 
					
						
							|  |  |  |       software_spec.fails_with(:clang) | 
					
						
							|  |  |  |       software_spec.fails_with(gcc: "7") { version "7.1" } | 
					
						
							|  |  |  |       expect(selector.compiler).to eq("gcc-6") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error when gcc or llvm is missing (hash syntax)" 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") | 
					
						
							| 
									
										
										
										
											2021-02-03 21:28:11 +01:00
										 |  |  |       software_spec.fails_with(gcc: "5") | 
					
						
							| 
									
										
										
										
											2021-03-30 03:00:35 +01:00
										 |  |  |       software_spec.fails_with(gcc: "4.9") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect { selector.compiler }.to raise_error(CompilerSelectionError) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error when gcc or llvm is missing (symbol syntax)" do | 
					
						
							|  |  |  |       software_spec.fails_with(:clang) | 
					
						
							|  |  |  |       software_spec.fails_with(:gcc) | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect { selector.compiler }.to raise_error(CompilerSelectionError) | 
					
						
							| 
									
										
										
										
											2017-02-21 05:37:08 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |