Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

View File

@@ -0,0 +1,135 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use super::utils::{show_error, TestResult};
use std::ffi::OsStr;
use std::path::Path;
fn to_correct_name(s: &str) -> String {
let mut out = String::with_capacity(s.len());
for c in s.chars() {
if c.is_uppercase() {
if !out.is_empty() {
out.push('_');
}
out.push_str(c.to_lowercase().to_string().as_str());
} else {
out.push(c);
}
}
out
}
fn check_md_doc_path(p: &Path, md_line: &str, ty_line: &str) -> bool {
let parts = md_line.split('/').collect::<Vec<_>>();
if let Some(md_name) = parts.last().and_then(|n| n.split(".md").next()) {
if let Some(name) = ty_line.split_whitespace().filter(|s| !s.is_empty()).nth(2) {
if let Some(name) = name
.split('<')
.next()
.and_then(|n| n.split('{').next())
.and_then(|n| n.split('(').next())
.and_then(|n| n.split(';').next())
{
let correct = to_correct_name(name);
if correct.as_str() == md_name {
return true;
}
show_error(
p,
&format!(
"Invalid markdown file name `{md_name}`, should have been `{correct}`",
),
);
return false;
}
}
show_error(p, &format!("Cannot extract type name from `{ty_line}`"));
} else {
show_error(p, &format!("Cannot extract md name from `{md_line}`"));
}
false
}
fn check_doc_comments_before(p: &Path, lines: &[&str], start: usize) -> bool {
let mut found_docs = false;
for pos in (0..start).rev() {
let trimmed = lines[pos].trim();
if trimmed.starts_with("///") {
if !lines[start].trim().starts_with("pub enum ThreadStatus {") {
show_error(
p,
&format!(
"Types should use common documentation by using `#[doc = include_str!(` \
and by putting the markdown file in the `md_doc` folder instead of `{}`",
&lines[pos],
),
);
return false;
}
return true;
} else if trimmed.starts_with("#[doc = include_str!(") {
found_docs = true;
if !check_md_doc_path(p, trimmed, lines[start]) {
return false;
}
} else if !trimmed.starts_with("#[") && !trimmed.starts_with("//") {
break;
}
}
if !found_docs {
show_error(
p,
&format!(
"Missing documentation for public item: `{}` (if it's not supposed to be a public \
item, use `pub(crate)` instead)",
lines[start],
),
);
return false;
}
true
}
pub fn check_docs(content: &str, p: &Path) -> TestResult {
let mut res = TestResult {
nb_tests: 0,
nb_errors: 0,
};
// No need to check if we are in the `src` or `src/common` folder or if we are in a `ffi.rs`
// file.
if p.file_name().unwrap() == OsStr::new("ffi.rs") {
return res;
}
let path = format!(
"/{}",
p.parent().unwrap().display().to_string().replace('\\', "/")
);
if path.ends_with("/src") || path.ends_with("src/common") {
return res;
}
let lines = content.lines().collect::<Vec<_>>();
for pos in 1..lines.len() {
let line = lines[pos];
let trimmed = line.trim();
if trimmed.starts_with("//!") {
show_error(p, "There shouln't be inner doc comments (`//!`)");
res.nb_tests += 1;
res.nb_errors += 1;
continue;
} else if !line.starts_with("pub fn ")
&& !trimmed.starts_with("pub struct ")
&& !trimmed.starts_with("pub enum ")
{
continue;
}
res.nb_tests += 1;
if !check_doc_comments_before(p, &lines, pos) {
res.nb_errors += 1;
}
}
res
}

View File

