@@ -15,6 +15,7 @@ use super::SeekStyle;
15
15
use rt:: rtio:: { RtioFileDescriptor , IoFactory , IoFactoryObject } ;
16
16
use rt:: io:: { io_error, read_error, EndOfFile } ;
17
17
use rt:: local:: Local ;
18
+ use rt:: test:: * ;
18
19
use libc:: { O_RDWR , O_RDONLY , O_WRONLY , S_IWUSR , S_IRUSR ,
19
20
O_CREAT , O_TRUNC , O_APPEND } ;
20
21
@@ -84,6 +85,18 @@ impl FileStream {
84
85
}
85
86
}
86
87
}
88
+ fn unlink < P : PathLike > ( path : & P ) {
89
+ let unlink_result = unsafe {
90
+ let io = Local :: unsafe_borrow :: < IoFactoryObject > ( ) ;
91
+ ( * io) . fs_unlink ( path)
92
+ } ;
93
+ match unlink_result {
94
+ Ok ( _) => ( ) ,
95
+ Err ( ioerr) => {
96
+ io_error:: cond. raise ( ioerr) ;
97
+ }
98
+ }
99
+ }
87
100
}
88
101
89
102
impl Reader for FileStream {
@@ -131,10 +144,9 @@ impl Seek for FileStream {
131
144
}
132
145
133
146
fn file_test_smoke_test_impl ( ) {
134
- use rt:: test:: * ;
135
147
do run_in_newsched_task {
136
148
let message = "it's alright. have a good time" ;
137
- let filename = & Path ( "rt_io_file_test.txt" ) ;
149
+ let filename = & Path ( "./ rt_io_file_test.txt" ) ;
138
150
{
139
151
let mut write_stream = FileStream :: open ( filename, Create , ReadWrite ) . unwrap ( ) ;
140
152
write_stream. write ( message. as_bytes ( ) ) ;
@@ -149,10 +161,48 @@ fn file_test_smoke_test_impl() {
149
161
} ;
150
162
assert ! ( read_str == message. to_owned( ) ) ;
151
163
}
164
+ FileStream :: unlink ( filename) ;
152
165
}
153
166
}
154
167
155
168
#[ test]
156
169
fn file_test_smoke_test ( ) {
157
170
file_test_smoke_test_impl ( ) ;
158
171
}
172
+
173
+ fn file_test_invalid_path_opened_without_create_should_raise_condition_impl ( ) {
174
+ do run_in_newsched_task {
175
+ let filename = & Path ( "./file_that_does_not_exist.txt" ) ;
176
+ let mut called = false ;
177
+ do io_error:: cond. trap ( |_| {
178
+ called = true ;
179
+ } ) . inside {
180
+ let result = FileStream :: open ( filename, Open , Read ) ;
181
+ assert ! ( result. is_none( ) ) ;
182
+ }
183
+ assert ! ( called) ;
184
+ }
185
+ }
186
+ #[ test]
187
+ fn file_test_invalid_path_opened_without_create_should_raise_condition ( ) {
188
+ file_test_invalid_path_opened_without_create_should_raise_condition_impl ( ) ;
189
+ }
190
+
191
+ fn file_test_unlinking_invalid_path_should_raise_condition_impl ( ) {
192
+ use io;
193
+ do run_in_newsched_task {
194
+ let filename = & Path ( "./another_file_that_does_not_exist.txt" ) ;
195
+ let mut called = false ;
196
+ do io_error:: cond. trap ( |e| {
197
+ io:: println ( fmt ! ( "condition kind: %?" , e. kind) ) ;
198
+ called = true ;
199
+ } ) . inside {
200
+ FileStream :: unlink ( filename) ;
201
+ }
202
+ assert ! ( called) ;
203
+ }
204
+ }
205
+ #[ test]
206
+ fn file_test_unlinking_invalid_path_should_raise_condition ( ) {
207
+ file_test_unlinking_invalid_path_should_raise_condition_impl ( ) ;
208
+ }
0 commit comments