diff --git a/gcc/testsuite/lib/fortran-modules.exp b/gcc/testsuite/lib/fortran-modules.exp index 158b16bada9..a7196f13ed2 100644 --- a/gcc/testsuite/lib/fortran-modules.exp +++ b/gcc/testsuite/lib/fortran-modules.exp @@ -172,3 +172,24 @@ proc igrep { args } { } return $grep_out } + +# If the code has any "open" statements for numbered units, make sure +# no corresponding output file remains. Redundant remove operations +# are ok, but duplicate removals look sloppy, so track for uniqueness. +proc fortran-delete-unit-files { src } { + set openpat {open *\( *(?:unit *= *)?([0-9]+)} + set openmatches [igrep $src $openpat] + if {![string match "" $openmatches]} { + # verbose -log "Found \"$openmatches\"" + set deleted_units {} + foreach openmatch $openmatches { + regexp -nocase -- "$openpat" $openmatch match unit + if {[lsearch $deleted_units $unit] < 0} { + set rmfile "fort.$unit" + verbose -log "Deleting $rmfile" + remote_file target delete "fort.$unit" + lappend deleted_units $unit + } + } + } +} diff --git a/gcc/testsuite/lib/fortran-torture.exp b/gcc/testsuite/lib/fortran-torture.exp index 66f5bc82223..0727fb4fb0a 100644 --- a/gcc/testsuite/lib/fortran-torture.exp +++ b/gcc/testsuite/lib/fortran-torture.exp @@ -332,6 +332,8 @@ proc fortran-torture-execute { src } { catch { remote_file build delete $executable } } $status "$testcase execution, $option" + + fortran-delete-unit-files $src } cleanup-modules "" } diff --git a/gcc/testsuite/lib/gfortran-dg.exp b/gcc/testsuite/lib/gfortran-dg.exp index fcba95dc396..2edc09e5c99 100644 --- a/gcc/testsuite/lib/gfortran-dg.exp +++ b/gcc/testsuite/lib/gfortran-dg.exp @@ -160,6 +160,7 @@ proc gfortran-dg-runtest { testcases flags default-extra-flags } { foreach flags_t $option_list { verbose "Testing $nshort, $flags $flags_t" 1 dg-test $test "$flags $flags_t" ${default-extra-flags} + fortran-delete-unit-files $test cleanup-modules "" } }