mod common;
use common::*;
use std::path::Path;
use log::LevelFilter;
use xvc::error::Result;
use xvc::watch;
use xvc_config::XvcVerbosity;
use xvc_test_helper::{create_directory_tree, test_logging};
use xvc_walker::AbsolutePath;
fn create_directory_hierarchy(temp_dir: &Path) -> Result<AbsolutePath> {
create_directory_tree(temp_dir, 5, 5, 1000, Some(23))?;
Ok(AbsolutePath::from(temp_dir))
}
#[test]
#[cfg(unix)]
fn test_file_list() -> Result<()> {
use std::path::PathBuf;
test_logging(LevelFilter::Trace);
let xvc_root = common::run_in_temp_xvc_dir()?;
create_directory_hierarchy(&xvc_root)?;
let x = |cmd: &[&str]| -> Result<String> {
let mut c = vec!["file"];
c.extend(cmd);
common::run_xvc(Some(&xvc_root), &c, XvcVerbosity::Trace)
};
let _xd = |dir: &str, cmd: &[&str]| {
let dir = &xvc_root.join(&PathBuf::from(dir));
let mut c = vec!["-C", dir.to_str().unwrap(), "data"];
c.extend(cmd);
common::run_xvc(Some(&xvc_root), &c, XvcVerbosity::Trace)
};
watch!("begin");
let list_all = x(&["list", "--format", "{{name}}", "--show-dot-files"])?;
watch!(list_all);
let count_all = list_all.trim().lines().count();
watch!(count_all);
assert!(count_all == 33);
let list_no_dots = x(&["list", "--format", "{{name}}"])?;
let count_no_dots = list_no_dots.trim().lines().count();
assert!(count_no_dots == 31);
let list_no_dots_no_summary = x(&["list", "--format", "{{name}}", "--no-summary"])?;
let count_no_dots_no_summary = list_no_dots_no_summary.trim().lines().count();
assert!(count_no_dots_no_summary == 30);
for (sort_option, top_element) in &[
("name-asc", "file-0001.bin"),
("name-desc", "file-0005.bin"),
("size-asc", "file-0001.bin"),
("size-desc", "file-0005.bin"),
] {
let cmd_res = x(&[
"list",
"--format",
"{{name}}",
"--sort",
sort_option,
"dir-0001",
])?;
let top_line = cmd_res.lines().next().unwrap();
assert!(
top_line.ends_with(top_element),
"sort: {sort_option}\ncmd_res: {}",
cmd_res
);
}
clean_up(&xvc_root)
}