| 1 |
! { dg-do run } |
| 2 |
!TODO: Move these testcases to gfortran testsuite |
| 3 |
! once compilation with pthreads is supported there |
| 4 |
! PR55818 Reading a REAL from a file which doesn't end in a new line fails |
| 5 |
! Test case from PR reporter. |
| 6 |
implicit none |
| 7 |
integer :: stat |
| 8 |
!integer :: var ! << works |
| 9 |
real :: var ! << fails |
| 10 |
character(len=10) :: cvar ! << fails |
| 11 |
complex :: cval |
| 12 |
logical :: lvar |
| 13 |
|
| 14 |
open(99, file="test.dat", access="stream", form="unformatted", status="new") |
| 15 |
write(99) "1", new_line("") |
| 16 |
write(99) "2", new_line("") |
| 17 |
write(99) "3" |
| 18 |
close(99) |
| 19 |
|
| 20 |
! Test character kind |
| 21 |
open(99, file="test.dat") |
| 22 |
read (99,*, iostat=stat) cvar |
| 23 |
if (stat /= 0 .or. cvar /= "1") stop 1 |
| 24 |
read (99,*, iostat=stat) cvar |
| 25 |
if (stat /= 0 .or. cvar /= "2") stop 2 |
| 26 |
read (99,*, iostat=stat) cvar ! << FAILS: stat /= 0 |
| 27 |
if (stat /= 0 .or. cvar /= "3") stop 3 ! << aborts here |
| 28 |
|
| 29 |
! Test real kind |
| 30 |
rewind(99) |
| 31 |
read (99,*, iostat=stat) var |
| 32 |
if (stat /= 0 .or. var /= 1.0) stop 4 |
| 33 |
read (99,*, iostat=stat) var |
| 34 |
if (stat /= 0 .or. var /= 2.0) stop 5 |
| 35 |
read (99,*, iostat=stat) var ! << FAILS: stat /= 0 |
| 36 |
if (stat /= 0 .or. var /= 3.0) stop 6 |
| 37 |
close(99, status="delete") |
| 38 |
|
| 39 |
! Test real kind with exponents |
| 40 |
open(99, file="test.dat", access="stream", form="unformatted", status="new") |
| 41 |
write(99) "1.0e3", new_line("") |
| 42 |
write(99) "2.0e-03", new_line("") |
| 43 |
write(99) "3.0e2" |
| 44 |
close(99) |
| 45 |
|
| 46 |
open(99, file="test.dat") |
| 47 |
read (99,*, iostat=stat) var |
| 48 |
if (stat /= 0) stop 7 |
| 49 |
read (99,*, iostat=stat) var |
| 50 |
if (stat /= 0) stop 8 |
| 51 |
read (99,*) var ! << FAILS: stat /= 0 |
| 52 |
if (stat /= 0) stop 9 |
| 53 |
close(99, status="delete") |
| 54 |
|
| 55 |
! Test logical kind |
| 56 |
open(99, file="test.dat", access="stream", form="unformatted", status="new") |
| 57 |
write(99) "Tru", new_line("") |
| 58 |
write(99) "fal", new_line("") |
| 59 |
write(99) "t" |
| 60 |
close(99) |
| 61 |
|
| 62 |
open(99, file="test.dat") |
| 63 |
read (99,*, iostat=stat) lvar |
| 64 |
if (stat /= 0 .or. (.not.lvar)) stop 10 |
| 65 |
read (99,*, iostat=stat) lvar |
| 66 |
if (stat /= 0 .or. lvar) stop 11 |
| 67 |
read (99,*) lvar ! << FAILS: stat /= 0 |
| 68 |
if (stat /= 0 .or. (.not.lvar)) stop 12 |
| 69 |
close(99, status="delete") |
| 70 |
|
| 71 |
! Test combinations of Inf and Nan |
| 72 |
open(99, file="test.dat", access="stream", form="unformatted", status="new") |
| 73 |
write(99) "infinity", new_line("") |
| 74 |
write(99) "nan", new_line("") |
| 75 |
write(99) "infinity" |
| 76 |
close(99) |
| 77 |
|
| 78 |
open(99, file="test.dat") |
| 79 |
read (99,*, iostat=stat) var |
| 80 |
if (stat /= 0) stop 13 |
| 81 |
read (99,*, iostat=stat) var |
| 82 |
if (stat /= 0) stop 14 |
| 83 |
read (99,*) var ! << FAILS: stat /= 0 |
| 84 |
if (stat /= 0) stop 1! << aborts here |
| 85 |
close(99, status="delete") |
| 86 |
|
| 87 |
open(99, file="test.dat", access="stream", form="unformatted", status="new") |
| 88 |
write(99) "infinity", new_line("") |
| 89 |
write(99) "inf", new_line("") |
| 90 |
write(99) "nan" |
| 91 |
close(99) |
| 92 |
|
| 93 |
open(99, file="test.dat") |
| 94 |
read (99,*, iostat=stat) var |
| 95 |
if (stat /= 0) stop 15 |
| 96 |
read (99,*, iostat=stat) var |
| 97 |
if (stat /= 0) stop 16 |
| 98 |
read (99,*) var ! << FAILS: stat /= 0 |
| 99 |
if (stat /= 0) stop 2! << aborts here |
| 100 |
close(99, status="delete") |
| 101 |
|
| 102 |
open(99, file="test.dat", access="stream", form="unformatted", status="new") |
| 103 |
write(99) "infinity", new_line("") |
| 104 |
write(99) "nan", new_line("") |
| 105 |
write(99) "inf" |
| 106 |
close(99) |
| 107 |
|
| 108 |
open(99, file="test.dat") |
| 109 |
read (99,*, iostat=stat) var |
| 110 |
if (stat /= 0) stop 17 |
| 111 |
read (99,*, iostat=stat) var |
| 112 |
if (stat /= 0) stop 18 |
| 113 |
read (99,*) var ! << FAILS: stat /= 0 |
| 114 |
if (stat /= 0) stop 3! << aborts here |
| 115 |
close(99, status="delete") |
| 116 |
|
| 117 |
! Test complex kind |
| 118 |
open(99, file="test.dat", access="stream", form="unformatted", status="new") |
| 119 |
write(99) "(1,2)", new_line("") |
| 120 |
write(99) "(2,3)", new_line("") |
| 121 |
write(99) "(4,5)" |
| 122 |
close(99) |
| 123 |
|
| 124 |
open(99, file="test.dat") |
| 125 |
read (99,*, iostat=stat) cval |
| 126 |
if (stat /= 0 .or. cval /= cmplx(1,2)) stop 19 |
| 127 |
read (99,*, iostat=stat) cval |
| 128 |
if (stat /= 0 .or. cval /= cmplx(2,3)) stop 20 |
| 129 |
read (99,*, iostat=stat) cval ! << FAILS: stat /= 0, value is okay |
| 130 |
if (stat /= 0 .or. cval /= cmplx(4,5)) stop 21 |
| 131 |
close(99, status="delete") |
| 132 |
end |