Skip to content

Commit

Permalink
Impl test for listing invalid UTF8 trash items
Browse files Browse the repository at this point in the history
* Both UTF8 tests are gated to non-macOS, non-Android, and non-iOS
  Unixes.
  • Loading branch information
joshuamegnauth54 committed Jun 17, 2024
1 parent 2f31116 commit 209db9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ mod os_limited {
use super::{get_unique_name, init_logging};
use serial_test::serial;
use std::collections::{hash_map::Entry, HashMap};
use std::ffi::OsString;
use std::ffi::{OsStr, OsString};
use std::fs::File;
use std::os::unix::ffi::OsStringExt;

use crate as trash;

Expand Down Expand Up @@ -94,6 +95,22 @@ mod os_limited {
let _ = trash::os_limited::purge_all(items.iter().flat_map(|(_name, item)| item));
}

#[test]
#[serial]
fn list_invalid_utf8() {
let mut name = OsStr::new(&get_unique_name()).to_os_string().into_encoded_bytes();
name.push(168);
let name = OsString::from_vec(name);
File::create(&name).unwrap();

// Delete, list, and remove file with an invalid UTF8 name
// Listing items is already exhaustively checked above, so this test is mainly concerned
// with checking that listing non-Unicode names does not panic
trash::delete(&name).unwrap();
let item = trash::os_limited::list().unwrap().into_iter().find(|item| item.name == name).unwrap();
let _ = trash::os_limited::purge_all([item]);
}

#[test]
fn purge_empty() {
init_logging();
Expand Down
1 change: 1 addition & 0 deletions tests/trash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ fn create_remove_single_file() {
assert!(File::open(&name).is_err());
}

#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
#[test]
#[serial]
fn create_remove_single_file_invalid_utf8() {
Expand Down

0 comments on commit 209db9d

Please sign in to comment.