@@ -2,7 +2,8 @@ module test_filesystem
2
2
use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
3
3
use stdlib_system, only: is_directory, delete_file, FS_ERROR, FS_ERROR_CODE, &
4
4
make_directory, remove_directory, make_directory_all, is_windows, OS_TYPE, &
5
- OS_WINDOWS, exists, fs_type_unknown, fs_type_regular_file, fs_type_directory, fs_type_symlink
5
+ OS_WINDOWS, exists, fs_type_unknown, fs_type_regular_file, fs_type_directory, fs_type_symlink, &
6
+ is_regular_file
6
7
use stdlib_error, only: state_type, STDLIB_FS_ERROR
7
8
use stdlib_strings, only: to_string
8
9
@@ -21,6 +22,7 @@ subroutine collect_suite(testsuite)
21
22
new_unittest(" fs_exists_reg_file" , test_exists_reg_file), &
22
23
new_unittest(" fs_exists_dir" , test_exists_dir), &
23
24
new_unittest(" fs_exists_symlink" , test_exists_symlink), &
25
+ new_unittest(" fs_is_regular_file" , test_is_regular_file), &
24
26
new_unittest(" fs_is_directory_dir" , test_is_directory_dir), &
25
27
new_unittest(" fs_is_directory_file" , test_is_directory_file), &
26
28
new_unittest(" fs_delete_non_existent" , test_delete_file_non_existent), &
@@ -85,7 +87,7 @@ subroutine test_exists_reg_file(error)
85
87
if (allocated (error)) then
86
88
! Clean up: remove the file
87
89
close (iunit,status= ' delete' ,iostat= ios,iomsg= msg)
88
- call check(error, ios == 0 , err % message// " and cannot delete test file: " // trim (msg))
90
+ call check(error, ios == 0 , error % message// " and cannot delete test file: " // trim (msg))
89
91
return
90
92
end if
91
93
@@ -95,7 +97,7 @@ subroutine test_exists_reg_file(error)
95
97
if (allocated (error)) then
96
98
! Clean up: remove the file
97
99
close (iunit,status= ' delete' ,iostat= ios,iomsg= msg)
98
- call check(error, ios == 0 , err % message// " and cannot delete test file: " // trim (msg))
100
+ call check(error, ios == 0 , error % message// " and cannot delete test file: " // trim (msg))
99
101
return
100
102
end if
101
103
@@ -105,6 +107,37 @@ subroutine test_exists_reg_file(error)
105
107
if (allocated (error)) return
106
108
end subroutine test_exists_reg_file
107
109
110
+ subroutine test_is_regular_file (error )
111
+ type (error_type), allocatable , intent (out ) :: error
112
+ character (len= 256 ) :: filename
113
+ integer :: ios, iunit
114
+ character (len= 512 ) :: msg
115
+
116
+ logical :: is_file
117
+
118
+ filename = " test_file.txt"
119
+
120
+ ! Create a file
121
+ open (newunit= iunit, file= filename, status= " replace" , iostat= ios, iomsg= msg)
122
+ call check(error, ios == 0 , " Cannot init test_is_regular_file: " // trim (msg))
123
+ if (allocated (error)) return
124
+
125
+ is_file = is_regular_file(filename)
126
+ call check(error, is_file, " is_regular_file could not identify a file" )
127
+
128
+ if (allocated (error)) then
129
+ ! Clean up: remove the file
130
+ close (iunit,status= ' delete' ,iostat= ios,iomsg= msg)
131
+ call check(error, ios == 0 , error% message// " and cannot delete test file: " // trim (msg))
132
+ return
133
+ end if
134
+
135
+ ! Clean up: remove the file
136
+ close (iunit,status= ' delete' ,iostat= ios,iomsg= msg)
137
+ call check(error, ios == 0 , " Cannot delete test file: " // trim (msg))
138
+ if (allocated (error)) return
139
+ end subroutine test_is_regular_file
140
+
108
141
subroutine test_exists_dir (error )
109
142
type (error_type), allocatable , intent (out ) :: error
110
143
type (state_type) :: err
@@ -125,7 +158,7 @@ subroutine test_exists_dir(error)
125
158
if (allocated (error)) then
126
159
! Clean up: remove the directory
127
160
call execute_command_line(" rmdir " // dirname, exitstat= ios, cmdstat= iocmd, cmdmsg= msg)
128
- call check(error, ios == 0 .and. iocmd == 0 , err % message // " and &
161
+ call check(error, ios == 0 .and. iocmd == 0 , error % message // " and &
129
162
& cannot cleanup test_exists_dir: " // trim (msg))
130
163
return
131
164
end if
@@ -136,7 +169,7 @@ subroutine test_exists_dir(error)
136
169
if (allocated (error)) then
137
170
! Clean up: remove the directory
138
171
call execute_command_line(" rmdir " // dirname, exitstat= ios, cmdstat= iocmd, cmdmsg= msg)
139
- call check(error, ios == 0 .and. iocmd == 0 , err % message // " and &
172
+ call check(error, ios == 0 .and. iocmd == 0 , error % message // " and &
140
173
& cannot cleanup test_exists_dir: " // trim (msg))
141
174
return
142
175
end if
@@ -174,7 +207,7 @@ subroutine test_exists_symlink(error)
174
207
if (allocated (error)) then
175
208
! Clean up: remove the target
176
209
close (iunit,status= ' delete' ,iostat= ios,iomsg= msg)
177
- call check(error, ios == 0 , err % message // " and cannot delete target: " // trim (msg))
210
+ call check(error, ios == 0 , error % message // " and cannot delete target: " // trim (msg))
178
211
return
179
212
end if
180
213
@@ -184,12 +217,12 @@ subroutine test_exists_symlink(error)
184
217
if (allocated (error)) then
185
218
! Clean up: remove the link
186
219
call execute_command_line(" rm " // link_name, exitstat= ios, cmdstat= iocmd, cmdmsg= msg)
187
- call check(error, ios == 0 .and. iocmd == 0 , err % message // " and &
220
+ call check(error, ios == 0 .and. iocmd == 0 , error % message // " and &
188
221
& cannot delete link: " // trim (msg))
189
222
190
223
! Clean up: remove the target
191
224
close (iunit,status= ' delete' ,iostat= ios,iomsg= msg)
192
- call check(error, ios == 0 , err % message // " and cannot delete target: " // trim (msg))
225
+ call check(error, ios == 0 , error % message // " and cannot delete target: " // trim (msg))
193
226
return
194
227
end if
195
228
@@ -199,12 +232,12 @@ subroutine test_exists_symlink(error)
199
232
if (allocated (error)) then
200
233
! Clean up: remove the link
201
234
call execute_command_line(" rm " // link_name, exitstat= ios, cmdstat= iocmd, cmdmsg= msg)
202
- call check(error, ios == 0 .and. iocmd == 0 , err % message // " and &
235
+ call check(error, ios == 0 .and. iocmd == 0 , error % message // " and &
203
236
& cannot delete link: " // trim (msg))
204
237
205
238
! Clean up: remove the target
206
239
close (iunit,status= ' delete' ,iostat= ios,iomsg= msg)
207
- call check(error, ios == 0 , err % message // " and cannot delete target: " // trim (msg))
240
+ call check(error, ios == 0 , error % message // " and cannot delete target: " // trim (msg))
208
241
return
209
242
end if
210
243
@@ -215,7 +248,7 @@ subroutine test_exists_symlink(error)
215
248
if (allocated (error)) then
216
249
! Clean up: remove the target
217
250
close (iunit,status= ' delete' ,iostat= ios,iomsg= msg)
218
- call check(error, ios == 0 , err % message // " and cannot delete target: " // trim (msg))
251
+ call check(error, ios == 0 , error % message // " and cannot delete target: " // trim (msg))
219
252
end if
220
253
221
254
! Clean up: remove the target
0 commit comments