add tests to verify executable state on Windows

This commit is contained in:
Icxolu 2022-11-24 19:34:17 +01:00 committed by Abin Simon
parent aed96649be
commit c48f0f48f5

View file

@ -112,7 +112,6 @@ mod test {
#[cfg(unix)]
use crate::meta::Permissions;
use crossterm::style::{Color, Stylize};
#[cfg(unix)]
use std::fs::File;
#[cfg(unix)]
use std::os::unix::fs::symlink;
@ -281,4 +280,42 @@ mod test {
file_type.render(&colors)
);
}
#[cfg(windows)]
#[test]
fn test_file_executable() {
let tmp_dir = tempdir().expect("failed to create temp dir");
for ext in FileType::EXECUTABLE_EXTENSIONS {
// Create the file;
let file_path = tmp_dir.path().join(format!("file.{ext}"));
File::create(&file_path).expect("failed to create file");
let meta = file_path.metadata().expect("failed to get metas");
let colors = Colors::new(ThemeOption::NoLscolors);
let file_type = FileType::new(&meta, None, &file_path);
assert_eq!(
".".to_string().with(Color::AnsiValue(40)),
file_type.render(&colors)
);
}
}
#[cfg(windows)]
#[test]
fn test_file_not_executable() {
let tmp_dir = tempdir().expect("failed to create temp dir");
// Create the file;
let file_path = tmp_dir.path().join("file.txt");
File::create(&file_path).expect("failed to create file");
let meta = file_path.metadata().expect("failed to get metas");
let colors = Colors::new(ThemeOption::NoLscolors);
let file_type = FileType::new(&meta, None, &file_path);
assert_eq!(
".".to_string().with(Color::AnsiValue(184)),
file_type.render(&colors)
);
}
}