Sha256: a48132a4a078081b2dd81a78c62c46b00d4508b65251305c3ee6e7b87bf38766

Contents?: true

Size: 1.72 KB

Versions: 16

Compression:

Stored size: 1.72 KB

Contents

silence_warnings do
  require 'elf'
end
require 'dply/elf'
require 'pathname'

module Dply
  describe Elf do

    before :all do
      @verbose = $VERBOSE
      $VERBOSE = false
    end

    let(:work_dir) { Pathname.new("#{__dir__}/../test_data/elf").realpath }

    def map_64bit(list)
      list.map { |i| "#{i}()(64bit)" }
    end

    describe ".elf?" do
      it "returns true if file is an ELF" do
        expect(Elf.elf? "#{work_dir}/elf").to eq(true)
      end

      it "returns false if file is not an ELF" do
        expect(Elf.elf? "#{work_dir}/not_elf").to eq(false)
      end

      it "returns false if file doesn't exist" do
        expect(Elf.elf? "#{work_dir}/nofile").to eq(false)
      end
    end

    describe "#external_libs" do
      it "returns a list of external libs when elf has no rpath section" do
        libs = map_64bit ["libattr.so.1", "libc.so.6"]
        elf = Elf.new("#{work_dir}/elf")
        expect(elf.external_libs).to match_array(libs)
      end

      context "when elf has absolute rpath or runpath" do
        it "returns all external libs ignoring rpath" do
          libs = map_64bit ["libpq.so.5", "libc.so.6", "libpgtypes.so.3", "libpthread.so.0"]
          elf = Elf.new("#{work_dir}/libecpg.so")
          expect(elf.external_libs).to match_array(libs)
        end
      end

      context "when elf contains a relative rpath or runpath" do
        it "returns all external libs excluding the ones found in relative rpath" do
          libs = map_64bit ["libpq.so.5", "libc.so.6", "libpthread.so.0"]
          elf = Elf.new("#{work_dir}/rpath_libecpg.so")
          expect(elf.external_libs).to match_array(libs)
        end
      end
    end

    after :all do
      $VERBOSE = @verbose
    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
dply-0.3.15 spec/dply/elf_spec.rb
dply-0.3.14 spec/dply/elf_spec.rb
dply-0.3.13 spec/dply/elf_spec.rb
dply-0.3.12 spec/dply/elf_spec.rb
dply-0.3.11 spec/dply/elf_spec.rb
dply-0.3.10 spec/dply/elf_spec.rb
dply-0.3.9 spec/dply/elf_spec.rb
dply-0.3.8 spec/dply/elf_spec.rb
dply-0.3.7 spec/dply/elf_spec.rb
dply-0.3.6 spec/dply/elf_spec.rb
dply-0.3.5 spec/dply/elf_spec.rb
dply-0.3.4 spec/dply/elf_spec.rb
dply-0.3.3 spec/dply/elf_spec.rb
dply-0.3.2 spec/dply/elf_spec.rb
dply-0.3.1 spec/dply/elf_spec.rb
dply-0.3.0 spec/dply/elf_spec.rb