| 1 |
program help_test |
| 2 |
! note hardcoded len=k1 instead of len=: in this test is a work-around a gfortran bug in old |
| 3 |
! pre-v8.3 versions |
| 4 |
use,intrinsic :: iso_fortran_env, only : stdin=>input_unit, stdout=>output_unit, stderr=>error_unit |
| 5 |
use fpm_filesystem, only : dirname, join_path, exists |
| 6 |
use fpm_environment, only : get_os_type, OS_WINDOWS |
| 7 |
implicit none |
| 8 |
integer :: i |
| 9 |
integer :: be, af |
| 10 |
character(len=:),allocatable :: path |
| 11 |
integer :: estat, cstat |
| 12 |
integer,parameter :: k1=132 |
| 13 |
character(len=k1) :: message |
| 14 |
logical,allocatable :: tally(:) |
| 15 |
!intel-bug!character(len=:),allocatable :: book1(:), book2(:) |
| 16 |
character(len=k1),allocatable :: book1(:), book2(:) |
| 17 |
!intel-bug!character(len=:),allocatable :: page1(:) |
| 18 |
character(len=k1),allocatable :: page1(:) |
| 19 |
integer :: lines |
| 20 |
integer :: chars |
| 21 |
! run a variety of "fpm help" variations and verify expected files are generated |
| 22 |
character(len=*),parameter :: cmds(*) = [character(len=80) :: & |
| 23 |
! build manual as pieces using various help commands |
| 24 |
! debug version |
| 25 |
'--version ',& ! verify fpm version being used |
| 26 |
'--help > fpm_scratch_help.txt',& |
| 27 |
'help new >> fpm_scratch_help.txt',& |
| 28 |
'help update >> fpm_scratch_help.txt',& |
| 29 |
'build --help >> fpm_scratch_help.txt',& |
| 30 |
'help run >> fpm_scratch_help.txt',& |
| 31 |
'help test >> fpm_scratch_help.txt',& |
| 32 |
'help runner >> fpm_scratch_help.txt',& |
| 33 |
'help install >> fpm_scratch_help.txt',& |
| 34 |
'help list >> fpm_scratch_help.txt',& |
| 35 |
'help help >> fpm_scratch_help.txt',& |
| 36 |
'help clean >> fpm_scratch_help.txt',& |
| 37 |
'help publish >> fpm_scratch_help.txt',& |
| 38 |
'--version >> fpm_scratch_help.txt',& |
| 39 |
! generate manual |
| 40 |
' help manual > fpm_scratch_manual.txt'] |
| 41 |
|
| 42 |
!'fpm run >> fpm_scratch_help.txt',& |
| 43 |
!'fpm run -- --list >> fpm_scratch_help.txt',& |
| 44 |
!'fpm run -- list --list >> fpm_scratch_help.txt',& |
| 45 |
character(len=*),parameter :: names(*)=[character(len=10) ::& |
| 46 |
'fpm','new','update','build','run','test','runner','install','list','help','clean'] |
| 47 |
character(len=:), allocatable :: prog |
| 48 |
integer :: length |
| 49 |
|
| 50 |
! FIXME: Super hacky way to get the name of the fpm executable, |
| 51 |
! it works better than invoking fpm again but should be replaced ASAP. |
| 52 |
call get_command_argument(0, length=length) |
| 53 |
allocate(character(len=length) :: prog) |
| 54 |
call get_command_argument(0, prog) |
| 55 |
path = dirname(prog) |
| 56 |
if (get_os_type() == OS_WINDOWS) then |
| 57 |
prog = join_path(path, "..", "app", "fpm.exe") |
| 58 |
if (.not.exists(prog)) then |
| 59 |
prog = join_path(path, "..", "..", "app", "fpm.exe") |
| 60 |
end if |
| 61 |
else |
| 62 |
prog = join_path(path, "..", "app", "fpm") |
| 63 |
if (.not.exists(prog)) then |
| 64 |
prog = join_path(path, "..", "..", "app", "fpm") |
| 65 |
end if |
| 66 |
end if |
| 67 |
|
| 68 |
write(*,'(g0:,1x)')'<INFO>TEST help SUBCOMMAND STARTED' |
| 69 |
if(allocated(tally))deallocate(tally) |
| 70 |
allocate(tally(0)) |
| 71 |
call wipe('fpm_scratch_help.txt') |
| 72 |
call wipe('fpm_scratch_manual.txt') |
| 73 |
|
| 74 |
! check that output has NAME SYNOPSIS DESCRIPTION |
| 75 |
do i=1,size(names) |
| 76 |
write(*,*)'<INFO>check '//names(i)//' for NAME SYNOPSIS DESCRIPTION' |
| 77 |
path= prog // ' help '//names(i)//' >fpm_scratch_help.txt' |
| 78 |
message='' |
| 79 |
call execute_command_line(path,exitstat=estat,cmdstat=cstat,cmdmsg=message) |
| 80 |
write(*,'(*(g0))')'<INFO>CMD=',path,' EXITSTAT=',estat,' CMDSTAT=',cstat,' MESSAGE=',trim(message) |
| 81 |
tally=[tally,all([estat==0,cstat==0])] |
| 82 |
call swallow('fpm_scratch_help.txt',page1) |
| 83 |
if(size(page1)<3)then |
| 84 |
write(*,*)'<ERROR>help for '//names(i)//' ridiculiously small' |
| 85 |
tally=[tally,.false.] |
| 86 |
exit |
| 87 |
endif |
| 88 |
!!write(*,*)findloc(page1,'NAME')==1 |
| 89 |
be=count(.not.tally) |
| 90 |
tally=[tally,count(page1=='NAME')==1] |
| 91 |
tally=[tally,count(page1=='SYNOPSIS')==1] |
| 92 |
tally=[tally,count(page1=='DESCRIPTION')==1] |
| 93 |
af=count(.not.tally) |
| 94 |
if(be/=af)then |
| 95 |
write(*,*)'<ERROR>missing expected sections in ',names(i) |
| 96 |
write(*,*)page1(1) ! assuming at least size 1 for debugging mingw |
| 97 |
write(*,*)count(page1=='NAME') |
| 98 |
write(*,*)count(page1=='SYNOPSIS') |
| 99 |
write(*,*)count(page1=='DESCRIPTION') |
| 100 |
write(*,'(a)')page1 |
| 101 |
endif |
| 102 |
write(*,*)'<INFO>have completed ',count(tally),' tests' |
| 103 |
call wipe('fpm_scratch_help.txt') |
| 104 |
enddo |
| 105 |
|
| 106 |
|
| 107 |
! execute the fpm(1) commands |
| 108 |
do i=1,size(cmds) |
| 109 |
message='' |
| 110 |
path= prog //' '//cmds(i) |
| 111 |
call execute_command_line(path,exitstat=estat,cmdstat=cstat,cmdmsg=message) |
| 112 |
write(*,'(*(g0))')'<INFO>CMD=',path,' EXITSTAT=',estat,' CMDSTAT=',cstat,' MESSAGE=',trim(message) |
| 113 |
tally=[tally,all([estat==0,cstat==0])] |
| 114 |
enddo |
| 115 |
|
| 116 |
! compare book written in fragments with manual |
| 117 |
call swallow('fpm_scratch_help.txt',book1) |
| 118 |
call swallow('fpm_scratch_manual.txt',book2) |
| 119 |
! get rid of lines from run() which is not on stderr at the moment |
| 120 |
book1=pack(book1,index(book1,' + build/')==0) |
| 121 |
book2=pack(book1,index(book2,' + build/')==0) |
| 122 |
write(*,*)'<INFO>book1 ',size(book1), len(book1) |
| 123 |
write(*,*)'<INFO>book2 ',size(book2), len(book2) |
| 124 |
if(size(book1)/=size(book2))then |
| 125 |
write(*,*)'<ERROR>manual and "debug" appended pages are not the same size' |
| 126 |
tally=[tally,.false.] |
| 127 |
else |
| 128 |
if(all(book1/=book2))then |
| 129 |
tally=[tally,.false.] |
| 130 |
write(*,*)'<ERROR>manual and "debug" appended pages are not the same' |
| 131 |
else |
| 132 |
write(*,*)'<INFO>manual and "debug" appended pages are the same' |
| 133 |
tally=[tally,.true.] |
| 134 |
endif |
| 135 |
endif |
| 136 |
|
| 137 |
! overall size of manual |
| 138 |
!chars=size(book2) |
| 139 |
!lines=max(count(char(10)==book2),count(char(13)==book2)) |
| 140 |
chars=sum(len_trim(book2)) ! SUM TRIMMED LENGTH |
| 141 |
lines=size(book2) |
| 142 |
if( (chars<12000) .or. (lines<350) )then |
| 143 |
write(*,*)'<ERROR>"debug" manual is suspiciously small, bytes=',chars,' lines=',lines |
| 144 |
tally=[tally,.false.] |
| 145 |
else |
| 146 |
write(*,*)'<INFO>"debug" manual size in bytes=',chars,' lines=',lines |
| 147 |
tally=[tally,.true.] |
| 148 |
endif |
| 149 |
|
| 150 |
write(*,'("<INFO>HELP TEST TALLY=",*(g0))')tally |
| 151 |
call wipe('fpm_scratch_help.txt') |
| 152 |
call wipe('fpm_scratch_manual.txt') |
| 153 |
if(all(tally))then |
| 154 |
write(*,'(*(g0))')'<INFO>PASSED: all ',count(tally),' tests passed ' |
| 155 |
else |
| 156 |
write(*,*)'<INFO>FAILED: PASSED=',count(tally),' FAILED=',count(.not.tally) |
| 157 |
stop 5 |
| 158 |
endif |
| 159 |
write(*,'(g0:,1x)')'<INFO>TEST help SUBCOMMAND COMPLETE' |
| 160 |
contains |
| 161 |
|
| 162 |
subroutine wipe(filename) |
| 163 |
character(len=*),intent(in) :: filename |
| 164 |
integer :: ios |
| 165 |
integer :: lun |
| 166 |
character(len=k1) :: message |
| 167 |
open(file=filename,newunit=lun,iostat=ios,iomsg=message) |
| 168 |
if(ios==0)then |
| 169 |
close(unit=lun,iostat=ios,status='delete',iomsg=message) |
| 170 |
if(ios/=0)then |
| 171 |
write(*,*)'<ERROR>'//trim(message) |
| 172 |
endif |
| 173 |
else |
| 174 |
write(*,*)'<ERROR>'//trim(message) |
| 175 |
endif |
| 176 |
end subroutine wipe |
| 177 |
|
| 178 |
subroutine slurp(filename,text) |
| 179 |
implicit none |
| 180 |
!$@(#) M_io::slurp(3f): allocate text array and read file filename into it |
| 181 |
character(*),intent(in) :: filename ! filename to shlep |
| 182 |
character(len=1),allocatable,intent(out) :: text(:) ! array to hold file |
| 183 |
integer :: nchars, igetunit, ios |
| 184 |
character(len=k1) :: message |
| 185 |
character(len=4096) :: local_filename |
| 186 |
ios=0 |
| 187 |
nchars=0 |
| 188 |
message='' |
| 189 |
open(newunit=igetunit, file=trim(filename), action="read", iomsg=message,& |
| 190 |
&form="unformatted", access="stream",status='old',iostat=ios) |
| 191 |
local_filename=filename |
| 192 |
if(ios==0)then ! if file was successfully opened |
| 193 |
inquire(unit=igetunit, size=nchars) |
| 194 |
if(nchars<=0)then |
| 195 |
call stderr_local( '*slurp* empty file '//trim(local_filename) ) |
| 196 |
return |
| 197 |
endif |
| 198 |
! read file into text array |
| 199 |
if(allocated(text))deallocate(text) ! make sure text array not allocated |
| 200 |
allocate ( text(nchars) ) ! make enough storage to hold file |
| 201 |
read(igetunit,iostat=ios,iomsg=message) text ! load input file -> text array |
| 202 |
if(ios/=0)then |
| 203 |
call stderr_local( '*slurp* bad read of '//trim(local_filename)//':'//trim(message) ) |
| 204 |
endif |
| 205 |
else |
| 206 |
call stderr_local('*slurp* '//message) |
| 207 |
allocate ( text(0) ) ! make enough storage to hold file |
| 208 |
endif |
| 209 |
close(iostat=ios,unit=igetunit) ! close if opened successfully or not |
| 210 |
end subroutine slurp |
| 211 |
|
| 212 |
subroutine stderr_local(message) |
| 213 |
character(len=*) :: message |
| 214 |
write(*,'(a)')trim(message) ! write message to standard error |
| 215 |
end subroutine stderr_local |
| 216 |
|
| 217 |
subroutine swallow(FILENAME,pageout) |
| 218 |
implicit none |
| 219 |
character(len=*),intent(in) :: FILENAME ! file to read |
| 220 |
!intel-bug!character(len=:),allocatable,intent(out) :: pageout(:) ! page to hold file in memory |
| 221 |
character(len=k1),allocatable,intent(out) :: pageout(:) ! page to hold file in memory |
| 222 |
character(len=1),allocatable :: text(:) ! array to hold file in memory |
| 223 |
|
| 224 |
call slurp(FILENAME,text) ! allocate character array and copy file into it |
| 225 |
|
| 226 |
if(.not.allocated(text))then |
| 227 |
write(*,*)'<ERROR>*swallow* failed to load file '//FILENAME |
| 228 |
else ! convert array of characters to array of lines |
| 229 |
pageout=page(text) |
| 230 |
deallocate(text) ! release memory |
| 231 |
endif |
| 232 |
end subroutine swallow |
| 233 |
|
| 234 |
function page(array) result (table) |
| 235 |
|
| 236 |
!$@(#) M_strings::page(3fp): function to copy char array to page of text |
| 237 |
|
| 238 |
character(len=1),intent(in) :: array(:) |
| 239 |
!intel-bug!character(len=:),allocatable :: table(:) |
| 240 |
character(len=k1),allocatable :: table(:) |
| 241 |
integer :: i |
| 242 |
integer :: linelength |
| 243 |
integer :: length |
| 244 |
integer :: lines |
| 245 |
integer :: linecount |
| 246 |
integer :: position |
| 247 |
integer :: sz |
| 248 |
!!character(len=1),parameter :: nl=new_line('A') |
| 249 |
character(len=1),parameter :: nl=char(10) |
| 250 |
character(len=1),parameter :: cr=char(13) |
| 251 |
lines=0 |
| 252 |
linelength=0 |
| 253 |
length=0 |
| 254 |
sz=size(array) |
| 255 |
do i=1,sz |
| 256 |
if(array(i)==nl)then |
| 257 |
linelength=max(linelength,length) |
| 258 |
lines=lines+1 |
| 259 |
length=0 |
| 260 |
else |
| 261 |
length=length+1 |
| 262 |
endif |
| 263 |
enddo |
| 264 |
if(sz>0)then |
| 265 |
if(array(sz)/=nl)then |
| 266 |
lines=lines+1 |
| 267 |
endif |
| 268 |
endif |
| 269 |
|
| 270 |
if(allocated(table))deallocate(table) |
| 271 |
!intel-bug!allocate(character(len=linelength) :: table(lines)) |
| 272 |
allocate(character(len=k1) :: table(lines)) |
| 273 |
table=' ' |
| 274 |
linecount=1 |
| 275 |
position=1 |
| 276 |
do i=1,sz |
| 277 |
if(array(i)==nl)then |
| 278 |
linecount=linecount+1 |
| 279 |
position=1 |
| 280 |
elseif(array(i)==cr)then |
| 281 |
elseif(linelength/=0)then |
| 282 |
if(position>len(table))then |
| 283 |
write(*,*)'<ERROR> adding character past edge of text',table(linecount),array(i) |
| 284 |
elseif(linecount>size(table))then |
| 285 |
write(*,*)'<ERROR> adding line past end of text',linecount,size(table) |
| 286 |
else |
| 287 |
table(linecount)(position:position)=array(i) |
| 288 |
endif |
| 289 |
position=position+1 |
| 290 |
endif |
| 291 |
enddo |
| 292 |
end function page |
| 293 |
|
| 294 |
end program help_test |