Skip to content

Commit ec6c55d

Browse files
committed
assert that write_at doesn't change the seek position
1 parent 984afdc commit ec6c55d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

library/std/src/fs/tests.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rand::RngCore;
88
target_vendor = "apple",
99
))]
1010
use crate::assert_matches::assert_matches;
11+
use crate::bstr::ByteStr;
1112
use crate::char::MAX_LEN_UTF8;
1213
#[cfg(any(
1314
windows,
@@ -500,11 +501,13 @@ fn file_test_append_write_at() {
500501
let msg = b"it's not working!";
501502
check!(fs::write(&filename, &msg));
502503
// write_at should work even in in append mode
503-
let f = check!(fs::File::options().append(true).open(&filename));
504+
let mut f = check!(fs::File::options().append(true).open(&filename));
505+
assert_eq!(check!(f.stream_position()), 0);
504506
assert_eq!(check!(f.write_at(b" ", 5)), 3);
507+
assert_eq!(check!(f.stream_position()), 0);
505508

506509
let content = check!(fs::read(&filename));
507-
assert_eq!(&content, b"it's working!");
510+
assert_eq!(ByteStr::new(&content), ByteStr::new(b"it's working!"));
508511
}
509512

510513
#[test]

library/std/src/os/unix/fs/tests.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use super::*;
2+
use crate::bstr::ByteStr;
3+
use crate::io::Seek;
24

35
#[test]
46
fn read_vectored_at() {
@@ -40,21 +42,23 @@ fn write_vectored_at() {
4042
}
4143
let expected = {
4244
// Open in append mode to test that positioned writes bypass O_APPEND.
43-
let file = fs::File::options().append(true).open(&filename).unwrap();
45+
let mut file = fs::File::options().append(true).open(&filename).unwrap();
4446
let buf0 = b" ";
4547
let buf1 = b"great ";
4648

4749
let iovec = [io::IoSlice::new(buf0), io::IoSlice::new(buf1)];
4850

51+
assert_eq!(file.stream_position().unwrap(), 0);
4952
let n = file.write_vectored_at(&iovec, 11).unwrap();
53+
assert_eq!(file.stream_position().unwrap(), 0);
5054

5155
assert!(n == 4 || n == 11);
5256

5357
if n == 4 { b"pwritev is working!" } else { b"pwritev is great !" }
5458
};
5559

5660
let content = fs::read(&filename).unwrap();
57-
assert_eq!(&content, expected);
61+
assert_eq!(ByteStr::new(&content), ByteStr::new(expected));
5862
}
5963

6064
#[test]

0 commit comments

Comments
 (0)