|
| 1 | +use async_dup::{Arc, Mutex}; |
1 | 2 | use async_std::fs::File; |
2 | 3 | use async_std::io::{self, Read, SeekFrom, Write}; |
3 | 4 | use async_std::path::PathBuf; |
4 | | -use async_std::sync::Arc; |
| 5 | +use async_std::prelude::*; |
5 | 6 | use async_std::task::{Context, Poll}; |
6 | 7 | use std::pin::Pin; |
7 | | -use std::sync::Mutex; |
8 | 8 |
|
9 | 9 | #[derive(Debug, Copy, Clone)] |
10 | 10 | #[allow(dead_code)] |
@@ -72,30 +72,25 @@ impl TestCase { |
72 | 72 | } |
73 | 73 |
|
74 | 74 | #[allow(dead_code)] |
75 | | - pub async fn read_result(&self) -> String { |
76 | | - use async_std::prelude::*; |
| 75 | + pub async fn read_result(&mut self) -> String { |
77 | 76 | let mut result = String::new(); |
78 | | - let mut file = self.result.lock().unwrap(); |
79 | | - file.seek(SeekFrom::Start(0)).await.unwrap(); |
80 | | - file.read_to_string(&mut result).await.unwrap(); |
| 77 | + self.result.seek(SeekFrom::Start(0)).await.unwrap(); |
| 78 | + self.result.read_to_string(&mut result).await.unwrap(); |
81 | 79 | result |
82 | 80 | } |
83 | 81 |
|
84 | 82 | #[allow(dead_code)] |
85 | | - pub async fn read_expected(&self) -> String { |
86 | | - use async_std::prelude::*; |
| 83 | + pub async fn read_expected(&mut self) -> String { |
87 | 84 | let mut expected = std::string::String::new(); |
88 | 85 | self.expected_fixture |
89 | | - .lock() |
90 | | - .unwrap() |
91 | 86 | .read_to_string(&mut expected) |
92 | 87 | .await |
93 | 88 | .unwrap(); |
94 | 89 | expected |
95 | 90 | } |
96 | 91 |
|
97 | 92 | #[allow(dead_code)] |
98 | | - pub(crate) async fn assert(self) { |
| 93 | + pub(crate) async fn assert(mut self) { |
99 | 94 | let mut actual = self.read_result().await; |
100 | 95 | let mut expected = self.read_expected().await; |
101 | 96 | assert!(!actual.is_empty(), "Received empty reply"); |
@@ -138,14 +133,14 @@ impl Read for TestCase { |
138 | 133 |
|
139 | 134 | impl Write for TestCase { |
140 | 135 | fn poll_write(self: Pin<&mut Self>, cx: &mut Context, buf: &[u8]) -> Poll<io::Result<usize>> { |
141 | | - Pin::new(&mut &*self.result.lock().unwrap()).poll_write(cx, buf) |
| 136 | + Pin::new(&mut &*self.result).poll_write(cx, buf) |
142 | 137 | } |
143 | 138 |
|
144 | 139 | fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<io::Result<()>> { |
145 | | - Pin::new(&mut &*self.result.lock().unwrap()).poll_flush(cx) |
| 140 | + Pin::new(&mut &*self.result).poll_flush(cx) |
146 | 141 | } |
147 | 142 |
|
148 | 143 | fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<io::Result<()>> { |
149 | | - Pin::new(&mut &*self.result.lock().unwrap()).poll_close(cx) |
| 144 | + Pin::new(&mut &*self.result).poll_close(cx) |
150 | 145 | } |
151 | 146 | } |
0 commit comments