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
|
2024-08-22 17:42:46 -04:00
|
|
|
when "gcc-12" then Version.new("12.1")
|
|
|
|
when "gcc-11" then Version.new("11.1")
|
|
|
|
when "gcc-10" then Version.new("10.1")
|
|
|
|
when "gcc-9" then Version.new("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
|
2024-08-22 17:42:46 -04:00
|
|
|
software_spec.fails_with(gcc: "12")
|
2021-01-31 13:14:23 -05:00
|
|
|
expect(selector.compiler).to eq(:clang)
|
2017-02-21 05:37:08 +01:00
|
|
|
end
|
|
|
|
|
2024-08-22 17:42:46 -04:00
|
|
|
it "still returns gcc-12 if it fails with gcc without a specific version" do
|
2017-02-21 05:37:08 +01:00
|
|
|
software_spec.fails_with(:clang)
|
2024-08-22 17:42:46 -04:00
|
|
|
expect(selector.compiler).to eq("gcc-12")
|
2017-02-21 05:37:08 +01:00
|
|
|
end
|
|
|
|
|
2024-08-22 17:42:46 -04:00
|
|
|
it "returns gcc-11 if gcc formula offers gcc-11 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")
|
2024-08-22 17:42:46 -04:00
|
|
|
.and_return(instance_double(Formula, version: Version.new("11.0")))
|
|
|
|
expect(selector.compiler).to eq("gcc-11")
|
2019-03-31 21:42:05 +08:00
|
|
|
end
|
|
|
|
|
2024-08-22 17:42:46 -04:00
|
|
|
it "returns gcc-10 if gcc formula offers gcc-10 on linux", :needs_linux do
|
2021-02-03 21:28:11 +01:00
|
|
|
software_spec.fails_with(:clang)
|
2023-03-03 22:13:41 +00:00
|
|
|
allow(Formulary).to receive(:factory)
|
2025-04-03 12:47:21 +01:00
|
|
|
.with(OS::LINUX_PREFERRED_GCC_COMPILER_FORMULA)
|
2024-08-22 17:42:46 -04:00
|
|
|
.and_return(instance_double(Formula, version: Version.new("10.0")))
|
|
|
|
expect(selector.compiler).to eq("gcc-10")
|
2021-02-03 21:28:11 +01:00
|
|
|
end
|
|
|
|
|
2024-08-22 17:42:46 -04:00
|
|
|
it "returns gcc-11 if gcc formula offers gcc-10 and fails with gcc-10 and gcc-12 on linux", :needs_linux do
|
2021-02-03 21:28:11 +01:00
|
|
|
software_spec.fails_with(:clang)
|
2024-08-22 17:42:46 -04:00
|
|
|
software_spec.fails_with(gcc: "10")
|
|
|
|
software_spec.fails_with(gcc: "12")
|
2023-03-03 22:13:41 +00:00
|
|
|
allow(Formulary).to receive(:factory)
|
2025-04-03 12:47:21 +01:00
|
|
|
.with(OS::LINUX_PREFERRED_GCC_COMPILER_FORMULA)
|
2024-08-22 17:42:46 -04:00
|
|
|
.and_return(instance_double(Formula, version: Version.new("10.0")))
|
|
|
|
expect(selector.compiler).to eq("gcc-11")
|
2021-02-03 21:28:11 +01:00
|
|
|
end
|
|
|
|
|
2024-08-22 17:42:46 -04:00
|
|
|
it "returns gcc-12 if gcc formula offers gcc-11 and fails with gcc <= 11 on linux", :needs_linux do
|
2021-03-30 03:00:35 +01:00
|
|
|
software_spec.fails_with(:clang)
|
2024-08-22 17:42:46 -04:00
|
|
|
software_spec.fails_with(:gcc) { version "11" }
|
2023-03-03 22:13:41 +00:00
|
|
|
allow(Formulary).to receive(:factory)
|
2025-04-03 12:47:21 +01:00
|
|
|
.with(OS::LINUX_PREFERRED_GCC_COMPILER_FORMULA)
|
2024-08-22 17:42:46 -04:00
|
|
|
.and_return(instance_double(Formula, version: Version.new("11.0")))
|
|
|
|
expect(selector.compiler).to eq("gcc-12")
|
2021-03-30 03:00:35 +01:00
|
|
|
end
|
|
|
|
|
2024-08-22 17:42:46 -04:00
|
|
|
it "returns gcc-12 if gcc-12 is version 12.1 but spec fails with gcc-12 <= 12.0" do
|
2021-03-30 03:00:35 +01:00
|
|
|
software_spec.fails_with(:clang)
|
2024-08-22 17:42:46 -04:00
|
|
|
software_spec.fails_with(gcc: "12") { version "12.0" }
|
|
|
|
expect(selector.compiler).to eq("gcc-12")
|
2021-03-30 03:00:35 +01:00
|
|
|
end
|
|
|
|
|
2024-08-22 17:42:46 -04:00
|
|
|
it "returns gcc-11 if gcc-12 is version 12.1 but spec fails with gcc-12 <= 12.1" do
|
2021-03-30 03:00:35 +01:00
|
|
|
software_spec.fails_with(:clang)
|
2024-08-22 17:42:46 -04:00
|
|
|
software_spec.fails_with(gcc: "12") { version "12.1" }
|
|
|
|
expect(selector.compiler).to eq("gcc-11")
|
2021-03-30 03:00:35 +01:00
|
|
|
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)
|
2024-08-22 17:42:46 -04:00
|
|
|
software_spec.fails_with(gcc: "12")
|
|
|
|
software_spec.fails_with(gcc: "11")
|
|
|
|
software_spec.fails_with(gcc: "10")
|
|
|
|
software_spec.fails_with(gcc: "9")
|
2021-03-30 03:00:35 +01:00
|
|
|
|
|
|
|
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
|