1
1
module test_zip
2
2
use stdlib_io_zip
3
+ use stdlib_string_type, only : string_type, char
3
4
use testdrive, only : new_unittest, unittest_type, error_type, check, test_failed
4
5
implicit none
5
6
private
@@ -22,7 +23,12 @@ subroutine collect_zip(testsuite)
22
23
new_unittest(" unzip_zip_has_txt_file" , unzip_zip_has_txt_file), &
23
24
new_unittest(" unzip_npz_array_empty_0_file" , unzip_npz_array_empty_0_file), &
24
25
new_unittest(" unzip_two_files" , unzip_two_files), &
25
- new_unittest(" unzip_compressed_npz" , unzip_compressed_npz) &
26
+ new_unittest(" unzip_compressed_npz" , unzip_compressed_npz), &
27
+ new_unittest(" zip_nonexistent_file" , zip_nonexistent_file, should_fail= .true. ), &
28
+ new_unittest(" zip_invalid_file" , zip_invalid_file, should_fail= .true. ), &
29
+ new_unittest(" zip_empty_file" , zip_empty_file), &
30
+ new_unittest(" zip_invalid_output_file" , zip_invalid_output_file, should_fail= .true. ), &
31
+ new_unittest(" zip_two_files" , zip_two_files) &
26
32
]
27
33
end
28
34
@@ -150,6 +156,97 @@ subroutine unzip_compressed_npz(error)
150
156
call check(error, stat, " Listing the contents of a compressed npz file should not fail." )
151
157
end
152
158
159
+ subroutine zip_nonexistent_file (error )
160
+ type (error_type), allocatable , intent (out ) :: error
161
+
162
+ integer :: stat
163
+ character (* ), parameter :: output_file = " temp.zip"
164
+ character (* ), parameter :: input_file = " nonexistent"
165
+ type (string_type), allocatable :: files(:)
166
+
167
+ files = [string_type(input_file)]
168
+
169
+ call zip(output_file, files, stat)
170
+ call check(error, stat, " Compressing a non-existent file should fail." )
171
+ end
172
+
173
+ subroutine zip_invalid_file (error )
174
+ type (error_type), allocatable , intent (out ) :: error
175
+
176
+ integer :: stat
177
+ character (* ), parameter :: output_file = " temp.zip"
178
+ character (* ), parameter :: input_file = " ."
179
+ type (string_type), allocatable :: files(:)
180
+
181
+ files = [string_type(input_file)]
182
+
183
+ call zip(output_file, files, stat)
184
+ call check(error, stat, " Compressing an invalid file should fail." )
185
+ end
186
+
187
+ subroutine zip_empty_file (error )
188
+ type (error_type), allocatable , intent (out ) :: error
189
+
190
+ integer :: stat, unit
191
+ character (* ), parameter :: output_file = " temp.zip"
192
+ character (* ), parameter :: input_file = " abc.txt"
193
+ type (string_type), allocatable :: files(:)
194
+
195
+ files = [string_type(input_file)]
196
+
197
+ open (newunit= unit, file= input_file)
198
+ close (unit)
199
+
200
+ call zip(output_file, files, stat)
201
+ call check(error, stat, " Compressing a valid empty file should not fail." )
202
+
203
+ call delete_file(input_file)
204
+ call delete_file(output_file)
205
+ end
206
+
207
+ subroutine zip_invalid_output_file (error )
208
+ type (error_type), allocatable , intent (out ) :: error
209
+
210
+ integer :: stat, unit
211
+ character (* ), parameter :: output_file = " "
212
+ character (* ), parameter :: input_file = " abc.txt"
213
+ type (string_type), allocatable :: files(:)
214
+
215
+ files = [string_type(input_file)]
216
+
217
+ open (newunit= unit, file= input_file)
218
+ close (unit)
219
+
220
+ call zip(output_file, files, stat)
221
+ call check(error, stat, " Providing an empty output file should fail." )
222
+
223
+ call delete_file(input_file)
224
+ end
225
+
226
+ subroutine zip_two_files (error )
227
+ type (error_type), allocatable , intent (out ) :: error
228
+
229
+ integer :: stat, unit
230
+ character (* ), parameter :: output_file = " temp.zip"
231
+ character (* ), parameter :: input_file_1 = " abc.txt"
232
+ character (* ), parameter :: input_file_2 = " def.txt"
233
+ type (string_type), allocatable :: files(:)
234
+
235
+ files = [string_type(input_file_1), string_type(input_file_2)]
236
+
237
+ open (newunit= unit, file= input_file_1)
238
+ close (unit)
239
+ open (newunit= unit, file= input_file_2)
240
+ close (unit)
241
+
242
+ call zip(output_file, files, stat)
243
+ call check(error, stat, " Compressing two valid files should not fail." )
244
+
245
+ call delete_file(input_file_1)
246
+ call delete_file(input_file_2)
247
+ call delete_file(output_file)
248
+ end
249
+
153
250
! > Makes sure that we find the file when running both `ctest` and `fpm test`.
154
251
function get_path (file ) result(path)
155
252
character (* ), intent (in ) :: file
0 commit comments