test_DirPath.pf Source File


This file depends on

sourcefile~~test_dirpath.pf~~EfferentGraph sourcefile~test_dirpath.pf test_DirPath.pf sourcefile~constants.f90 Constants.F90 sourcefile~test_dirpath.pf->sourcefile~constants.f90 sourcefile~mapl_dirpath.f90 MAPL_DirPath.F90 sourcefile~test_dirpath.pf->sourcefile~mapl_dirpath.f90 sourcefile~internalconstants.f90 InternalConstants.F90 sourcefile~constants.f90->sourcefile~internalconstants.f90 sourcefile~mathconstants.f90 MathConstants.F90 sourcefile~constants.f90->sourcefile~mathconstants.f90 sourcefile~physicalconstants.f90 PhysicalConstants.F90 sourcefile~constants.f90->sourcefile~physicalconstants.f90 sourcefile~mapl_dirpath.f90->sourcefile~constants.f90 sourcefile~mapl_keywordenforcer.f90 MAPL_KeywordEnforcer.F90 sourcefile~mapl_dirpath.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~physicalconstants.f90->sourcefile~mathconstants.f90

Source Code

module test_DirPath
   use pfunit
   use MAPL_DirPathMod
   use MAPL_Constants

contains

   @before
   subroutine setup()
      integer :: unit

      call execute_command_line('mkdir dir1 dir2')
      call execute_command_line('mkdir dir1/dir3')
      open(newunit=unit,file='dir1/exist.dat',status='new')
      close(unit)
      open(newunit=unit,file='dir1/dir3/exist3.dat',status='new')
      close(unit)
      open(newunit=unit,file='dir2/exist2.dat',status='new')
      close(unit)

   end subroutine setup
  

   @after
   subroutine tearDown()
      integer :: unit

      open(newunit=unit,file='dir1/exist.dat',status='old')
      close(unit, status='delete')
      open(newunit=unit,file='dir1/dir3/exist3.dat',status='old')
      close(unit, status='delete')
      open(newunit=unit,file='dir2/exist2.dat',status='old')
      close(unit, status='delete')

      call execute_command_line('rmdir dir1/dir3')
      call execute_command_line('rmdir dir1 dir2')
      
   end subroutine tearDown
      

   @test
   subroutine test_empty()
      type (DirPath) :: path
      character(len=:), allocatable :: full_name
      integer :: status

      full_name = path%find('does_not_exist.dat', rc=status)
      @assertEqual(MAPL_FILE_NOT_FOUND, status)
      
   end subroutine test_empty

   @test
   subroutine test_simple()
      type (DirPath) :: path
      character(len=:), allocatable :: full_name
      integer :: status

      call path%append('dir1')
      full_name = path%find('exist.dat', rc=status)
      @assertEqual(0, status)
      @assertEqual('dir1/exist.dat', full_name)

   end subroutine test_simple


   @test
   subroutine test_complex()
      type (DirPath) :: path
      character(len=:), allocatable :: full_name
      integer :: status

      call path%append('dir1')
      call path%append('dir1/dir3')
      call path%append('dir2')

      full_name = path%find('exist.dat', rc=status)
      @assertEqual(0, status)
      @assertEqual('dir1/exist.dat', full_name)

      full_name = path%find('exist2.dat', rc=status)
      @assertEqual(0, status)
      @assertEqual('dir2/exist2.dat', full_name)

      full_name = path%find('exist3.dat', rc=status)
      @assertEqual(0, status)
      @assertEqual('dir1/dir3/exist3.dat', full_name)


   end subroutine test_complex



end module test_DirPath