Existing tests for Read, Write, and Seek traits

I’ve provided implementations of the Read, Write, and Seek traits and would like to test that they work as expected.

It seems likely that this has already been codified in an abstract sense somewhere in a test suite or testing crate, but I haven’t been able to find anything yet.

Does such a thing exist?

I don't think such a test suite exists because there is no standardized definition for Read, Write, and Seek. For example, some Read+Write+Seek implementations can have their data modified behind their back (e.g. std::fs::File), while this is statically prevented in other implementations (e.g. std::fs::Cursor).

I think the best example you'll find of a "well behaved" implementation are the std::io::Cursor tests.

1 Like

@Michael-F-Bryan thanks for this.

I created my own version of these tests and ran into something unexpected; the assertion on the result of write_vectored fails because only 2 bytes are written when 3 are expected. &[10] doesn't get written for some reason.

Since write_vectored is a provided method, I'm not sure where to start.

Doing the equivalent with write appears to work, and IoSlice::new(&[8, 9, 10]) also works.

According to this, the behavior is expected:

The docs say this as well.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.