2022-01-18 07:58:04 -05:00
|
|
|
# frozen_string_literal: false
|
|
|
|
require_relative 'base'
|
|
|
|
require 'shellwords'
|
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
class TestMkmfPkgConfig < TestMkmf
|
|
|
|
PKG_CONFIG = find_executable0("pkg-config")
|
2022-01-18 07:58:04 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
def setup
|
|
|
|
super
|
2022-01-18 07:58:04 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
if PKG_CONFIG
|
|
|
|
@fixtures_dir = File.join(Dir.pwd, "fixtures")
|
|
|
|
@fixtures_lib_dir = File.join(@fixtures_dir, "lib")
|
|
|
|
@fixtures_inc_dir = File.join(@fixtures_dir, "include")
|
2022-01-18 07:58:04 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
FileUtils.mkdir(@fixtures_dir)
|
|
|
|
File.write("fixtures/test1.pc", <<~EOF)
|
|
|
|
libdir=#{@fixtures_lib_dir}
|
|
|
|
includedir=#{@fixtures_inc_dir}
|
2022-01-18 07:58:04 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
Name: test1
|
|
|
|
Description: Test for mkmf pkg-config method
|
|
|
|
Version: 1.2.3
|
|
|
|
Libs: -L${libdir} -ltest1-public
|
|
|
|
Libs.private: -ltest1-private
|
|
|
|
Cflags: -I${includedir}/cflags-I --cflags-other
|
|
|
|
EOF
|
2022-01-18 07:58:04 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
@pkg_config_path, ENV["PKG_CONFIG_PATH"] = ENV["PKG_CONFIG_PATH"], File.join(Dir.pwd, "fixtures")
|
2022-01-18 07:58:04 -05:00
|
|
|
end
|
2022-04-22 16:01:43 -04:00
|
|
|
end
|
2022-01-18 07:58:04 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
def teardown
|
|
|
|
if PKG_CONFIG
|
|
|
|
ENV["PKG_CONFIG_PATH"] = @pkg_config_path
|
2022-01-18 07:58:04 -05:00
|
|
|
end
|
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
super
|
|
|
|
end
|
2022-01-18 07:58:04 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
def test_pkgconfig_with_option_returns_nil_on_error
|
|
|
|
pend("skipping because pkg-config is not installed") unless PKG_CONFIG
|
|
|
|
assert_nil(pkg_config("package-does-not-exist", "exists"), MKMFLOG)
|
|
|
|
end
|
2022-01-18 07:58:04 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
def test_pkgconfig_with_libs_option_returns_output
|
|
|
|
pend("skipping because pkg-config is not installed") unless PKG_CONFIG
|
|
|
|
expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public"].sort
|
|
|
|
actual = pkg_config("test1", "libs").shellsplit.sort
|
|
|
|
assert_equal(expected, actual, MKMFLOG)
|
|
|
|
end
|
2022-01-18 08:13:48 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
def test_pkgconfig_with_cflags_option_returns_output
|
|
|
|
pend("skipping because pkg-config is not installed") unless PKG_CONFIG
|
|
|
|
expected = ["--cflags-other", "-I#{@fixtures_inc_dir}/cflags-I"].sort
|
|
|
|
actual = pkg_config("test1", "cflags").shellsplit.sort
|
|
|
|
assert_equal(expected, actual, MKMFLOG)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_pkgconfig_with_multiple_options
|
|
|
|
pend("skipping because pkg-config is not installed") unless PKG_CONFIG
|
|
|
|
expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public", "-ltest1-private"].sort
|
|
|
|
actual = pkg_config("test1", "libs", "static").shellsplit.sort
|
|
|
|
assert_equal(expected, actual, MKMFLOG)
|
2022-01-18 07:58:04 -05:00
|
|
|
end
|
|
|
|
end
|