Skip to content

Commit 066b445

Browse files
committed
WIP: Move std::io tests into alloctests
1 parent d84260c commit 066b445

14 files changed

Lines changed: 63 additions & 36 deletions

File tree

library/alloc/src/io/buffered/bufreader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,9 @@ impl<R: ?Sized> BufReader<R> {
295295
}
296296

297297
// This is only used by a test which asserts that the initialization-tracking is correct.
298-
#[cfg(test)]
299298
impl<R: ?Sized> BufReader<R> {
299+
#[doc(hidden)]
300+
#[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")]
300301
#[allow(missing_docs)]
301302
pub fn initialized(&self) -> bool {
302303
self.buf.initialized()

library/alloc/src/io/buffered/bufreader/buffer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ impl Buffer {
7979
}
8080

8181
// This is only used by a test which asserts that the initialization-tracking is correct.
82-
#[cfg(test)]
82+
#[doc(hidden)]
83+
#[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")]
8384
pub fn initialized(&self) -> bool {
8485
self.initialized
8586
}

library/alloc/src/io/buffered/bufwriter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl<W: Write> BufWriter<W> {
8989
/// use std::io::BufWriter;
9090
/// use std::net::TcpStream;
9191
///
92+
/// # #[expect(unused_mut)]
9293
/// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
9394
/// ```
9495
#[stable(feature = "rust1", since = "1.0.0")]
@@ -121,6 +122,7 @@ impl<W: Write> BufWriter<W> {
121122
/// use std::net::TcpStream;
122123
///
123124
/// let stream = TcpStream::connect("127.0.0.1:34254").unwrap();
125+
/// # #[expect(unused_mut)]
124126
/// let mut buffer = BufWriter::with_capacity(100, stream);
125127
/// ```
126128
#[stable(feature = "rust1", since = "1.0.0")]
@@ -142,6 +144,7 @@ impl<W: Write> BufWriter<W> {
142144
/// use std::io::BufWriter;
143145
/// use std::net::TcpStream;
144146
///
147+
/// # #[expect(unused_mut)]
145148
/// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
146149
///
147150
/// // unwrap the TcpStream and flush the buffer
@@ -295,6 +298,7 @@ impl<W: ?Sized + Write> BufWriter<W> {
295298
/// use std::io::BufWriter;
296299
/// use std::net::TcpStream;
297300
///
301+
/// # #[expect(unused_mut)]
298302
/// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
299303
///
300304
/// // we can use reference just like buffer

library/alloc/src/io/buffered/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::io::Error;
2929
/// use std::io::BufWriter;
3030
/// use std::net::TcpStream;
3131
///
32+
/// # #[expect(unused_mut)]
3233
/// let mut stream = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
3334
///
3435
/// // do stuff with the stream
@@ -71,6 +72,7 @@ impl<W> IntoInnerError<W> {
7172
/// use std::io::BufWriter;
7273
/// use std::net::TcpStream;
7374
///
75+
/// # #[expect(unused_mut)]
7476
/// let mut stream = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
7577
///
7678
/// // do stuff with the stream
@@ -105,6 +107,7 @@ impl<W> IntoInnerError<W> {
105107
/// use std::io::BufWriter;
106108
/// use std::net::TcpStream;
107109
///
110+
/// # #[expect(unused_mut)]
108111
/// let mut stream = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
109112
///
110113
/// // do stuff with the stream

library/alloc/src/io/read.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ pub trait Read {
248248
/// situations gracefully.
249249
///
250250
/// ```no_run
251+
/// # #![expect(dead_code)]
251252
/// # use std::io::{self, BufRead};
252253
/// # struct Example { example_datasource: io::Empty } impl Example {
253254
/// # fn get_some_data_for_the_example(&self) -> &'static [u8] { &[] }
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
use crate::io::prelude::*;
2-
use crate::io::{
3-
self, BorrowedBuf, BufReader, BufWriter, ErrorKind, IoSlice, LineWriter, SeekFrom,
1+
//! Tests for buffering wrappers for I/O traits
2+
3+
use alloc::io::{
4+
self, BorrowedBuf, BufRead, BufReader, BufWriter, ErrorKind, IoSlice, LineWriter, Read, Seek,
5+
SeekFrom, Write,
46
};
5-
use crate::mem::MaybeUninit;
6-
use crate::sync::atomic::{AtomicUsize, Ordering};
7-
use crate::{panic, thread};
7+
use core::mem::MaybeUninit;
8+
use core::sync::atomic::{AtomicUsize, Ordering};
9+
use std::{panic, thread};
10+
11+
extern crate test;
812

913
/// A dummy reader intended at testing short-reads propagation.
1014
pub struct ShortReader {
@@ -681,7 +685,7 @@ fn line_vectored() {
681685

682686
#[test]
683687
fn line_vectored_partial_and_errors() {
684-
use crate::collections::VecDeque;
688+
use alloc::collections::VecDeque;
685689

686690
enum Call {
687691
Write { inputs: Vec<&'static [u8]>, output: io::Result<usize> },
@@ -1023,7 +1027,7 @@ struct WriteRecorder {
10231027

10241028
impl Write for WriteRecorder {
10251029
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
1026-
use crate::str::from_utf8;
1030+
use core::str::from_utf8;
10271031

10281032
self.events.push(RecordedEvent::Write(from_utf8(buf).unwrap().to_string()));
10291033
Ok(buf.len())
@@ -1056,7 +1060,7 @@ fn single_formatted_write() {
10561060
fn bufreader_full_initialize() {
10571061
struct OneByteReader;
10581062
impl Read for OneByteReader {
1059-
fn read(&mut self, buf: &mut [u8]) -> crate::io::Result<usize> {
1063+
fn read(&mut self, buf: &mut [u8]) -> alloc::io::Result<usize> {
10601064
if buf.len() > 0 {
10611065
buf[0] = 0;
10621066
Ok(1)
@@ -1079,7 +1083,7 @@ fn bufreader_full_initialize() {
10791083
/// This is a regression test for https://github.com/rust-lang/rust/issues/127584.
10801084
#[test]
10811085
fn bufwriter_aliasing() {
1082-
use crate::io::{BufWriter, Cursor};
1086+
use alloc::io::{BufWriter, Cursor};
10831087
let mut v = vec![0; 1024];
10841088
let c = Cursor::new(&mut v);
10851089
let w = BufWriter::new(Box::new(c));
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use crate::io::prelude::*;
2-
use crate::io::{Cursor, IoSlice, IoSliceMut, SeekFrom};
1+
use alloc::io::{Cursor, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
2+
3+
extern crate test;
34

45
#[test]
56
fn test_vec_writer() {
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
use super::{BorrowedBuf, Cursor, SeekFrom, repeat};
2-
use crate::cmp::{self, min};
3-
use crate::io::{self, BufRead, BufReader, DEFAULT_BUF_SIZE, IoSlice, Read, Seek, Write};
4-
use crate::mem::MaybeUninit;
1+
mod buffered;
2+
mod cursor;
3+
mod util;
4+
5+
use alloc::io::{
6+
self, BorrowedBuf, BufRead, BufReader, Cursor, DEFAULT_BUF_SIZE, IoSlice, Read, Seek, SeekFrom,
7+
Write, repeat,
8+
};
9+
use core::cmp::{self, min};
10+
use core::mem::MaybeUninit;
11+
12+
extern crate test;
513

614
#[test]
715
fn read_until() {
@@ -270,7 +278,7 @@ fn chain_bufread() {
270278
#[test]
271279
fn chain_splitted_char() {
272280
let chain = b"\xc3".chain(b"\xa9".as_slice());
273-
assert_eq!(crate::io::read_to_string(chain).unwrap(), "é");
281+
assert_eq!(alloc::io::read_to_string(chain).unwrap(), "é");
274282

275283
let mut chain = b"\xc3".chain(b"\xa9\n".as_slice());
276284
let mut buf = String::new();
@@ -360,7 +368,7 @@ fn bench_read_to_end(b: &mut test::Bencher) {
360368
b.iter(|| {
361369
let mut lr = repeat(1).take(10000000);
362370
let mut vec = Vec::with_capacity(1024);
363-
super::default_read_to_end(&mut lr, &mut vec, None)
371+
alloc::io::default_read_to_end(&mut lr, &mut vec, None)
364372
});
365373
}
366374

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::fmt;
2-
use crate::io::prelude::*;
3-
use crate::io::{
4-
BorrowedBuf, Empty, ErrorKind, IoSlice, IoSliceMut, Repeat, SeekFrom, Sink, empty, repeat, sink,
1+
use alloc::io::{
2+
BorrowedBuf, Empty, ErrorKind, IoSlice, IoSliceMut, Read, Repeat, Seek, SeekFrom, Sink, Write,
3+
empty, repeat, sink,
54
};
6-
use crate::mem::MaybeUninit;
5+
use core::fmt;
6+
use core::mem::MaybeUninit;
77

88
struct ErrorDisplay;
99

library/alloctests/tests/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@
4141
#![feature(macro_metavar_expr_concat)]
4242
#![feature(vec_peek_mut)]
4343
#![feature(vec_try_remove)]
44+
#![feature(alloc_io)]
45+
#![feature(borrowed_buf_init)]
46+
#![feature(buf_read_has_data_left)]
47+
#![feature(can_vector)]
48+
#![feature(core_io_borrowed_buf)]
49+
#![feature(core_io_internals)]
50+
#![feature(cursor_split)]
51+
#![feature(io_const_error)]
52+
#![feature(read_buf)]
53+
#![feature(seek_io_take_position)]
54+
#![feature(seek_stream_len)]
55+
#![feature(write_all_vectored)]
4456
#![allow(internal_features)]
4557
#![deny(fuzzy_provenance_casts)]
4658
#![deny(unsafe_op_in_unsafe_fn)]
@@ -62,6 +74,7 @@ mod const_fns;
6274
mod cow_str;
6375
mod fmt;
6476
mod heap;
77+
mod io;
6578
mod linked_list;
6679
mod misc_tests;
6780
mod num;

0 commit comments

Comments
 (0)