]>
git.proxmox.com Git - cargo.git/blob - vendor/pkg-config/tests/test.rs
1 extern crate pkg_config
;
3 extern crate lazy_static
;
7 use std
::path
::PathBuf
;
11 static ref LOCK
: Mutex
<()> = Mutex
::new(());
15 for (k
, _
) in env
::vars() {
16 if k
.contains("DYNAMIC")
17 || k
.contains("STATIC")
18 || k
.contains("PKG_CONFIG_ALLOW_CROSS")
19 || k
.contains("PKG_CONFIG_SYSROOT_DIR")
20 || k
.contains("FOO_NO_PKG_CONFIG")
25 env
::remove_var("TARGET");
26 env
::remove_var("HOST");
29 &env
::current_dir().unwrap().join("tests"),
33 fn find(name
: &str) -> Result
<pkg_config
::Library
, Error
> {
34 pkg_config
::probe_library(name
)
40 env
::set_var("TARGET", "foo");
41 env
::set_var("HOST", "bar");
43 Err(Error
::CrossCompilation
) => {}
44 x
=> panic
!("Error::CrossCompilation expected, found `{:?}`", x
),
51 env
::set_var("TARGET", "foo");
52 env
::set_var("HOST", "bar");
53 env
::set_var("PKG_CONFIG_ALLOW_CROSS", "1");
58 fn cross_enabled_if_customized() {
61 env
::set_var("TARGET", "foo");
62 env
::set_var("HOST", "bar");
63 env
::set_var("PKG_CONFIG_SYSROOT_DIR", "/tmp/cross-test");
67 fn cross_disabled_if_customized() {
70 env
::set_var("TARGET", "foo");
71 env
::set_var("HOST", "bar");
72 env
::set_var("PKG_CONFIG_ALLOW_CROSS", "0");
73 env
::set_var("PKG_CONFIG_SYSROOT_DIR", "/tmp/cross-test");
74 // match find("foo") {
75 // Err(Error::CrossCompilation) => {}
76 // _ => panic!("expected CrossCompilation failure"),
81 fn package_disabled() {
84 env
::set_var("FOO_NO_PKG_CONFIG", "1");
86 Err(Error
::EnvNoPkgConfig(name
)) => assert_eq
!(name
, "FOO_NO_PKG_CONFIG"),
87 x
=> panic
!("Error::EnvNoPkgConfig expected, found `{:?}`", x
),
95 let lib
= find("foo").unwrap();
96 assert
!(lib
.libs
.contains(&"gcc".to_string()));
97 assert
!(lib
.libs
.contains(&"coregrind-amd64-linux".to_string()));
98 assert
!(lib
.link_paths
.contains(&PathBuf
::from("/usr/lib/valgrind")));
101 .contains(&PathBuf
::from("/usr/include/valgrind")));
102 assert
!(lib
.include_paths
.contains(&PathBuf
::from("/usr/foo")));
107 let _g
= LOCK
.lock();
109 let lib
= find("escape").unwrap();
112 .contains(&PathBuf
::from("include path with spaces")));
115 .contains(&PathBuf
::from("link path with spaces")));
117 lib
.defines
.get("A"),
118 Some(&Some("\"escaped string' literal\"".to_owned()))
121 lib
.defines
.get("B"),
122 Some(&Some("ESCAPED IDENTIFIER".to_owned()))
124 assert_eq
!(lib
.defines
.get("FOX"), Some(&Some("🦊".to_owned())));
129 let _g
= LOCK
.lock();
131 let lib
= find("framework").unwrap();
132 assert
!(lib
.frameworks
.contains(&"foo".to_string()));
133 assert
!(lib
.frameworks
.contains(&"bar".to_string()));
134 assert
!(lib
.frameworks
.contains(&"baz".to_string()));
135 assert
!(lib
.frameworks
.contains(&"foobar".to_string()));
136 assert
!(lib
.frameworks
.contains(&"foobaz".to_string()));
137 assert
!(lib
.framework_paths
.contains(&PathBuf
::from("/usr/lib")));
142 let _g
= LOCK
.lock();
144 let prefix
= pkg_config
::get_variable("foo", "prefix").unwrap();
145 assert_eq
!(prefix
, "/usr");
150 let _g
= LOCK
.lock();
152 assert_eq
!(&find("foo").unwrap().version
[..], "3.10.0.SVN");
156 fn atleast_version_ok() {
157 let _g
= LOCK
.lock();
159 pkg_config
::Config
::new()
160 .atleast_version("3.10")
167 fn atleast_version_ng() {
168 let _g
= LOCK
.lock();
170 pkg_config
::Config
::new()
171 .atleast_version("3.11")
177 fn exactly_version_ok() {
178 let _g
= LOCK
.lock();
180 pkg_config
::Config
::new()
181 .exactly_version("3.10.0.SVN")
188 fn exactly_version_ng() {
189 let _g
= LOCK
.lock();
191 pkg_config
::Config
::new()
192 .exactly_version("3.10.0")
198 fn range_version_range_ok() {
199 let _g
= LOCK
.lock();
201 pkg_config
::Config
::new()
202 .range_version("4.2.0".."4.4.0")
209 fn range_version_range_ng() {
210 let _g
= LOCK
.lock();
212 pkg_config
::Config
::new()
213 .range_version("4.0.0".."4.2.0")
219 fn range_version_range_inclusive_ok() {
220 let _g
= LOCK
.lock();
222 pkg_config
::Config
::new()
223 .range_version("4.0.0"..="4.2.0")
230 fn range_version_range_inclusive_ng() {
231 let _g
= LOCK
.lock();
233 pkg_config
::Config
::new()
234 .range_version("3.8.0"..="4.0.0")
240 fn range_version_range_from_ok() {
241 let _g
= LOCK
.lock();
243 pkg_config
::Config
::new()
244 .range_version("4.0.0"..)
251 fn range_version_range_from_ng() {
252 let _g
= LOCK
.lock();
254 pkg_config
::Config
::new()
255 .range_version("4.4.0"..)
261 fn range_version_range_to_ok() {
262 let _g
= LOCK
.lock();
264 pkg_config
::Config
::new()
265 .range_version(.."4.4.0")
272 fn range_version_range_to_ng() {
273 let _g
= LOCK
.lock();
275 pkg_config
::Config
::new()
276 .range_version(.."4.2.0")
282 fn range_version_range_to_inclusive_ok() {
283 let _g
= LOCK
.lock();
285 pkg_config
::Config
::new()
286 .range_version(..="4.2.0")
293 fn range_version_range_to_inclusive_ng() {
294 let _g
= LOCK
.lock();
296 pkg_config
::Config
::new()
297 .range_version(..="4.0.0")
303 fn range_version_full() {
304 let _g
= LOCK
.lock();
306 pkg_config
::Config
::new()
314 let _g
= LOCK
.lock();
316 let lib
= find("rpath").unwrap();
319 .contains(&vec
!["-rpath".to_string(), "/usr/local/lib".to_string(),]));