test programs for SELECT CASE
Steve Kargl
sgk@troutmask.apl.washington.edu
Thu Dec 30 19:56:00 GMT 2004
In looking at PR 19168, I found that the testsuite contains
only 1 program to test SELECT CASE. I've attached five
short test programs that can be merged into the testsuite.
select_2.f90, select_3.f90, and select_4.f90 should all
compile and execute with gfortran. select_5.f90 and
select_6.f90 should fail during compilation with errors
due to overlapping CASE ranges. I don't know how to
tell the testsuite that these two should fail. If someone
can annotate select_5.f90 and select_6.f90, I would
appreciate it.
2004-12-30 Steven G. Kargl <kargls@comcast.net>
* select_{2-6}.f90: new tests
--
Steve
-------------- next part --------------
!
! Simple test for SELECT CASE
!
program select_2
integer i
do i = 1, 4
select case(i)
case (1)
if (i /= 1) call abort
case (2:3)
if (i /= 2 .and. i /= 3) call abort
case (4)
if (i /= 4) call abort
case default
call abort
end select
end do
end program select_2
!
! Used with other Fortran 95 compilers
!
!subroutine abort
! print *, 'Abort'
! stop
!end subroutine abort
-------------- next part --------------
!
! Simple test program to see if gfortran eliminates the 'case (3:2)'
! statement. This is an unreachable CASE because the range is empty.
!
program select_3
integer i
do i = 1, 4
select case(i)
case (1)
if (i /= 1) call abort
case (3:2)
if (i /= 2 .and. i /= 3) call abort
case (4)
if (i /= 4) call abort
case default
if (i /= 2 .and. i /= 3) call abort
end select
end do
end program select_3
!
! Used with other Fortran 95 compilers
!
!subroutine abort
! print *, 'Abort'
! stop
!end subroutine abort
-------------- next part --------------
!
! Short test program with a CASE statement that uses a range.
!
program select_4
integer i
do i = 1, 40, 4
select case(i)
case (:5)
if (i /= 1 .and. i /= 5) call abort
case (20:30)
if (i /= 21 .and. i /= 25 .and. i /= 29) call abort
case (34:)
if (i /= 37) call abort
end select
end do
end program select_4
!
! Used with other Fortran 95 compilers
!
!subroutine abort
! print *, 'Abort'
! stop
!end subroutine abort
-------------- next part --------------
!
! This should compile due to the overlapping CASE values.
!
program select_4
integer i
do i = 1, 40, 4
select case(i)
case (:5)
if (i /= 1 .and. i /= 5) call abort
case (20:30)
if (i /= 21 .and. i /= 25 .and. i /= 29) call abort
case (25:)
if (i /= 37) call abort
end select
end do
end program select_4
!
! Used with other Fortran 95 compilers
!
!subroutine abort
! print *, 'Abort'
! stop
!end subroutine abort
-------------- next part --------------
!
! Test for overlapping ranges in the CASE statements.
! This should not compile.
!
program select_6
integer i
do i = 1, 40, 4
select case(i)
case (:15)
if (i /= 1 .and. i /= 5) call abort
case (10:30)
if (i /= 21 .and. i /= 25 .and. i /= 29) call abort
case (25:31)
if (i /= 37 .and. i /= 29) call abort
case (25:)
if (i /= 37) call abort
end select
end do
end program select_6
!
! Used with other Fortran 95 compilers
!
!subroutine abort
! print *, 'Abort'
! stop
!end subroutine abort
More information about the Fortran
mailing list