Skip to content

Commit 27b9ece

Browse files
committed
Add test that includes one dir
1 parent d760b5f commit 27b9ece

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

test/io/test_filesystem.f90

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ subroutine collect_filesystem(testsuite)
2525
new_unittest("fs_run_valid_command", fs_run_valid_command), &
2626
new_unittest("fs_list_dir_empty", fs_list_dir_empty), &
2727
new_unittest("fs_list_dir_one_file", fs_list_dir_one_file), &
28-
new_unittest("fs_list_dir_two_files", fs_list_dir_two_files) &
28+
new_unittest("fs_list_dir_two_files", fs_list_dir_two_files), &
29+
new_unittest("fs_list_dir_one_file_one_dir", fs_list_dir_one_file_one_dir) &
2930
]
3031
end
3132

@@ -181,6 +182,44 @@ subroutine fs_list_dir_two_files(error)
181182
call run('rm -rf '//temp_list_dir, iostat=stat)
182183
end
183184

185+
subroutine fs_list_dir_one_file_one_dir(error)
186+
type(error_type), allocatable, intent(out) :: error
187+
188+
integer :: stat
189+
190+
type(string_type), allocatable :: contents(:)
191+
character(*), parameter :: filename1 = 'abc.txt'
192+
character(*), parameter :: dir = 'xyz'
193+
194+
call run('rm -rf '//temp_list_dir, iostat=stat)
195+
if (stat /= 0) then
196+
call test_failed(error, "Removing directory '"//temp_list_dir//"' failed."); return
197+
end if
198+
199+
call run('mkdir '//temp_list_dir, iostat=stat)
200+
if (stat /= 0) then
201+
call test_failed(error, "Creating directory '"//temp_list_dir//"' failed."); return
202+
end if
203+
204+
call run('touch '//temp_list_dir//'/'//filename1, iostat=stat)
205+
if (stat /= 0) then
206+
call test_failed(error, "Creating file 1 in directory '"//temp_list_dir//"' failed."); return
207+
end if
208+
209+
call run('mkdir '//temp_list_dir//'/'//dir, iostat=stat)
210+
if (stat /= 0) then
211+
call test_failed(error, "Creating dir in directory '"//temp_list_dir//"' failed."); return
212+
end if
213+
214+
call list_dir(temp_list_dir, contents, stat)
215+
call check(error, stat, "Listing the contents of an empty directory shouldn't fail.")
216+
call check(error, size(contents) == 2, "The directory should contain two files.")
217+
call check(error, char(contents(1)) == filename1, "The file should be '"//filename1//"'.")
218+
call check(error, char(contents(2)) == dir, "The file should be '"//dir//"'.")
219+
220+
call run('rm -rf '//temp_list_dir, iostat=stat)
221+
end
222+
184223
subroutine delete_file(filename)
185224
character(len=*), intent(in) :: filename
186225

0 commit comments

Comments
 (0)