This fixes the problem observed with some filebuf tests.

The "@require@" string seems a bit hacky, as I don't know why that
string is in the tests in the first palce ... but it is there, so this
works.

-- > 8--

Some tests rely on text files with specific content being present in the
test directory. Because the tests modify those files, running the same
test more than once in the same directory will FAIL because the content
of the file is not in the expected state.

This uses a "@require@" marker that happens to be present in those tests
to decide when we need to copy the original files into the test dir
again, so that repeated tests always see the initial file content.

libstdc++-v3/ChangeLog:

        * testsuite/lib/libstdc++.exp (v3-init-data-files): New proc.
        (libstdc++_init): Use v3-init-data-files.
        (v3-dg-runtest): Use v3-init-data-files to update test data
        files for repeated tests.
---
 libstdc++-v3/testsuite/lib/libstdc++.exp | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp 
b/libstdc++-v3/testsuite/lib/libstdc++.exp
index 2c497707184..daace4c1d59 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -102,6 +102,12 @@ proc v3-copy-files {srcfiles} {
     }
 }
 
+proc v3-init-data-files { } {
+    global srcdir
+    v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
+    v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
+}
+
 # Called once, during runtest.exp setup.
 proc libstdc++_init { testfile } {
     global env
@@ -159,8 +165,7 @@ proc libstdc++_init { testfile } {
     set dg-do-what-default run
 
     # Copy any required data files.
-    v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
-    v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
+    v3-init-data-files
 
     set ld_library_path_tmp ""
 
@@ -556,11 +561,26 @@ proc v3-dg-runtest { testcases flags default-extra-flags 
} {
            set option_list { "" }
        }
 
+       # Some tests (e.g. 27_io/basic_filebuf/seek{off,pos}/char/[12]-io.cc)
+       # rely on text files with specific data being present in the test dir.
+       # Because the tests modify those files, running the same test a second
+       # time will FAIL due to the files not being in their initial state.
+       # We rely on the fact that those files contain a "@require@" comment
+       # to trigger creating fresh copies of the files for repeated tests.
+       if [search_for $test "@require@"] {
+           set need_fresh_data_files [llength $option_list]
+       } else {
+           set need_fresh_data_files 0
+       }
+
        set nshort [file tail [file dirname $test]]/[file tail $test]
 
        foreach flags_t $option_list {
            verbose "Testing $nshort, $flags $flags_t" 1
            dg-test $test "$flags $flags_t" ${default-extra-flags}
+           if { $need_fresh_data_files > 1 } {
+               v3-init-data-files
+           }
        }
     }
 }
-- 
2.41.0

Reply via email to