@@ -0,0 +1,58 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use super::utils::{show_error, TestResult};
use std::path::Path;
pub fn check_license_header(content: &str, p: &Path) -> TestResult {
let mut lines = content.lines();
let next = lines.next();
let header = "// Take a look at the license at the top of the repository in the LICENSE file.";
match next {
Some(s) if s == header => {
let next = lines.next();
match next {
Some("") => TestResult {
nb_tests: 1,
nb_errors: 0,
},
Some(s) => {
show_error(
p,
&format!("Expected empty line after license header, found `{s}`"),
);
TestResult {
nb_tests: 1,
nb_errors: 1,
}
}
None => {
show_error(p, "This file should very likely not exist...");
TestResult {
nb_tests: 1,
nb_errors: 1,
}
}
}
}
Some(s) => {
show_error(
p,
&format!(
"Expected license header at the top of the file (`{header}`), found: `{s}`",
),
);
TestResult {
nb_tests: 1,
nb_errors: 1,
}
}
None => {
show_error(p, "This (empty?) file should very likely not exist...");
TestResult {
nb_tests: 1,
nb_errors: 1,
}
}
}
}

View File

@@ -0,0 +1,50 @@
// Take a look at the license at the top of the repository in the LICENSE file.
mod docs;
mod headers;
mod signals;
mod utils;
use std::path::Path;
use utils::TestResult;
#[allow(clippy::type_complexity)]
const CHECKS: &[(fn(&str, &Path) -> TestResult, &[&str])] = &[
(headers::check_license_header, &["src", "tests", "examples"]),
(signals::check_signals, &["src"]),
(docs::check_docs, &["src"]),
];
fn handle_tests(res: &mut [TestResult]) {
utils::read_dirs(
&["benches", "examples", "src", "tests"],
&mut |p: &Path, c: &str| {
if let Some(first) = p.iter().next().and_then(|first| first.to_str()) {
for (pos, (check, filter)) in CHECKS.iter().enumerate() {
if filter.contains(&first) {
res[pos] += check(c, p);
}
}
}
},
);
}
#[test]
fn code_checks() {
let mut res = Vec::new();
for _ in CHECKS {
res.push(TestResult {
nb_tests: 0,
nb_errors: 0,
});
}
handle_tests(&mut res);
for r in res {
assert_eq!(r.nb_errors, 0);
assert_ne!(r.nb_tests, 0);
}
}

View File

@@ -0,0 +1,64 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use super::utils::{show_error, TestResult};
use std::path::Path;
fn check_supported_signals_decl<'a>(lines: &mut impl Iterator<Item = &'a str>, p: &Path) -> usize {
for line in lines {
let trimmed = line.trim();
if trimmed.starts_with("const SUPPORTED_SIGNALS: &'static [Signal]") {
if trimmed != "const SUPPORTED_SIGNALS: &[Signal] = supported_signals();" {
show_error(
p,
"SUPPORTED_SIGNALS should be declared using `supported_signals()`",
);
return 1;
}
break;
}
}
0
}
fn check_kill_decl<'a>(lines: &mut impl Iterator<Item = &'a str>, p: &Path) -> usize {
let mut errors = 0;
while let Some(line) = lines.next() {
let trimmed = line.trim();
if trimmed.starts_with("fn kill(") {
show_error(p, "`Process::kill` should not be reimplemented!");
errors += 1;
} else if trimmed.starts_with("fn kill_with(") {
if let Some(line) = lines.next() {
let trimmed = line.trim();
if trimmed.ends_with("crate::sys::convert_signal(signal)?;") || trimmed == "None" {
continue;
} else {
show_error(p, "`Process::kill_with` should use `convert_signal`");
errors += 1;
}
}
}
}
errors
}
pub fn check_signals(content: &str, p: &Path) -> TestResult {
let mut lines = content.lines();
let mut res = TestResult {
nb_tests: 0,
nb_errors: 0,
};
while let Some(line) = lines.next() {
let trimmed = line.trim();
if trimmed.starts_with("impl SystemInner {") {
res.nb_tests += 1;
res.nb_errors += check_supported_signals_decl(&mut lines, p);
} else if trimmed.starts_with("impl ProcessInner {") {
res.nb_tests += 1;
res.nb_errors += check_kill_decl(&mut lines, p);
}
}
res
}

