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

Merge pull request #7767 from cakebaker/bump_bincode

Bump `bincode` & adapt test code to API changes
This commit is contained in:
Sylvestre Ledru 2025-04-17 17:58:39 +02:00 committed by GitHub
commit 785ae3c954
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 additions and 12 deletions

View file

@ -13,7 +13,7 @@ use uutests::util::TestScenario;
use uutests::util_name;
#[cfg(not(any(target_os = "macos", target_os = "openbsd")))]
use bincode::serialize;
use bincode::{config, serde::encode_to_vec};
use regex::Regex;
#[cfg(not(any(target_os = "macos", target_os = "openbsd")))]
use serde::Serialize;
@ -134,12 +134,14 @@ fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() {
}
arr
}
// Creates a file utmp records of three different types including a valid BOOT_TIME entry
fn utmp(path: &PathBuf) {
// Definitions of our utmpx structs
const BOOT_TIME: i32 = 2;
const RUN_LVL: i32 = 1;
const USER_PROCESS: i32 = 7;
#[derive(Serialize)]
#[repr(C)]
pub struct TimeVal {
@ -153,6 +155,7 @@ fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() {
e_termination: i16,
e_exit: i16,
}
#[derive(Serialize)]
#[repr(C, align(4))]
pub struct Utmp {
@ -230,9 +233,10 @@ fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() {
glibc_reserved: [0; 20],
};
let mut buf = serialize(&utmp).unwrap();
buf.append(&mut serialize(&utmp1).unwrap());
buf.append(&mut serialize(&utmp2).unwrap());
let config = config::legacy();
let mut buf = encode_to_vec(utmp, config).unwrap();
buf.append(&mut encode_to_vec(utmp1, config).unwrap());
buf.append(&mut encode_to_vec(utmp2, config).unwrap());
let mut f = File::create(path).unwrap();
f.write_all(&buf).unwrap();
}