Skip to content

Commit 35b2704

Browse files
committed
Add tests for rpath or other build related paths
1 parent 63fc155 commit 35b2704

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

spec/pg_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,30 @@
6767
[PG.library_version, PG.version_string, PG.threadsafe?, PG::VERSION, PG::POSTGRESQL_LIB_PATH]
6868
)
6969
end
70+
71+
it "native gem's C-ext file shouldn't contain any rpath or other build-related paths" do
72+
skip "applies to native binary gems only" unless PG::IS_BINARY_GEM
73+
cext_fname = $LOADED_FEATURES.grep(/pg_ext/).first
74+
expect(cext_fname).not_to be_nil
75+
cext_text = File.binread(cext_fname)
76+
expect(cext_text).to match(/Init_pg_ext/) # C-ext shoud contain the init function
77+
expect(cext_text).not_to match(/usr\/local/) # there should be no rpath to /usr/local/rake-compiler/ruby/x86_64-unknown-linux-musl/ruby-3.4.5/lib or so
78+
expect(cext_text).not_to match(/home\//) # there should be no path to /home/ or so
79+
end
80+
81+
it "native gem's libpq file shouldn't contain any rpath or other build-related paths" do
82+
skip "applies to native binary gems only" unless PG::IS_BINARY_GEM
83+
84+
libpq_fname = case RUBY_PLATFORM
85+
when /mingw|mswin/ then "libpq.dll"
86+
when /linux/ then "libpq-ruby-pg.so.1"
87+
when /darwin/ then "libpq-ruby-pg.1.dylib"
88+
end
89+
90+
path = File.join(PG::POSTGRESQL_LIB_PATH, libpq_fname)
91+
text = File.binread(path)
92+
expect(text).to match(/PQconnectdb/) # libpq shoud contain the connect function
93+
expect(text).not_to match(/usr\/local/) # there should be no rpath to build dirs
94+
expect(text).not_to match(/home\//) # there should be no path to /home/.../ports/ or so
95+
end
7096
end

0 commit comments

Comments
 (0)