lib/pkgforge/components/test.rb in pkgforge-0.4.10 vs lib/pkgforge/components/test.rb in pkgforge-0.4.11

- old
+ new

@@ -14,10 +14,41 @@ Contract None => nil def test! tester = PkgForge::DSL::Test.new(self) tester.instance_eval(&test_block) end + + Contract Or[String, Array], Or[HashOf[String => String], {}, nil] => nil + def test_run(cmd, env = {}) + cmd.unshift('/usr/bin/env') if cmd.is_a? Array + cmd.prepend('/usr/bin/env ') if cmd.is_a? String + env['PATH'] ||= './usr/bin' + lib_override do + Dir.chdir(tmpdir(:release)) do + run_local(cmd, env) + end + end + end + + private + + Contract Func[None => nil] => nil + def lib_override + lib_path_file = '/etc/ld-musl-x86_64.path' + old_lib_paths = File.read(lib_path_file) + puts "Setting library path: #{ld_library_path}" + File.open(lib_path_file, 'w') { |fh| fh << ld_library_path } + yield + ensure + File.open(lib_path_file, 'w') { |fh| fh << old_lib_paths } + nil + end + + Contract None => String + def ld_library_path + deps.keys.map { |x| "#{dep(x)}/usr/lib" }.join(':') + end end module DSL ## # Add test methods to Forge DSL @@ -32,21 +63,10 @@ ## # Add test methods to Test DSL class Test Contract Or[String, Array], Or[HashOf[String => String], {}, nil] => nil def run(cmd, env = {}) - cmd.unshift('/usr/bin/env') if cmd.is_a? Array - cmd << ';' if cmd.is_a? String - env['PATH'] ||= './usr/bin' - env['LD_LIBRARY_PATH'] ||= ld_library_path @forge.test_run(cmd, env) - end - - private - - Contract None => String - def ld_library_path - @forge.deps.keys.map { |x| "#{@forge.dep(x)}/usr/lib" }.join(':') end end end end