Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clippy fixes #251

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions tests/spooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn test_automatic_rollover() {
let mut buf = Vec::new();

assert!(!t.is_rolled());
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 0);
assert_eq!(t.stream_position().unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 0);
assert_eq!(buf.as_slice(), b"");
buf.clear();
Expand All @@ -24,21 +24,21 @@ fn test_automatic_rollover() {

assert_eq!(t.write(b"fghijklmno").unwrap(), 10);

assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 15);
assert_eq!(t.stream_position().unwrap(), 15);
assert!(t.is_rolled());
}

#[test]
fn test_explicit_rollover() {
let mut t = SpooledTempFile::new(100);
assert_eq!(t.write(b"abcdefghijklmnopqrstuvwxyz").unwrap(), 26);
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26);
assert_eq!(t.stream_position().unwrap(), 26);
assert!(!t.is_rolled());

// roll over explicitly
assert!(t.roll().is_ok());
assert!(t.is_rolled());
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26);
assert_eq!(t.stream_position().unwrap(), 26);

let mut buf = Vec::new();
assert_eq!(t.read_to_end(&mut buf).unwrap(), 0);
Expand All @@ -48,15 +48,15 @@ fn test_explicit_rollover() {
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 26);
assert_eq!(buf.as_slice(), b"abcdefghijklmnopqrstuvwxyz");
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26);
assert_eq!(t.stream_position().unwrap(), 26);
}

// called by test_seek_{buffer, file}
// assumes t is empty and offset is 0 to start
fn test_seek(t: &mut SpooledTempFile) {
assert_eq!(t.write(b"abcdefghijklmnopqrstuvwxyz").unwrap(), 26);

assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26); // tell()
assert_eq!(t.stream_position().unwrap(), 26); // tell()
assert_eq!(t.seek(SeekFrom::Current(-1)).unwrap(), 25);
assert_eq!(t.seek(SeekFrom::Current(1)).unwrap(), 26);
assert_eq!(t.seek(SeekFrom::Current(1)).unwrap(), 27);
Expand Down Expand Up @@ -110,7 +110,7 @@ fn test_seek_read(t: &mut SpooledTempFile) {
buf.clear();

// now we're at the end again
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26); // tell()
assert_eq!(t.stream_position().unwrap(), 26); // tell()
assert_eq!(t.read_to_end(&mut buf).unwrap(), 0);
assert_eq!(buf.as_slice(), b"");
buf.clear();
Expand All @@ -122,7 +122,7 @@ fn test_seek_read(t: &mut SpooledTempFile) {
assert_eq!(buf, *b"fghij");

// read again from current spot
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 10); // tell()
assert_eq!(t.stream_position().unwrap(), 10); // tell()
assert!(t.read_exact(&mut buf).is_ok());
assert_eq!(buf, *b"klmno");

Expand Down Expand Up @@ -190,11 +190,11 @@ fn test_overwrite_and_extend_rollover() {
assert_eq!(t.write(b"abcdefghijklmno").unwrap(), 15);
assert!(!t.is_rolled());
assert_eq!(t.seek(SeekFrom::End(-5)).unwrap(), 10);
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 10); // tell()
assert_eq!(t.stream_position().unwrap(), 10); // tell()
assert!(!t.is_rolled());
assert_eq!(t.write(b"0123456789)!@#$%^&*(").unwrap(), 20);
assert!(t.is_rolled());
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 30); // tell()
assert_eq!(t.stream_position().unwrap(), 30); // tell()
let mut buf = Vec::new();
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 30);
Expand Down Expand Up @@ -247,11 +247,11 @@ fn test_set_len(t: &mut SpooledTempFile) {
assert!(t.set_len(10).is_ok());

// position should not have moved
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26); // tell()
assert_eq!(t.stream_position().unwrap(), 26); // tell()

assert_eq!(t.read_to_end(&mut buf).unwrap(), 0);
assert_eq!(buf.as_slice(), b"");
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26); // tell()
assert_eq!(t.stream_position().unwrap(), 26); // tell()
buf.clear();

// read whole thing
Expand All @@ -262,7 +262,7 @@ fn test_set_len(t: &mut SpooledTempFile) {

// set_len to expand beyond the end
assert!(t.set_len(40).is_ok());
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 10); // tell()
assert_eq!(t.stream_position().unwrap(), 10); // tell()
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 40);
assert_eq!(
Expand Down Expand Up @@ -290,17 +290,17 @@ fn test_set_len_rollover() {
let mut t = spooled_tempfile(10);
assert_eq!(t.write(b"abcde").unwrap(), 5);
assert!(!t.is_rolled());
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 5); // tell()
assert_eq!(t.stream_position().unwrap(), 5); // tell()

assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 5);
assert_eq!(buf.as_slice(), b"abcde");
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 5); // tell()
assert_eq!(t.stream_position().unwrap(), 5); // tell()
buf.clear();

assert!(t.set_len(20).is_ok());
assert!(t.is_rolled());
assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 5); // tell()
assert_eq!(t.stream_position().unwrap(), 5); // tell()
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 20);
assert_eq!(buf.as_slice(), b"abcde\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
Expand Down
20 changes: 10 additions & 10 deletions tests/tempdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl PathExt for Path {

fn test_tempdir() {
let path = {
let p = t!(Builder::new().prefix("foobar").tempdir_in(&Path::new(".")));
let p = t!(Builder::new().prefix("foobar").tempdir_in(Path::new(".")));
let p = p.path();
assert!(p.to_str().unwrap().contains("foobar"));
p.to_path_buf()
Expand Down Expand Up @@ -159,17 +159,17 @@ fn recursive_mkdir_rel() {
cwd.display(),
path.exists()
);
t!(fs::create_dir(&path));
t!(fs::create_dir(path));
assert!(path.is_dir());
t!(fs::create_dir_all(&path));
t!(fs::create_dir_all(path));
assert!(path.is_dir());
}

fn recursive_mkdir_dot() {
let dot = Path::new(".");
t!(fs::create_dir_all(&dot));
t!(fs::create_dir_all(dot));
let dotdot = Path::new("..");
t!(fs::create_dir_all(&dotdot));
t!(fs::create_dir_all(dotdot));
}

fn recursive_mkdir_rel_2() {
Expand All @@ -181,7 +181,7 @@ fn recursive_mkdir_rel_2() {
cwd.display(),
path.exists()
);
t!(fs::create_dir_all(&path));
t!(fs::create_dir_all(path));
assert!(path.is_dir());
assert!(path.parent().unwrap().is_dir());
let path2 = Path::new("quux/blat");
Expand All @@ -191,7 +191,7 @@ fn recursive_mkdir_rel_2() {
cwd.display()
);
t!(fs::create_dir("quux"));
t!(fs::create_dir_all(&path2));
t!(fs::create_dir_all(path2));
assert!(path2.is_dir());
assert!(path2.parent().unwrap().is_dir());
}
Expand All @@ -204,9 +204,9 @@ pub fn test_remove_dir_all_ok() {

println!("making {}", root.display());
t!(fs::create_dir(&root));
t!(fs::create_dir(&root.join("foo")));
t!(fs::create_dir(&root.join("foo").join("bar")));
t!(fs::create_dir(&root.join("foo").join("bar").join("blat")));
t!(fs::create_dir(root.join("foo")));
t!(fs::create_dir(root.join("foo").join("bar")));
t!(fs::create_dir(root.join("foo").join("bar").join("blat")));
t!(fs::remove_dir_all(&root));
assert!(!root.exists());
assert!(!root.join("bar").exists());
Expand Down