summaryrefslogtreecommitdiffstats
path: root/vendor/pkg-config/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/pkg-config/tests
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/pkg-config/tests')
-rw-r--r--vendor/pkg-config/tests/escape.pc5
-rw-r--r--vendor/pkg-config/tests/foo.pc16
-rw-r--r--vendor/pkg-config/tests/framework.pc16
-rw-r--r--vendor/pkg-config/tests/rpath.pc7
-rw-r--r--vendor/pkg-config/tests/test.rs323
5 files changed, 367 insertions, 0 deletions
diff --git a/vendor/pkg-config/tests/escape.pc b/vendor/pkg-config/tests/escape.pc
new file mode 100644
index 000000000..701c4bf73
--- /dev/null
+++ b/vendor/pkg-config/tests/escape.pc
@@ -0,0 +1,5 @@
+Name: Escape
+Version: 4.2.0
+Description: Escape utility library
+Libs: -Llink\ path\ with\ spaces
+Cflags: -Iinclude\ path\ with\ spaces -DA=\"escaped\ string\'\ literal\" -DB=ESCAPED\ IDENTIFIER -DFOX=🦊
diff --git a/vendor/pkg-config/tests/foo.pc b/vendor/pkg-config/tests/foo.pc
new file mode 100644
index 000000000..ce63ceb55
--- /dev/null
+++ b/vendor/pkg-config/tests/foo.pc
@@ -0,0 +1,16 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include/valgrind
+arch=amd64
+os=linux
+platform=amd64-linux
+valt_load_address=0x38000000
+
+Name: Valgrind
+Description: A dynamic binary instrumentation framework
+Version: 3.10.0.SVN
+Requires:
+Libs: -L${libdir}/valgrind -lcoregrind-amd64-linux -lvex-amd64-linux -lgcc
+Cflags: -I${includedir} -isystem /usr/foo
+
diff --git a/vendor/pkg-config/tests/framework.pc b/vendor/pkg-config/tests/framework.pc
new file mode 100644
index 000000000..fec17f47a
--- /dev/null
+++ b/vendor/pkg-config/tests/framework.pc
@@ -0,0 +1,16 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include/valgrind
+arch=amd64
+os=linux
+platform=amd64-linux
+valt_load_address=0x38000000
+
+Name: Valgrind
+Description: A dynamic binary instrumentation framework
+Version: 3.10.0.SVN
+Requires:
+Libs: -F${libdir} -framework foo -Wl,-framework,bar -Wl,-framework -Wl,baz -Wl,-framework,foobar,-framework,foobaz
+Cflags: -I${includedir}
+
diff --git a/vendor/pkg-config/tests/rpath.pc b/vendor/pkg-config/tests/rpath.pc
new file mode 100644
index 000000000..7c36c5cb7
--- /dev/null
+++ b/vendor/pkg-config/tests/rpath.pc
@@ -0,0 +1,7 @@
+prefix=/usr/local
+
+Name: rpath
+Version: 4.2.0
+Description: RPath example library
+Libs: -L${prefix}/lib -Wl,-rpath,${prefix}/lib -lrpath
+Cflags: -I${prefix}/include
diff --git a/vendor/pkg-config/tests/test.rs b/vendor/pkg-config/tests/test.rs
new file mode 100644
index 000000000..4e04ac071
--- /dev/null
+++ b/vendor/pkg-config/tests/test.rs
@@ -0,0 +1,323 @@
+extern crate pkg_config;
+#[macro_use]
+extern crate lazy_static;
+
+use pkg_config::Error;
+use std::env;
+use std::path::PathBuf;
+use std::sync::Mutex;
+
+lazy_static! {
+ static ref LOCK: Mutex<()> = Mutex::new(());
+}
+
+fn reset() {
+ for (k, _) in env::vars() {
+ if k.contains("DYNAMIC")
+ || k.contains("STATIC")
+ || k.contains("PKG_CONFIG_ALLOW_CROSS")
+ || k.contains("PKG_CONFIG_SYSROOT_DIR")
+ || k.contains("FOO_NO_PKG_CONFIG")
+ {
+ env::remove_var(&k);
+ }
+ }
+ env::remove_var("TARGET");
+ env::remove_var("HOST");
+ env::set_var(
+ "PKG_CONFIG_PATH",
+ &env::current_dir().unwrap().join("tests"),
+ );
+}
+
+fn find(name: &str) -> Result<pkg_config::Library, Error> {
+ pkg_config::probe_library(name)
+}
+
+#[test]
+fn cross_disabled() {
+ let _g = LOCK.lock();
+ reset();
+ env::set_var("TARGET", "foo");
+ env::set_var("HOST", "bar");
+ match find("foo") {
+ Err(Error::CrossCompilation) => {}
+ x => panic!("Error::CrossCompilation expected, found `{:?}`", x),
+ }
+}
+
+#[test]
+fn cross_enabled() {
+ let _g = LOCK.lock();
+ reset();
+ env::set_var("TARGET", "foo");
+ env::set_var("HOST", "bar");
+ env::set_var("PKG_CONFIG_ALLOW_CROSS", "1");
+ find("foo").unwrap();
+}
+
+#[test]
+fn cross_enabled_if_customized() {
+ let _g = LOCK.lock();
+ reset();
+ env::set_var("TARGET", "foo");
+ env::set_var("HOST", "bar");
+ env::set_var("PKG_CONFIG_SYSROOT_DIR", "/tmp/cross-test");
+ find("foo").unwrap();
+}
+
+#[test]
+fn cross_disabled_if_customized() {
+ let _g = LOCK.lock();
+ reset();
+ env::set_var("TARGET", "foo");
+ env::set_var("HOST", "bar");
+ env::set_var("PKG_CONFIG_ALLOW_CROSS", "0");
+ env::set_var("PKG_CONFIG_SYSROOT_DIR", "/tmp/cross-test");
+ match find("foo") {
+ Err(Error::CrossCompilation) => {}
+ _ => panic!("expected CrossCompilation failure"),
+ }
+}
+
+#[test]
+fn package_disabled() {
+ let _g = LOCK.lock();
+ reset();
+ env::set_var("FOO_NO_PKG_CONFIG", "1");
+ match find("foo") {
+ Err(Error::EnvNoPkgConfig(name)) => assert_eq!(name, "FOO_NO_PKG_CONFIG"),
+ x => panic!("Error::EnvNoPkgConfig expected, found `{:?}`", x),
+ }
+}
+
+#[test]
+fn output_ok() {
+ let _g = LOCK.lock();
+ reset();
+ let lib = find("foo").unwrap();
+ assert!(lib.libs.contains(&"gcc".to_string()));
+ assert!(lib.libs.contains(&"coregrind-amd64-linux".to_string()));
+ assert!(lib.link_paths.contains(&PathBuf::from("/usr/lib/valgrind")));
+ assert!(lib
+ .include_paths
+ .contains(&PathBuf::from("/usr/include/valgrind")));
+ assert!(lib.include_paths.contains(&PathBuf::from("/usr/foo")));
+}
+
+#[test]
+fn escapes() {
+ let _g = LOCK.lock();
+ reset();
+ let lib = find("escape").unwrap();
+ assert!(lib
+ .include_paths
+ .contains(&PathBuf::from("include path with spaces")));
+ assert!(lib
+ .link_paths
+ .contains(&PathBuf::from("link path with spaces")));
+ assert_eq!(
+ lib.defines.get("A"),
+ Some(&Some("\"escaped string' literal\"".to_owned()))
+ );
+ assert_eq!(
+ lib.defines.get("B"),
+ Some(&Some("ESCAPED IDENTIFIER".to_owned()))
+ );
+ assert_eq!(lib.defines.get("FOX"), Some(&Some("🦊".to_owned())));
+}
+
+#[test]
+fn framework() {
+ let _g = LOCK.lock();
+ reset();
+ let lib = find("framework").unwrap();
+ assert!(lib.frameworks.contains(&"foo".to_string()));
+ assert!(lib.frameworks.contains(&"bar".to_string()));
+ assert!(lib.frameworks.contains(&"baz".to_string()));
+ assert!(lib.frameworks.contains(&"foobar".to_string()));
+ assert!(lib.frameworks.contains(&"foobaz".to_string()));
+ assert!(lib.framework_paths.contains(&PathBuf::from("/usr/lib")));
+}
+
+#[test]
+fn get_variable() {
+ let _g = LOCK.lock();
+ reset();
+ let prefix = pkg_config::get_variable("foo", "prefix").unwrap();
+ assert_eq!(prefix, "/usr");
+}
+
+#[test]
+fn version() {
+ let _g = LOCK.lock();
+ reset();
+ assert_eq!(&find("foo").unwrap().version[..], "3.10.0.SVN");
+}
+
+#[test]
+fn atleast_version_ok() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .atleast_version("3.10")
+ .probe("foo")
+ .unwrap();
+}
+
+#[test]
+#[should_panic]
+fn atleast_version_ng() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .atleast_version("3.11")
+ .probe("foo")
+ .unwrap();
+}
+
+#[test]
+fn exactly_version_ok() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .exactly_version("3.10.0.SVN")
+ .probe("foo")
+ .unwrap();
+}
+
+#[test]
+#[should_panic]
+fn exactly_version_ng() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .exactly_version("3.10.0")
+ .probe("foo")
+ .unwrap();
+}
+
+#[test]
+fn range_version_range_ok() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .range_version("4.2.0".."4.4.0")
+ .probe("escape")
+ .unwrap();
+}
+
+#[test]
+#[should_panic]
+fn range_version_range_ng() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .range_version("4.0.0".."4.2.0")
+ .probe("escape")
+ .unwrap();
+}
+
+#[test]
+fn range_version_range_inclusive_ok() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .range_version("4.0.0"..="4.2.0")
+ .probe("escape")
+ .unwrap();
+}
+
+#[test]
+#[should_panic]
+fn range_version_range_inclusive_ng() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .range_version("3.8.0"..="4.0.0")
+ .probe("escape")
+ .unwrap();
+}
+
+#[test]
+fn range_version_range_from_ok() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .range_version("4.0.0"..)
+ .probe("escape")
+ .unwrap();
+}
+
+#[test]
+#[should_panic]
+fn range_version_range_from_ng() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .range_version("4.4.0"..)
+ .probe("escape")
+ .unwrap();
+}
+
+#[test]
+fn range_version_range_to_ok() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .range_version(.."4.4.0")
+ .probe("escape")
+ .unwrap();
+}
+
+#[test]
+#[should_panic]
+fn range_version_range_to_ng() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .range_version(.."4.2.0")
+ .probe("escape")
+ .unwrap();
+}
+
+#[test]
+fn range_version_range_to_inclusive_ok() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .range_version(..="4.2.0")
+ .probe("escape")
+ .unwrap();
+}
+
+#[test]
+#[should_panic]
+fn range_version_range_to_inclusive_ng() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .range_version(..="4.0.0")
+ .probe("escape")
+ .unwrap();
+}
+
+#[test]
+fn range_version_full() {
+ let _g = LOCK.lock();
+ reset();
+ pkg_config::Config::new()
+ .range_version(..)
+ .probe("escape")
+ .unwrap();
+}
+
+#[test]
+fn rpath() {
+ let _g = LOCK.lock();
+ reset();
+ let lib = find("rpath").unwrap();
+ assert!(lib
+ .ld_args
+ .contains(&vec!["-rpath".to_string(), "/usr/local/lib".to_string(),]));
+}