|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "os/linux/libstdcxx" |
| 4 | + |
| 5 | +RSpec.describe OS::Linux::Libstdcxx do |
| 6 | + describe "::below_ci_version?" do |
| 7 | + it "returns false when system version matches CI version" do |
| 8 | + allow(described_class).to receive(:system_version).and_return(Version.new(OS::LINUX_LIBSTDCXX_CI_VERSION)) |
| 9 | + expect(described_class.below_ci_version?).to be false |
| 10 | + end |
| 11 | + |
| 12 | + it "returns true when system version cannot be detected" do |
| 13 | + allow(described_class).to receive(:system_version).and_return(Version::NULL) |
| 14 | + expect(described_class.below_ci_version?).to be true |
| 15 | + end |
| 16 | + end |
| 17 | + |
| 18 | + describe "::system_version" do |
| 19 | + let(:tmpdir) { mktmpdir } |
| 20 | + let(:libstdcxx) { tmpdir/described_class::SONAME } |
| 21 | + let(:soversion) { Version.new(described_class::SOVERSION.to_s) } |
| 22 | + |
| 23 | + before do |
| 24 | + tmpdir.mkpath |
| 25 | + described_class.instance_variable_set(:@system_version, nil) |
| 26 | + allow(described_class).to receive(:system_path).and_return(libstdcxx) |
| 27 | + end |
| 28 | + |
| 29 | + after do |
| 30 | + FileUtils.rm_rf(tmpdir) |
| 31 | + end |
| 32 | + |
| 33 | + it "returns NULL when unable to find system path" do |
| 34 | + allow(described_class).to receive(:system_path).and_return(nil) |
| 35 | + expect(described_class.system_version).to be Version::NULL |
| 36 | + end |
| 37 | + |
| 38 | + it "returns full version from filename" do |
| 39 | + full_version = Version.new("#{soversion}.0.999") |
| 40 | + libstdcxx_real = libstdcxx.sub_ext(".#{full_version}") |
| 41 | + FileUtils.touch libstdcxx_real |
| 42 | + FileUtils.ln_s libstdcxx_real, libstdcxx |
| 43 | + expect(described_class.system_version).to eq full_version |
| 44 | + end |
| 45 | + |
| 46 | + it "returns major version when non-standard libstdc++ filename without full version" do |
| 47 | + FileUtils.touch libstdcxx |
| 48 | + expect(described_class.system_version).to eq soversion |
| 49 | + end |
| 50 | + |
| 51 | + it "returns major version when non-standard libstdc++ filename with unexpected realpath" do |
| 52 | + libstdcxx_real = tmpdir/"libstdc++.so.real" |
| 53 | + FileUtils.touch libstdcxx_real |
| 54 | + FileUtils.ln_s libstdcxx_real, libstdcxx |
| 55 | + expect(described_class.system_version).to eq soversion |
| 56 | + end |
| 57 | + end |
| 58 | +end |
0 commit comments