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"
|
|
|
|
|
2024-02-18 15:11:11 -08:00
|
|
|
RSpec.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 }
|
2023-07-06 16:47:09 +01:00
|
|
|
let(:versions) { class_double(DevelopmentTools, clang_build_version: Version.new("600")) }
|
2017-02-21 05:37:08 +01:00
|
|
|
|
2018-03-25 13:30:37 +01:00
|
|
|
before do
|
2022-08-23 12:42:02 +01:00
|
|
|
allow(versions).to receive(:gcc_version) do |name|
|
2017-02-21 05:37:08 +01:00
|
|
|
case name
|
2023-07-06 16:47:09 +01:00
|
|
|
when "gcc-7" then Version.new("7.1")
|
|
|
|
when "gcc-6" then Version.new("6.1")
|
|
|
|
when "gcc-5" then Version.new("5.1")
|
|
|
|
when "gcc-4.9" then Version.new("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)
|
2023-03-03 22:13:41 +00:00
|
|
|
allow(Formulary).to receive(:factory)
|
|
|
|
.with("gcc")
|
2023-01-22 17:05:56 -08:00
|
|
|
.and_return(instance_double(Formula, 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)
|
2023-03-03 22:13:41 +00:00
|
|
|
allow(Formulary).to receive(:factory)
|
|
|
|
.with("gcc@11")
|
2023-01-22 17:05:56 -08:00
|
|
|
.and_return(instance_double(Formula, 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")
|
2023-03-03 22:13:41 +00:00
|
|
|
allow(Formulary).to receive(:factory)
|
|
|
|
.with("gcc@11")
|
2023-01-22 17:05:56 -08:00
|
|
|
.and_return(instance_double(Formula, 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" }
|
2023-03-03 22:13:41 +00:00
|
|
|
allow(Formulary).to receive(:factory)
|
|
|
|
.with("gcc@11")
|
2023-01-22 17:05:56 -08:00
|
|
|
.and_return(instance_double(Formula, version: Version.new("5.0")))
|
2021-03-30 03:00:35 +01:00
|
|
|
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
|