mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-15 06:22:47 +00:00
Make sure that mod time of file in the test is before dir created.
This commit is contained in:
parent
9a83bda871
commit
0eef7aea59
1 changed files with 12 additions and 3 deletions
15
src/batch.rs
15
src/batch.rs
|
@ -162,15 +162,24 @@ fn sort_by_meta(a: &Meta, b: &Meta, flags: Flags) -> Ordering {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::fs::{create_dir, File};
|
use std::fs::{create_dir, File};
|
||||||
|
use std::process::Command;
|
||||||
use tempdir::TempDir;
|
use tempdir::TempDir;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_sort_by_meta() {
|
fn test_sort_by_meta() {
|
||||||
let tmp_dir = TempDir::new("test_dir").expect("failed to create temp dir");
|
let tmp_dir = TempDir::new("test_dir").expect("failed to create temp dir");
|
||||||
|
|
||||||
// Create a file;
|
// Create a file and make sure that its mod time is before now.
|
||||||
let path_a = tmp_dir.path().join("a.txt");
|
let path_a = tmp_dir.path().join("a.txt");
|
||||||
File::create(&path_a).expect("failed to create file");
|
File::create(&path_a).expect("failed to create file");
|
||||||
|
let success = Command::new("touch")
|
||||||
|
.arg("-t")
|
||||||
|
.arg("19851116")
|
||||||
|
.arg(&path_a)
|
||||||
|
.status()
|
||||||
|
.unwrap()
|
||||||
|
.success();
|
||||||
|
assert!(success, "failed to exec touch");
|
||||||
let meta_a = Meta::from_path(&path_a).expect("failed to get meta");
|
let meta_a = Meta::from_path(&path_a).expect("failed to get meta");
|
||||||
|
|
||||||
// Create a dir;
|
// Create a dir;
|
||||||
|
@ -207,7 +216,7 @@ mod tests {
|
||||||
..Flags::default()
|
..Flags::default()
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
Ordering::Greater
|
Ordering::Less
|
||||||
);
|
);
|
||||||
|
|
||||||
// Sort by time reversed
|
// Sort by time reversed
|
||||||
|
@ -221,7 +230,7 @@ mod tests {
|
||||||
..Flags::default()
|
..Flags::default()
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
Ordering::Less
|
Ordering::Greater
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue