Skip to content

Commit

Permalink
test: use pkgconf if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Nov 21, 2024
1 parent fd2c892 commit 066f45c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions test/test-pkg-config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,36 @@
require "pkg-config"

class PkgConfigTest < Test::Unit::TestCase
def find_program(name)
exeext = RbConfig::CONFIG["EXEEXT"]
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
program = File.join(path, name)
return name if File.exist?(program)
return name if File.exist?("#{program}.#{exeext}")
end
nil
end

def setup
@pkgconf = find_program("pkgconf") || "pkg-config"
@custom_libdir = "/tmp/local/lib"
options = {:override_variables => {"libdir" => @custom_libdir}}
@cairo = PackageConfig.new("cairo", options)
@cairo_png = PackageConfig.new("cairo-png", options)
end

def only_pkg_config_version(major, minor)
pkg_config_version = `pkg-config --version`.chomp
pkg_config_version = `#{@pkgconf} --version`.chomp
current_major, current_minor = pkg_config_version.split(".").collect(&:to_i)
return if ([major, minor] <=> [current_major, current_minor]) <= 0
omit("Require pkg-config #{pkg_config_version} or later")
omit("Require #{@pkgconf} #{pkg_config_version} or later")
end

def test_exist?
assert(system("pkg-config --exists cairo"))
assert(system("#{@pkgconf} --exists cairo"))
assert(@cairo.exist?)

assert(system("pkg-config --exists cairo-png"))
assert(system("#{@pkgconf} --exists cairo-png"))
assert(@cairo_png.exist?)
end

Expand Down Expand Up @@ -177,7 +188,7 @@ def test_not_found
def pkg_config(package, *args)
args.unshift("--define-variable=libdir=#{@custom_libdir}")
args = args.collect {|arg| arg.dump}.join(" ")
normalize_pkg_config_result(`pkg-config #{args} #{package}`.strip)
normalize_pkg_config_result(`#{@pkgconf} #{args} #{package}`.strip)
end

def normalize_pkg_config_result(result)
Expand Down

0 comments on commit 066f45c

Please sign in to comment.