View File

@@ -0,0 +1,58 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use std::fs::{self, File};
use std::io::Read;
use std::path::Path;
pub struct TestResult {
pub nb_tests: usize,
pub nb_errors: usize,
}
impl std::ops::AddAssign for TestResult {
fn add_assign(&mut self, other: Self) {
self.nb_tests += other.nb_tests;
self.nb_errors += other.nb_errors;
}
}
pub fn read_dirs<P: AsRef<Path>, F: FnMut(&Path, &str)>(dirs: &[P], callback: &mut F) {
for dir in dirs {
read_dir(dir, callback);
}
}
fn read_dir<P: AsRef<Path>, F: FnMut(&Path, &str)>(dir: P, callback: &mut F) {
for entry in fs::read_dir(dir).expect("read_dir failed") {
let entry = entry.expect("entry failed");
let file_type = entry.file_type().expect("file_type failed");
let path = entry.path();
if file_type.is_dir() {
read_dir(path, callback);
} else if path
.extension()
.map(|ext| ext == "rs" || ext == "c" || ext == "h")
.unwrap_or(false)
{
let content = read_file(&path);
callback(&path, &content);
}
}
}
fn read_file<P: AsRef<Path>>(p: P) -> String {
let mut f = File::open(&p).expect("read_file::open failed");
let mut content =
String::with_capacity(f.metadata().map(|m| m.len() as usize + 1).unwrap_or(0));
if let Err(e) = f.read_to_string(&mut content) {
panic!(
"read_file::read_to_end failed for `{}: {e:?}",
p.as_ref().display()
);
}
content
}
pub fn show_error(p: &Path, err: &str) {
eprintln!("=> [{}]: {err}", p.display());
}

18
vendor/sysinfo/tests/components.rs vendored Normal file
View File

@@ -0,0 +1,18 @@
// Take a look at the license at the top of the repository in the LICENSE file.
#[cfg(feature = "component")]
#[test]
fn test_components() {
use std::env::var;
let mut c = sysinfo::Components::new();
assert!(c.is_empty());
// Unfortunately, we can't get components in the CI...
if !sysinfo::IS_SUPPORTED_SYSTEM || cfg!(windows) || var("CI").is_ok() {
return;
}
c.refresh(false);
assert!(!c.is_empty());
}

52
vendor/sysinfo/tests/cpu.rs vendored Normal file
View File

@@ -0,0 +1,52 @@
// Take a look at the license at the top of the repository in the LICENSE file.
#![cfg(feature = "system")]
// This test is used to ensure that the CPUs are not loaded by default.
#[test]
fn test_cpu() {
let mut s = sysinfo::System::new();
assert!(s.cpus().is_empty());
if !sysinfo::IS_SUPPORTED_SYSTEM {
return;
}
s.refresh_cpu_all();
assert!(!s.cpus().is_empty());
let s = sysinfo::System::new_all();
assert!(!s.cpus().is_empty());
assert!(!s.cpus()[0].brand().chars().any(|c| c == '\0'));
if !cfg!(target_os = "freebsd") {
// This information is currently not retrieved on freebsd...
assert!(s.cpus().iter().any(|c| !c.brand().is_empty()));
}
assert!(s.cpus().iter().any(|c| !c.vendor_id().is_empty()));
}
#[test]
fn test_physical_core_numbers() {
if sysinfo::IS_SUPPORTED_SYSTEM {
let count = sysinfo::System::physical_core_count();
assert_ne!(count, None);
assert!(count.unwrap() > 0);
}
}
#[test]
fn test_too_rapid_cpu_refresh() {
let mut s = sysinfo::System::new();
assert!(s.cpus().is_empty());
if !sysinfo::IS_SUPPORTED_SYSTEM {
return;
}
s.refresh_cpu_all();
s.refresh_cpu_all();
assert!(s.cpus().iter().any(|c| !c.cpu_usage().is_nan()));
}

