Lines
100 %
Functions
Branches
use super::*;
#[test]
fn an_existing_tree_is_removed() {
let dir = tempfile::tempdir().unwrap();
let tree = dir.path().join("coverage");
std::fs::create_dir_all(tree.join("nested")).unwrap();
std::fs::write(tree.join("nested/index.html"), "stale").unwrap();
remove_dir_if_present(&tree).unwrap();
assert!(!tree.exists());
}
fn a_missing_tree_is_not_an_error() {
remove_dir_if_present(&dir.path().join("absent")).unwrap();
fn a_tree_that_cannot_be_removed_is_an_error() {
let file = dir.path().join("not-a-dir");
std::fs::write(&file, "x").unwrap();
assert!(remove_dir_if_present(&file).is_err());
fn an_existing_file_is_removed() {
let file = dir.path().join("disdoc.html");
std::fs::write(&file, "stale").unwrap();
remove_file_if_present(&file).unwrap();
assert!(!file.exists());
fn a_missing_file_is_not_an_error() {
remove_file_if_present(&dir.path().join("absent.html")).unwrap();
fn a_file_that_cannot_be_removed_is_an_error() {
assert!(remove_file_if_present(dir.path()).is_err());
fn only_not_found_is_ignored() {
assert!(ignore_not_found(Err(io::Error::from(ErrorKind::NotFound))).is_ok());
assert!(ignore_not_found(Err(io::Error::from(ErrorKind::PermissionDenied))).is_err());
assert!(ignore_not_found(Ok(())).is_ok());