1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

Merge pull request #6514 from lcheylus/openbsd-uptime

uptime: add support for OpenBSD using utmp
This commit is contained in:
Sylvestre Ledru 2024-06-30 21:27:48 +02:00 committed by GitHub
commit 96fa8e9480
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 410 additions and 352 deletions

View file

@ -8,16 +8,16 @@
use crate::common::util::TestScenario;
#[cfg(not(target_os = "macos"))]
#[cfg(not(any(target_os = "macos", target_os = "openbsd")))]
use bincode::serialize;
use regex::Regex;
#[cfg(not(target_os = "macos"))]
#[cfg(not(any(target_os = "macos", target_os = "openbsd")))]
use serde::Serialize;
#[cfg(not(target_os = "macos"))]
#[cfg(not(any(target_os = "macos", target_os = "openbsd")))]
use serde_big_array::BigArray;
#[cfg(not(target_os = "macos"))]
#[cfg(not(any(target_os = "macos", target_os = "openbsd")))]
use std::fs::File;
#[cfg(not(target_os = "macos"))]
#[cfg(not(any(target_os = "macos", target_os = "openbsd")))]
use std::{io::Write, path::PathBuf};
#[test]
@ -26,7 +26,6 @@ fn test_invalid_arg() {
}
#[test]
#[cfg(not(target_os = "openbsd"))]
fn test_uptime() {
TestScenario::new(util_name!())
.ucmd()
@ -83,7 +82,7 @@ fn test_uptime_with_fifo() {
}
#[test]
#[cfg(not(any(target_os = "openbsd", target_os = "freebsd")))]
#[cfg(not(target_os = "freebsd"))]
fn test_uptime_with_non_existent_file() {
// Disabled for freebsd, since it doesn't use the utmpxname() sys call to change the default utmpx
// file that is accessed using getutxent()
@ -232,7 +231,6 @@ fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() {
}
#[test]
#[cfg(not(target_os = "openbsd"))]
fn test_uptime_with_extra_argument() {
let ts = TestScenario::new(util_name!());
@ -244,7 +242,6 @@ fn test_uptime_with_extra_argument() {
}
/// Checks whether uptime displays the correct stderr msg when its called with a directory
#[test]
#[cfg(not(target_os = "openbsd"))]
fn test_uptime_with_dir() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
@ -258,7 +255,15 @@ fn test_uptime_with_dir() {
}
#[test]
#[cfg(not(target_os = "openbsd"))]
#[cfg(target_os = "openbsd")]
fn test_uptime_check_users_openbsd() {
new_ucmd!()
.args(&["openbsd_utmp"])
.run()
.stdout_contains("4 users");
}
#[test]
fn test_uptime_since() {
let re = Regex::new(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}").unwrap();