Skip to content

Commit

Permalink
add tests to verify executable state on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Icxolu authored and meain committed Nov 26, 2022
1 parent aed9664 commit c48f0f4
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/meta/filetype.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
);
}
}

0 comments on commit c48f0f4

Please sign in to comment.