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
|
|
|
|
2018-09-27 20:23:00 -07:00
|
|
|
let(:compilers) { [:clang, :gcc_4_2, :gnu] }
|
2017-02-21 05:37:08 +01:00
|
|
|
let(:software_spec) { SoftwareSpec.new }
|
|
|
|
let(:cc) { :clang }
|
|
|
|
let(:versions) do
|
|
|
|
double(
|
|
|
|
gcc_4_0_build_version: Version::NULL,
|
2018-09-27 20:23:00 -07:00
|
|
|
gcc_4_2_build_version: Version.create("5666"),
|
2017-02-21 05:37:08 +01:00
|
|
|
llvm_build_version: Version::NULL,
|
|
|
|
clang_build_version: Version.create("425"),
|
|
|
|
)
|
|
|
|
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
|
|
|
|
when "gcc-4.8" then Version.create("4.8.1")
|
|
|
|
when "gcc-4.7" then Version.create("4.7.1")
|
|
|
|
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
|
|
|
|
software_spec.fails_with(gcc: "4.8")
|
|
|
|
expect(subject.compiler).to eq(:clang)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "still returns gcc-4.8 if it fails with gcc without a specific version" do
|
|
|
|
software_spec.fails_with(:clang)
|
2018-09-27 20:23:00 -07:00
|
|
|
software_spec.fails_with(:gcc_4_2)
|
2017-02-21 05:37:08 +01:00
|
|
|
expect(subject.compiler).to eq("gcc-4.8")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns gcc if it fails with clang and llvm" do
|
|
|
|
software_spec.fails_with(:clang)
|
2018-09-27 20:23:00 -07:00
|
|
|
expect(subject.compiler).to eq(:gcc_4_2)
|
2017-02-21 05:37:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns clang if it fails with gcc and llvm" do
|
2018-09-27 20:23:00 -07:00
|
|
|
software_spec.fails_with(:gcc_4_2)
|
2017-02-21 05:37:08 +01:00
|
|
|
expect(subject.compiler).to eq(:clang)
|
|
|
|
end
|
|
|
|
|
|
|
|
example "returns gcc if it fails with a specific gcc version" do
|
|
|
|
software_spec.fails_with(:clang)
|
|
|
|
software_spec.fails_with(gcc: "4.8")
|
2018-09-27 20:23:00 -07:00
|
|
|
expect(subject.compiler).to eq(:gcc_4_2)
|
2017-02-21 05:37:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
example "returns a lower version of gcc if it fails with the highest version" do
|
|
|
|
software_spec.fails_with(:clang)
|
2018-09-27 20:23:00 -07:00
|
|
|
software_spec.fails_with(:gcc_4_2)
|
2017-02-21 05:37:08 +01:00
|
|
|
software_spec.fails_with(gcc: "4.8")
|
|
|
|
expect(subject.compiler).to eq("gcc-4.7")
|
|
|
|
end
|
|
|
|
|
2018-10-12 23:47:55 +02:00
|
|
|
it "raises an error when gcc or llvm is missing" do
|
2018-09-27 20:23:00 -07:00
|
|
|
allow(versions).to receive(:gcc_4_2_build_version).and_return(Version::NULL)
|
2017-02-21 05:37:08 +01:00
|
|
|
|
|
|
|
software_spec.fails_with(:clang)
|
|
|
|
software_spec.fails_with(gcc: "4.8")
|
|
|
|
software_spec.fails_with(gcc: "4.7")
|
|
|
|
|
|
|
|
expect { subject.compiler }.to raise_error(CompilerSelectionError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|