Skip to content

Commit 066f45c

Browse files
committed
test: use pkgconf if it exists
1 parent fd2c892 commit 066f45c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

test/test-pkg-config.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,36 @@
22
require "pkg-config"
33

44
class PkgConfigTest < Test::Unit::TestCase
5+
def find_program(name)
6+
exeext = RbConfig::CONFIG["EXEEXT"]
7+
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
8+
program = File.join(path, name)
9+
return name if File.exist?(program)
10+
return name if File.exist?("#{program}.#{exeext}")
11+
end
12+
nil
13+
end
14+
515
def setup
16+
@pkgconf = find_program("pkgconf") || "pkg-config"
617
@custom_libdir = "/tmp/local/lib"
718
options = {:override_variables => {"libdir" => @custom_libdir}}
819
@cairo = PackageConfig.new("cairo", options)
920
@cairo_png = PackageConfig.new("cairo-png", options)
1021
end
1122

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

1930
def test_exist?
20-
assert(system("pkg-config --exists cairo"))
31+
assert(system("#{@pkgconf} --exists cairo"))
2132
assert(@cairo.exist?)
2233

23-
assert(system("pkg-config --exists cairo-png"))
34+
assert(system("#{@pkgconf} --exists cairo-png"))
2435
assert(@cairo_png.exist?)
2536
end
2637

@@ -177,7 +188,7 @@ def test_not_found
177188
def pkg_config(package, *args)
178189
args.unshift("--define-variable=libdir=#{@custom_libdir}")
179190
args = args.collect {|arg| arg.dump}.join(" ")
180-
normalize_pkg_config_result(`pkg-config #{args} #{package}`.strip)
191+
normalize_pkg_config_result(`#{@pkgconf} #{args} #{package}`.strip)
181192
end
182193

183194
def normalize_pkg_config_result(result)

0 commit comments

Comments
 (0)