Skip to content

Commit c88cabc

Browse files
Fix the new_test
- use function to find the executable
1 parent 2687745 commit c88cabc

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

fpm/test/new_test/new_test.f90

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
program new_test
22
use,intrinsic :: iso_fortran_env, only : stdin=>input_unit, stdout=>output_unit, stderr=>error_unit
3-
use fpm_filesystem, only : is_dir, list_files, exists, windows_path
3+
use fpm_filesystem, only : is_dir, list_files, exists, windows_path, join_path
44
use fpm_strings, only : string_t, operator(.in.)
5-
use fpm_environment, only : run, get_os_type
5+
use fpm_environment, only : run, get_os_type
66
use fpm_environment, only : OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_WINDOWS
77
implicit none
88
type(string_t), allocatable :: file_names(:)
99
integer :: i, j, k
10-
character(len=*),parameter :: cmdpath = 'build/gfortran_debug/app/fpm'
10+
character(len=:),allocatable :: cmdpath
1111
character(len=:),allocatable :: path
1212
character(len=*),parameter :: scr = 'fpm_scratch_'
1313
character(len=*),parameter :: cmds(*) = [character(len=80) :: &
@@ -35,6 +35,8 @@ program new_test
3535
logical,allocatable :: tally(:)
3636
logical :: IS_OS_WINDOWS
3737
write(*,'(g0:,1x)')'TEST new SUBCOMMAND (draft):'
38+
39+
cmdpath = get_command_path()
3840
allocate(tally(0))
3941
shortdirs=[character(len=80) :: 'A','B','C','D','E','F','G','BB','CC']
4042
allocate(character(len=80) :: directories(size(shortdirs)))
@@ -44,18 +46,18 @@ program new_test
4446
!! o assuming fpm command is in expected path and the new version
4547
!! o DOS versus POSIX filenames
4648
is_os_windows=.false.
47-
select case (get_os_type())
49+
select case (get_os_type())
4850
case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD)
4951
call execute_command_line('rm -rf fpm_scratch_*',exitstat=estat,cmdstat=cstat,cmdmsg=message)
5052
path=cmdpath
51-
case (OS_WINDOWS)
53+
case (OS_WINDOWS)
5254
path=windows_path(cmdpath)
5355
is_os_windows=.true.
5456
call execute_command_line('rmdir fpm_scratch_* /s /q',exitstat=estat,cmdstat=cstat,cmdmsg=message)
5557
case default
5658
write(*,*)'ERROR: unknown OS. Stopping test'
5759
stop 2
58-
end select
60+
end select
5961
do i=1,size(directories)
6062
directories(i)=scr//trim(shortdirs(i))
6163
if( is_dir(trim(directories(i))) ) then
@@ -121,7 +123,7 @@ program new_test
121123
endif
122124

123125
do j=1,size(expected)
124-
126+
125127
expected(j)=scr//expected(j)
126128
if(is_os_windows) expected(j)=windows_path(expected(j))
127129
if( .not.(trim(expected(j)).in.file_names) )then
@@ -137,12 +139,12 @@ program new_test
137139
enddo TESTS
138140

139141
! clean up scratch files; might want an option to leave them for inspection
140-
select case (get_os_type())
142+
select case (get_os_type())
141143
case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD)
142144
call execute_command_line('rm -rf fpm_scratch_*',exitstat=estat,cmdstat=cstat,cmdmsg=message)
143-
case (OS_WINDOWS)
145+
case (OS_WINDOWS)
144146
call execute_command_line('rmdir fpm_scratch_* /s /q',exitstat=estat,cmdstat=cstat,cmdmsg=message)
145-
end select
147+
end select
146148

147149
write(*,'("TALLY=",*(g0))')tally
148150
if(all(tally))then
@@ -151,5 +153,19 @@ program new_test
151153
write(*,*)'FAILED: PASSED=',count(tally),' FAILED=',count(.not.tally)
152154
stop 5
153155
endif
156+
contains
157+
function get_command_path() result(command_path)
158+
character(len=:), allocatable :: command_path
159+
160+
type(string_t), allocatable :: files(:)
161+
integer :: i
154162

163+
call list_files("build", files)
164+
do i = 1, size(files)
165+
if (index(files(i)%s, "gfortran") > 0) then
166+
command_path = join_path(files(i)%s, "app", "fpm")
167+
return
168+
end if
169+
end do
170+
end function
155171
end program new_test

0 commit comments

Comments
 (0)