186
vendor/sysinfo/tests/disk.rs vendored Normal file
View File

@@ -0,0 +1,186 @@
// Take a look at the license at the top of the repository in the LICENSE file.
#[cfg(all(feature = "system", feature = "disk"))]
fn should_skip() -> bool {
if !sysinfo::IS_SUPPORTED_SYSTEM {
return true;
}
// If we don't have any physical core present, it's very likely that we're inside a VM...
sysinfo::System::physical_core_count().unwrap_or_default() == 0
}
#[test]
#[cfg(all(feature = "system", feature = "disk"))]
fn test_disks() {
if should_skip() {
return;
}
let mut disks = sysinfo::Disks::new();
assert!(disks.list().is_empty());
disks.refresh(false);
assert!(!disks.list().is_empty());
}
#[test]
#[cfg(all(feature = "system", feature = "disk"))]
fn test_disk_refresh_kind() {
use itertools::Itertools;
use sysinfo::{DiskKind, DiskRefreshKind, Disks};
if should_skip() {
return;
}
for fs in [
DiskRefreshKind::with_kind,
DiskRefreshKind::without_kind,
DiskRefreshKind::with_storage,
DiskRefreshKind::without_storage,
DiskRefreshKind::with_io_usage,
DiskRefreshKind::without_io_usage,
]
.iter()
.powerset()
{
let mut refreshes = DiskRefreshKind::nothing();
for f in fs {
refreshes = f(refreshes);
}
let assertions = |name: &'static str, disks: &Disks| {
if refreshes.kind() {
// This would ideally assert that *all* are refreshed, but we settle for a weaker
// assertion because failures can't be distinguished from "not refreshed" values.
#[cfg(not(any(target_os = "freebsd", target_os = "windows")))]
assert!(
disks
.iter()
.any(|disk| disk.kind() != DiskKind::Unknown(-1)),
"{name}: disk.kind should be refreshed"
);
} else {
assert!(
disks
.iter()
.all(|disk| disk.kind() == DiskKind::Unknown(-1)),
"{name}: disk.kind should not be refreshed"
);
}
if refreshes.storage() {
// These would ideally assert that *all* are refreshed, but we settle for a weaker
// assertion because failures can't be distinguished from "not refreshed" values.
assert!(
disks
.iter()
.any(|disk| disk.available_space() != Default::default()),
"{name}: disk.available_space should be refreshed"
);
assert!(
disks
.iter()
.any(|disk| disk.total_space() != Default::default()),
"{name}: disk.total_space should be refreshed"
);
// We can't assert anything about booleans, since false is indistinguishable from
// not-refreshed
} else {
assert!(
disks
.iter()
.all(|disk| disk.available_space() == Default::default()),
"{name}: disk.available_space should not be refreshed"
);
assert!(
disks
.iter()
.all(|disk| disk.total_space() == Default::default()),
"{name}: disk.total_space should not be refreshed"
);
}
if refreshes.io_usage() {
// This would ideally assert that *all* are refreshed, but we settle for a weaker
// assertion because failures can't be distinguished from "not refreshed" values.
assert!(
disks.iter().any(|disk| disk.usage() != Default::default()),
"{name}: disk.usage should be refreshed"
);
} else {
assert!(
disks.iter().all(|disk| disk.usage() == Default::default()),
"{name}: disk.usage should not be refreshed"
);
}
};
// load and refresh with the desired details should work
let disks = Disks::new_with_refreshed_list_specifics(refreshes);
assertions("full", &disks);
// load with minimal `DiskRefreshKind`, then refresh for added detail should also work!
let mut disks = Disks::new_with_refreshed_list_specifics(DiskRefreshKind::nothing());
disks.refresh_specifics(false, refreshes);
assertions("incremental", &disks);
}
}
#[test]
#[cfg(all(feature = "system", feature = "disk"))]
fn test_disks_usage() {
use std::fs::{remove_file, File};
use std::io::Write;
use std::path::{Path, PathBuf};
use std::thread::sleep;
use sysinfo::Disks;
if should_skip() {
return;
}
// The test always fails in CI on Linux. For some unknown reason, /proc/diskstats just doesn't
// update, regardless of how long we wait. Until the root cause is discovered, skip the test
// in CI.
if cfg!(target_os = "linux") && std::env::var("CI").is_ok() {
return;
}
let mut disks = Disks::new_with_refreshed_list();
let path = match std::env::var("CARGO_TARGET_DIR") {
Ok(p) => Path::new(&p).join("data.tmp"),
_ => PathBuf::from("target/data.tmp"),
};
let mut file = File::create(&path).expect("failed to create temporary file");
// Write 10mb worth of data to the temp file.
let data = vec![1u8; 10 * 1024 * 1024];
file.write_all(&data).unwrap();
// The sync_all call is important to ensure all the data is persisted to disk. Without
// the call, this test is flaky.
file.sync_all().unwrap();
// Wait a bit just in case
sleep(std::time::Duration::from_millis(500));
disks.refresh(false);
// Depending on the OS and how disks are configured, the disk usage may be the exact same
// across multiple disks. To account for this, collect the disk usages and dedup.
let mut disk_usages = disks.list().iter().map(|d| d.usage()).collect::<Vec<_>>();
disk_usages.dedup();
let mut written_bytes = 0;
for disk_usage in disk_usages {
written_bytes += disk_usage.written_bytes;
}
let _ = remove_file(path);
// written_bytes should have increased by about 10mb, but this is not fully reliable in CI Linux. For now,
// just verify the number is non-zero.
assert!(written_bytes > 0);
}

