1
1
module test_zip
2
+ use stdlib_filesystem, only: exists
2
3
use stdlib_io_zip
3
- use stdlib_string_type, only : string_type, char
4
- use testdrive, only : new_unittest, unittest_type, error_type, check, test_failed
4
+ use stdlib_string_type, only: string_type, char
5
+ use testdrive, only: new_unittest, unittest_type, error_type, check, test_failed
5
6
implicit none
6
7
private
7
8
@@ -28,7 +29,8 @@ subroutine collect_zip(testsuite)
28
29
new_unittest(" zip_invalid_file" , zip_invalid_file, should_fail= .true. ), &
29
30
new_unittest(" zip_empty_file" , zip_empty_file), &
30
31
new_unittest(" zip_invalid_output_file" , zip_invalid_output_file, should_fail= .true. ), &
31
- new_unittest(" zip_two_files" , zip_two_files) &
32
+ new_unittest(" zip_two_files" , zip_two_files), &
33
+ new_unittest(" zip_without_comp" , zip_without_comp) &
32
34
]
33
35
end
34
36
@@ -199,6 +201,13 @@ subroutine zip_empty_file(error)
199
201
200
202
call zip(output_file, files, stat)
201
203
call check(error, stat, " Compressing a valid empty file should not fail." )
204
+ if (allocated (error)) then
205
+ call delete_file(input_file)
206
+ call delete_file(output_file)
207
+ return
208
+ end if
209
+
210
+ call check(error, exists(output_file), " The output file should exist." )
202
211
203
212
call delete_file(input_file)
204
213
call delete_file(output_file)
@@ -241,12 +250,48 @@ subroutine zip_two_files(error)
241
250
242
251
call zip(output_file, files, stat)
243
252
call check(error, stat, " Compressing two valid files should not fail." )
253
+ if (allocated (error)) then
254
+ call delete_file(input_file_1)
255
+ call delete_file(input_file_2)
256
+ call delete_file(output_file)
257
+ return
258
+ end if
259
+
260
+ call check(error, exists(output_file), " The output file should exist." )
244
261
245
262
call delete_file(input_file_1)
246
263
call delete_file(input_file_2)
247
264
call delete_file(output_file)
248
265
end
249
266
267
+
268
+ subroutine zip_without_comp (error )
269
+ type (error_type), allocatable , intent (out ) :: error
270
+
271
+ integer :: stat, unit
272
+ character (* ), parameter :: output_file = " temp.zip"
273
+ character (* ), parameter :: input_file = " abc.txt"
274
+ type (string_type), allocatable :: files(:)
275
+
276
+ files = [string_type(input_file)]
277
+
278
+ open (newunit= unit, file= input_file)
279
+ close (unit)
280
+
281
+ call zip(output_file, files, stat, compressed= .false. )
282
+ call check(error, stat, " Zipping a valid file without compression shouldn't fail." )
283
+ if (allocated (error)) then
284
+ call delete_file(input_file)
285
+ call delete_file(output_file)
286
+ return
287
+ end if
288
+
289
+ call check(error, exists(output_file), " The output file should exist." )
290
+
291
+ call delete_file(input_file)
292
+ call delete_file(output_file)
293
+ end
294
+
250
295
! > Makes sure that we find the file when running both `ctest` and `fpm test`.
251
296
function get_path (file ) result(path)
252
297
character (* ), intent (in ) :: file
0 commit comments