about summary refs log tree commit diff
path: root/library/std/src/sys/pal/unix/os/tests.rs
diff options
context:
space:
mode:
authorThom Chiovoloni <thom@shift.click>2022-08-18 20:23:01 -0700
committerMads Marquart <mads@marquart.dk>2024-10-10 18:36:12 +0200
commitcbe428d8cb60f901cae2c99a5aff0f563b142681 (patch)
treefd17d370470821d4134a59346ee8bf4596351223 /library/std/src/sys/pal/unix/os/tests.rs
parent4cc494bbfe9911d24f3ee521f98d5c6bb7e3ffe8 (diff)
downloadrust-cbe428d8cb60f901cae2c99a5aff0f563b142681.tar.gz
rust-cbe428d8cb60f901cae2c99a5aff0f563b142681.zip
use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` as a `TMPDIR` fallback on darwin
Diffstat (limited to 'library/std/src/sys/pal/unix/os/tests.rs')
-rw-r--r--library/std/src/sys/pal/unix/os/tests.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/library/std/src/sys/pal/unix/os/tests.rs b/library/std/src/sys/pal/unix/os/tests.rs
index efc29955b05..ab9742fc677 100644
--- a/library/std/src/sys/pal/unix/os/tests.rs
+++ b/library/std/src/sys/pal/unix/os/tests.rs
@@ -21,3 +21,28 @@ fn test_parse_glibc_version() {
         assert_eq!(parsed, super::parse_glibc_version(version_str));
     }
 }
+
+// Smoke check `confstr`, do it for several hint values, to ensure our resizing
+// logic is correct.
+#[test]
+#[cfg(target_os = "macos")]
+fn test_confstr() {
+    for key in [libc::_CS_DARWIN_USER_TEMP_DIR, libc::_CS_PATH] {
+        let value_nohint = super::confstr(key, None).unwrap_or_else(|e| {
+            panic!("confstr({key}, None) failed: {e:?}");
+        });
+        let end = (value_nohint.len() + 1) * 2;
+        for hint in 0..end {
+            assert_eq!(
+                super::confstr(key, Some(hint)).as_deref().ok(),
+                Some(&*value_nohint),
+                "confstr({key}, Some({hint})) failed",
+            );
+        }
+    }
+    // Smoke check that we don't loop forever or something if the input was not valid.
+    for hint in [None, Some(0), Some(1)] {
+        let hopefully_invalid = 123456789_i32;
+        assert!(super::confstr(hopefully_invalid, hint).is_err());
+    }
+}