Skip to content

Commit

Permalink
use simpler mactime2 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Starke committed Sep 25, 2023
1 parent 9d2838c commit ef4fc67
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 232 deletions.
6 changes: 5 additions & 1 deletion tests/mactime2/is_sorted.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::{path::PathBuf, io::{BufReader, Cursor, BufRead}};
use std::{
io::{BufRead, BufReader, Cursor},
path::PathBuf,
};

use assert_cmd::Command;
use more_asserts::assert_le;

/// tests if the result of `mactime2` is always sorted
#[test]
fn is_sorted() {
let mut cmd = Command::cargo_bin("mactime2").unwrap();
Expand Down
44 changes: 44 additions & 0 deletions tests/mactime2/is_stable_sorting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use std::io::{BufReader, Cursor, BufRead};
use lazy_regex::regex;
use assert_cmd::Command;

/// tests if the result of `mactime2` is a stable sort, i.e. if pos(a)<=pos(b) then sorted_pos(a) <= sorted_pos(b)
#[test]
fn is_stable_sorted() {
let mut cmd = Command::cargo_bin("mactime2").unwrap();

let sample_bodyfile =
"0|a|1703937|d/drwxr-xr-x|0|0|4096|1661774613|1661774613|1661774613|1661774613
0|b|11|d/drwx------|0|0|16384|1661774613|1661774613|1661774613|1661774613
0|c|11|d/drwx------|0|0|16384|1661774613|1661774613|1661774613|1661774613";

let result = cmd
.arg("-d")
.arg("-b")
.arg("-")
.write_stdin(sample_bodyfile)
.ok();
assert!(result.is_ok());

let reader = BufReader::new(Cursor::new(result.unwrap().stdout));
let lines: Vec<_> = reader
.lines()
.map_while(Result::ok)
.map(name_of)
.collect();
assert_eq!(lines.len(), 3);
assert_eq!(lines[0].as_ref().unwrap(), "a");
assert_eq!(lines[1].as_ref().unwrap(), "b");
assert_eq!(lines[2].as_ref().unwrap(), "c");
}

fn name_of(line: String) -> Option<String> {
let re = regex!(r#""(?P<name>[^"]*)""#);
let result = re.captures_iter(&line);
for c in result {
if let Some(name) = c.name("name") {
return Some(name.as_str().to_owned())
}
}
None
}
3 changes: 2 additions & 1 deletion tests/mactime2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod help;
mod autocomplete;
mod is_sorted;
mod is_sorted;
mod is_stable_sorting;
81 changes: 0 additions & 81 deletions tests/mactime2_test_ambiguity.rs

This file was deleted.

149 changes: 0 additions & 149 deletions tests/mactime2_test_sorted.rs

This file was deleted.

0 comments on commit ef4fc67

Please sign in to comment.