PR target/83368
[official-gcc.git] / gcc / testsuite / gfortran.dg / open_errors.f90
blob23d4b3d807b1cc824c8c3a699428c1405f10ee6e
1 ! { dg-do run { target { ! { *-*-mingw* *-*-cygwin* spu-*-* } } } }
2 ! PR30005 Enhanced error messages for OPEN
3 ! Submitted by Jerry DeLisle <jvdelisle@gcc.gnu.org>
4 ! See PR38956. Test fails on cygwin when user has Administrator rights
5 ! As of the fix for PR 65200, the error message is partly generated by
6 ! strerror*(), so can depend on the target and the locale, so check
7 ! only the beginning of the error string, which should be constant.
8 character(60) :: msg
9 character(25) :: n = "temptestfile"
10 logical :: there
11 inquire(file=n, exist=there)
12 if (.not.there) then
13 open(77,file=n,status="new")
14 close(77, status="keep")
15 endif
16 msg=""
17 open(77,file=n,status="new", iomsg=msg, iostat=i)
18 if (i == 0) call abort()
19 if (msg(1:33) /= "Cannot open file 'temptestfile': ") call abort()
21 open(77,file=n,status="old")
22 close(77, status="delete")
23 open(77,file=n,status="old", iomsg=msg, iostat=i)
24 if (i == 0) call abort()
25 if (msg(1:33) /= "Cannot open file 'temptestfile': ") call abort()
27 open(77,file="./", iomsg=msg, iostat=i)
28 if (msg(1:23) /= "Cannot open file './': " &
29 .and. msg /= "Invalid argument") call abort()
31 open(77,file=n,status="new")
32 i = chmod(n, "-w")
33 if (i == 0 .and. getuid() /= 0) then
34 close(77, status="keep")
35 open(77,file=n, iomsg=msg, iostat=i, action="write")
36 if (i == 0) call abort()
37 if (msg(1:33) /= "Cannot open file 'temptestfile': ") call abort()
38 endif
40 i = chmod(n,"+w")
41 open(77,file=n, iomsg=msg, iostat=i, action="read")
42 close(77, status="delete")
43 end