3
vendor/sysinfo/tests/extras.rs vendored Normal file
View File

@@ -0,0 +1,3 @@
// Take a look at the license at the top of the repository in the LICENSE file.
mod code_checkers;

16
vendor/sysinfo/tests/network.rs vendored Normal file
View File

@@ -0,0 +1,16 @@
// Take a look at the license at the top of the repository in the LICENSE file.
// This test is used to ensure that the networks are not loaded by default.
#[cfg(feature = "network")]
#[test]
fn test_networks() {
use sysinfo::Networks;
if sysinfo::IS_SUPPORTED_SYSTEM {
let mut n = Networks::new();
assert_eq!(n.iter().count(), 0);
n.refresh(false);
assert!(n.iter().count() > 0);
}
}

1147
vendor/sysinfo/tests/process.rs vendored Normal file

File diff suppressed because it is too large Load Diff

12
vendor/sysinfo/tests/send_sync.rs vendored Normal file
View File

@@ -0,0 +1,12 @@
// Take a look at the license at the top of the repository in the LICENSE file.
#[test]
#[allow(clippy::extra_unused_type_parameters)]
#[cfg(feature = "system")]
fn test_send_sync() {
fn is_send<T: Send>() {}
fn is_sync<T: Sync>() {}
is_send::<sysinfo::System>();
is_sync::<sysinfo::System>();
}

256
vendor/sysinfo/tests/system.rs vendored Normal file
View File

