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