Skip to content

Commit

Permalink
w: Add tests for date formatting and fetching cmdline
Browse files Browse the repository at this point in the history
  • Loading branch information
fortifiedhill committed Mar 27, 2024
1 parent 61789e2 commit bf4c480
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/uu/w/src/w.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,27 @@ pub fn uu_app() -> Command {
.action(ArgAction::SetTrue),
)
}

#[cfg(test)]
mod tests {
use time::OffsetDateTime;
use crate::format_time;
use crate::fetch_cmdline;
use std::{fs::read_to_string, path::Path, process};


#[test]
fn test_format_time() {
let unix_epoc = OffsetDateTime::UNIX_EPOCH;
assert_eq!(format_time(unix_epoc).unwrap(), "00:00");
}

#[test]
// Get PID of current process and use that for cmdline testing
fn test_fetch_cmdline() {
// uucore's utmpx returns an i32, so we cast to that to mimic it.
let pid = process::id() as i32;
let path = Path::new("/proc").join(pid.to_string()).join("cmdline");
assert_eq!(read_to_string(path).unwrap(), fetch_cmdline(pid).unwrap())
}
}

0 comments on commit bf4c480

Please sign in to comment.