@@ -0,0 +1,256 @@
// Take a look at the license at the top of the repository in the LICENSE file.
#![cfg(feature = "system")]
#![allow(clippy::assertions_on_constants)]
use sysinfo::{ProcessesToUpdate, System};
#[test]
fn test_refresh_system() {
let mut sys = System::new();
sys.refresh_memory();
sys.refresh_cpu_usage();
// We don't want to test on unsupported systems.
if sysinfo::IS_SUPPORTED_SYSTEM {
assert!(sys.total_memory() != 0);
assert!(sys.free_memory() != 0);
}
assert!(sys.total_memory() >= sys.free_memory());
assert!(sys.total_swap() >= sys.free_swap());
}
#[test]
fn test_refresh_process() {
let mut sys = System::new();
assert!(sys.processes().is_empty(), "no process should be listed!");
// We don't want to test on unsupported systems.
#[cfg(not(feature = "apple-sandbox"))]
if sysinfo::IS_SUPPORTED_SYSTEM {
assert_eq!(
sys.refresh_processes(
ProcessesToUpdate::Some(&[
sysinfo::get_current_pid().expect("failed to get current pid")
]),
false
),
1,
"process not listed",
);
// Ensure that the process was really added to the list!
assert!(sys
.process(sysinfo::get_current_pid().expect("failed to get current pid"))
.is_some());
}
}
#[test]
fn test_get_process() {
let mut sys = System::new();
sys.refresh_processes(ProcessesToUpdate::All, false);
let current_pid = match sysinfo::get_current_pid() {
Ok(pid) => pid,
_ => {
if !sysinfo::IS_SUPPORTED_SYSTEM {
return;
}
panic!("get_current_pid should work!");
}
};
if let Some(p) = sys.process(current_pid) {
assert!(p.memory() > 0);
} else {
#[cfg(not(feature = "apple-sandbox"))]
assert!(!sysinfo::IS_SUPPORTED_SYSTEM);
}
}
#[test]
fn check_if_send_and_sync() {
trait Foo {
fn foo(&self) {}
}
impl<T> Foo for T where T: Send {}
trait Bar {
fn bar(&self) {}
}
impl<T> Bar for T where T: Sync {}
let mut sys = System::new();
sys.refresh_processes(ProcessesToUpdate::All, false);
let current_pid = match sysinfo::get_current_pid() {
Ok(pid) => pid,
_ => {
if !sysinfo::IS_SUPPORTED_SYSTEM {
return;
}
panic!("get_current_pid should work!");
}
};
if let Some(p) = sys.process(current_pid) {
p.foo(); // If this doesn't compile, it'll simply mean that the Process type
// doesn't implement the Send trait.
p.bar(); // If this doesn't compile, it'll simply mean that the Process type
// doesn't implement the Sync trait.
} else {
#[cfg(not(feature = "apple-sandbox"))]
assert!(!sysinfo::IS_SUPPORTED_SYSTEM);
}
}
#[test]
fn check_hostname_has_no_nuls() {
if let Some(hostname) = System::host_name() {
assert!(!hostname.contains('\u{0}'))
}
}
#[test]
fn check_uptime() {
let uptime = System::uptime();
if sysinfo::IS_SUPPORTED_SYSTEM {
std::thread::sleep(std::time::Duration::from_millis(1000));
let new_uptime = System::uptime();
assert!(uptime < new_uptime);
}
}
#[test]
fn check_boot_time() {
if sysinfo::IS_SUPPORTED_SYSTEM {
assert_ne!(System::boot_time(), 0);
}
}
// This test is used to ensure that the CPU usage computation isn't completely going off
// when refreshing it too frequently (ie, multiple times in a row in a very small interval).
#[test]
#[ignore] // This test MUST be run on its own to prevent wrong CPU usage measurements.
fn test_consecutive_cpu_usage_update() {
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
use sysinfo::{Pid, ProcessRefreshKind, System};
if !sysinfo::IS_SUPPORTED_SYSTEM {
return;
}
let mut sys = System::new_all();
assert!(!sys.cpus().is_empty());
sys.refresh_processes_specifics(
ProcessesToUpdate::All,
true,
ProcessRefreshKind::nothing().with_cpu(),
);
let stop = Arc::new(AtomicBool::new(false));
// Spawning a few threads to ensure that it will actually have an impact on the CPU usage.
for it in 0..sys.cpus().len() / 2 + 1 {
let stop_c = Arc::clone(&stop);
std::thread::spawn(move || {
while !stop_c.load(Ordering::Relaxed) {
if it != 0 {
// The first thread runs at 100% to be sure it'll be noticeable.
std::thread::sleep(Duration::from_millis(1));
}
}
});
}
let mut pids = sys
.processes()
.iter()
.map(|(pid, _)| *pid)
.take(2)
.collect::<Vec<_>>();
let pid = std::process::id();
pids.push(Pid::from_u32(pid));
assert_eq!(pids.len(), 3);
for it in 0..3 {
std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL + Duration::from_millis(1));
for pid in &pids {
sys.refresh_processes_specifics(
ProcessesToUpdate::Some(&[*pid]),
true,
ProcessRefreshKind::nothing().with_cpu(),
);
}
// To ensure that Linux doesn't give too high numbers.
assert!(
sys.process(pids[2]).unwrap().cpu_usage() < sys.cpus().len() as f32 * 100.,
"using ALL CPU: failed at iteration {}",
it
);
// To ensure it's not 0 either.
assert!(
sys.process(pids[2]).unwrap().cpu_usage() > 0.,
"using NO CPU: failed at iteration {}",
it
);
}
stop.store(false, Ordering::Relaxed);
}
#[test]
fn test_refresh_memory() {
if !sysinfo::IS_SUPPORTED_SYSTEM {
return;
}
// On linux, since it's the same file, memory information are always retrieved.
let is_linux = cfg!(any(target_os = "linux", target_os = "android"));
let mut s = System::new();
assert_eq!(s.total_memory(), 0);
assert_eq!(s.free_memory(), 0);
s.refresh_memory_specifics(sysinfo::MemoryRefreshKind::nothing().with_ram());
assert_ne!(s.total_memory(), 0);
assert_ne!(s.free_memory(), 0);
if is_linux {
assert_ne!(s.total_swap(), 0);
assert_ne!(s.free_swap(), 0);
} else {
assert_eq!(s.total_swap(), 0);
assert_eq!(s.free_swap(), 0);
}
let mut s = System::new();
assert_eq!(s.total_swap(), 0);
assert_eq!(s.free_swap(), 0);
if std::env::var("APPLE_CI").is_ok() {
// Apparently there is no swap for macOS in CIs so can't run futher than this point.
return;
}
s.refresh_memory_specifics(sysinfo::MemoryRefreshKind::nothing().with_swap());
// SWAP can be 0 on macOS so this test is disabled
#[cfg(not(target_os = "macos"))]
{
assert_ne!(s.total_swap(), 0);
assert_ne!(s.free_swap(), 0);
}
if is_linux {
assert_ne!(s.total_memory(), 0);
assert_ne!(s.free_memory(), 0);
} else {
assert_eq!(s.total_memory(), 0);
assert_eq!(s.free_memory(), 0);
}
let mut s = System::new();
s.refresh_memory();
// SWAP can be 0 on macOS so this test is disabled
#[cfg(not(target_os = "macos"))]
{
assert_ne!(s.total_swap(), 0);
assert_ne!(s.free_swap(), 0);
}
assert_ne!(s.total_memory(), 0);
assert_ne!(s.free_memory(), 0);
}

27
vendor/sysinfo/tests/users.rs vendored Normal file
View File

@@ -0,0 +1,27 @@
// Take a look at the license at the top of the repository in the LICENSE file.
// This test is used to ensure that the users are not loaded by default.
//
// users.groupps() multiple times doesn't return the same output https://github.com/GuillaumeGomez/sysinfo/issues/1233
//
// Example:
// ---- test_users 1 stdout ----
// user: Administrator group:[Group { inner: GroupInner { id: Gid(0), name: "Administrators" } }]
// ---- test_users 2 stdout ----
// user: Administrator group:[]
#[cfg(feature = "user")]
#[test]
fn test_users() {
use sysinfo::Users;
if sysinfo::IS_SUPPORTED_SYSTEM {
let mut users = Users::new();
assert_eq!(users.iter().count(), 0);
users.refresh();
assert!(users.iter().count() > 0);
let count = users.first().unwrap().groups().iter().len();
for _ in 1..10 {
assert!(users.first().unwrap().groups().iter().len() == count)
}
}
}