diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc
index e2b336a711d..d9e9c53e3e6 100644
--- a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc
@@ -15,14 +15,14 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.8.1.3 filebuf member functions
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.8.1.3 filebuf member functions
 
 // various tests for filebuf::open() and filebuf::close() including
 // the non-portable functionality in the libstdc++-v3 IO library
 
 // { dg-require-fileio "" }
+// { dg-additional-files "filebuf_members-1.tst filebuf_members-1.txt" }
+// { dg-final { file-io-diff "filebuf_members-1" } }
 
 #include <fstream>
 #include <testsuite_hooks.h>
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/2.cc
index 589402308c3..77543310caa 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/2.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/2.cc
@@ -17,11 +17,14 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.1.2.3 basic_istream::operator>>
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.6.1.2.3 basic_istream::operator>>
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_extractor_other-1.tst" }
+// { dg-additional-files "istream_extractor_other-1.txt" }
+// { dg-additional-files "istream_extractor_other-2.tst" }
+// { dg-final { file-io-diff "istream_extractor_other-1" } }
+// { dg-final { file-io-diff "istream_extractor_other-2" } }
 
 #include <istream>
 #include <fstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/2.cc
index b50dd26513a..82df1a17149 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/2.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/2.cc
@@ -15,11 +15,14 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.1.2.3 basic_istream::operator>>
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.6.1.2.3 basic_istream::operator>>
 
 // { dg-require-fileio "" }
+// { dg-additional-files "wistream_extractor_other-1.tst" }
+// { dg-additional-files "wistream_extractor_other-1.txt" }
+// { dg-additional-files "wistream_extractor_other-2.tst" }
+// { dg-final { file-io-diff "wistream_extractor_other-1" } }
+// { dg-final { file-io-diff "wistream_extractor_other-2" } }
 
 #include <istream>
 #include <fstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/get/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/get/char/2.cc
index cf646f379ef..95bad8badb9 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/get/char/2.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/get/char/2.cc
@@ -17,11 +17,13 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.1.3 unformatted input functions
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.6.1.3 unformatted input functions
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.tst" }
+// { dg-additional-files "istream_unformatted-1.txt" }
+// Reading the .txt file should not alter it:
+// { dg-final { file-io-diff "istream_unformatted-1" } }
 
 #include <istream>
 #include <sstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/2.cc
index 0ea162d8171..c155e402e2c 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/2.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/2.cc
@@ -15,11 +15,13 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.1.3 unformatted input functions
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.6.1.3 unformatted input functions
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.tst" }
+// { dg-additional-files "istream_unformatted-1.txt" }
+// Reading the .txt file should not alter it:
+// { dg-final { file-io-diff "istream_unformatted-1" } }
 
 #include <istream>
 #include <sstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/3.cc
index 222e450e9c8..acfafbcd83b 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/3.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/3.cc
@@ -17,11 +17,13 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.1.3 unformatted input functions
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.6.1.3 unformatted input functions
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.tst" }
+// { dg-additional-files "istream_unformatted-1.txt" }
+// Reading the .txt file should not alter it:
+// { dg-final { file-io-diff "istream_unformatted-1" } }
 
 #include <istream>
 #include <fstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/3.cc
index c9e942a712c..60c2655b606 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/3.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/3.cc
@@ -15,11 +15,13 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.1.3 unformatted input functions
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.6.1.3 unformatted input functions
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.tst" }
+// { dg-additional-files "istream_unformatted-1.txt" }
+// Reading the .txt file should not alter it:
+// { dg-final { file-io-diff "istream_unformatted-1" } }
 
 #include <istream>
 #include <fstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/6414.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/6414.cc
index 0e0b44153a8..ffa0e88d8eb 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/6414.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/6414.cc
@@ -17,10 +17,13 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.1.3 unformatted input functions
+// C++98 27.6.1.3 unformatted input functions
 // NB: ostream has a particular "seeks" category. Adopt this for istreams too.
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+
+// { dg-additional-files "istream_seeks-1.tst" }
+// { dg-additional-files "istream_seeks-1.txt" }
+// Reading the .txt file should not alter it:
+// { dg-final { file-io-diff "istream_seeks-1" } }
 
 #include <istream>
 #include <fstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/6414.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/6414.cc
index fbfbfbb2781..0d2172fe85d 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/6414.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/6414.cc
@@ -15,10 +15,13 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.1.3 unformatted input functions
+// C++98 27.6.1.3 unformatted input functions
 // NB: ostream has a particular "seeks" category. Adopt this for istreams too.
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+
+// { dg-additional-files "wistream_seeks-1.tst" }
+// { dg-additional-files "wistream_seeks-1.txt" }
+// Reading the .txt file should not alter it:
+// { dg-final { file-io-diff "wistream_seeks-1" } }
 
 #include <istream>
 #include <fstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/fstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/fstream.cc
index 0fa91a2716b..52401ca88fd 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/fstream.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/fstream.cc
@@ -17,12 +17,16 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.1.3 unformatted input functions
+// C++98 27.6.1.3 unformatted input functions
 // NB: ostream has a particular "seeks" category. Adopt this for istreams too.
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_seeks-1.tst" }
+// { dg-additional-files "istream_seeks-1.txt" }
+// { dg-additional-files "istream_seeks-2.tst" }
+// Do not create istream_seeks-2.txt, we want it to be created as empty.
+// { dg-final { file-io-diff "istream_seeks-1" } }
+// { dg-final { file-io-diff "istream_seeks-2" } }
 
 #include <istream>
 #include <sstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/fstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/fstream.cc
index b792c8bc5cc..6dc69d57516 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/fstream.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/fstream.cc
@@ -16,11 +16,15 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-require-fileio "" }
+// { dg-additional-files "wistream_seeks-1.tst" }
+// { dg-additional-files "wistream_seeks-1.txt" }
+// { dg-additional-files "wistream_seeks-2.tst" }
+// Do not create wistream_seeks-2.txt, we want it to be created as empty.
+// { dg-final { file-io-diff "wistream_seeks-1" } }
+// { dg-final { file-io-diff "wistream_seeks-2" } }
 
-// 27.6.1.3 unformatted input functions
+// C++98 27.6.1.3 unformatted input functions
 // NB: ostream has a particular "seeks" category. Adopt this for istreams too.
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
 
 #include <istream>
 #include <sstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/fstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/fstream.cc
index a1eabd6abb4..8ab130a0a71 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/fstream.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/fstream.cc
@@ -17,12 +17,16 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.1.3 unformatted input functions
+// C++98 27.6.1.3 unformatted input functions
 // NB: ostream has a particular "seeks" category. Adopt this for istreams too.
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_seeks-1.tst" }
+// { dg-additional-files "istream_seeks-1.txt" }
+// { dg-additional-files "istream_seeks-2.tst" }
+// Do not create istream_seeks-2.txt, we want it to be created as empty.
+// { dg-final { file-io-diff "istream_seeks-1" } }
+// { dg-final { file-io-diff "istream_seeks-2" } }
 
 #include <istream>
 #include <sstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/fstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/fstream.cc
index 636193af7e3..b22871f0d7d 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/fstream.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/fstream.cc
@@ -16,11 +16,15 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-require-fileio "" }
+// { dg-additional-files "wistream_seeks-1.tst" }
+// { dg-additional-files "wistream_seeks-1.txt" }
+// { dg-additional-files "wistream_seeks-2.tst" }
+// Do not create wistream_seeks-2.txt, we want it to be created as empty.
+// { dg-final { file-io-diff "wistream_seeks-1" } }
+// { dg-final { file-io-diff "wistream_seeks-2" } }
 
-// 27.6.1.3 unformatted input functions
+// C++98 27.6.1.3 unformatted input functions
 // NB: ostream has a particular "seeks" category. Adopt this for istreams too.
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
 
 #include <istream>
 #include <sstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc
index 45227107cbd..a9086a595cb 100644
--- a/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc
@@ -17,10 +17,9 @@
 
 // C++98 27.8.1.10 ofstream member functions
 
-// { dg-additional-files "ofstream_members-1.tst" }
-// @diff@ %-*.tst %-*.txt
-
 // { dg-require-fileio "" }
+// { dg-additional-files "ofstream_members-1.tst" }
+// { dg-final { file-io-diff "ofstream_members-1" } }
 
 #include <ostream>
 #include <fstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc
index 6d30d0ce94f..86a0ee8e77d 100644
--- a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc
@@ -18,11 +18,13 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.2.5.4 basic_ostream character inserters
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.6.2.5.3 basic_ostream inserters
 
 // { dg-require-fileio "" }
+// { dg-additional-files "ostream_inserter_other-1.tst" }
+// { dg-additional-files "ostream_inserter_other-2.tst" }
+// { dg-final { file-io-diff "ostream_inserter_other-1" } }
+// { dg-final { file-io-diff "ostream_inserter_other-2" } }
 
 #include <ostream>
 #include <sstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc
index 15f0d5f7b0b..735f2e20e9c 100644
--- a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc
@@ -18,9 +18,9 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.2.5.4 basic_ostream character inserters
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.6.2.5.3 basic_ostream inserters
+
+// { dg-final { file-io-diff "ostream_inserter_other_in" "ostream_inserter_other_out" } }
 
 #include <ostream>
 #include <fstream>
@@ -56,6 +56,7 @@ test03(void)
   out.seekp(0, ios_base::end);
   i_read = in.tellg() - rs;
   i_wrote = out.tellp() - ws;
+  VERIFY( i_read == i_wrote );
   in.close();
   out.close();
 }
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc
index 7692637e16d..1aecfa4f0e9 100644
--- a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc
@@ -15,11 +15,13 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.2.5.4 basic_ostream character inserters
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.6.2.5.3 basic_ostream inserters
 
 // { dg-require-fileio "" }
+// { dg-additional-files "wostream_inserter_other-1.tst" }
+// { dg-additional-files "wostream_inserter_other-2.tst" }
+// { dg-final { file-io-diff "wostream_inserter_other-1" } }
+// { dg-final { file-io-diff "wostream_inserter_other-2" } }
 
 #include <ostream>
 #include <sstream>
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc
index 856af56011a..663539a5b19 100644
--- a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc
@@ -15,9 +15,9 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.6.2.5.4 basic_ostream character inserters
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.6.2.5.3 basic_ostream inserters
+
+// { dg-final { file-io-diff "wostream_inserter_other_in.txt" "wostream_inserter_other_out.txt" } }
 
 #include <ostream>
 #include <fstream>
@@ -53,6 +53,7 @@ test03(void)
   out.seekp(0, ios_base::end);
   i_read = in.tellg() - rs;
   i_wrote = out.tellp() - ws;
+  VERIFY( i_read == i_wrote );
   in.close();
   out.close();
 }
diff --git a/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/1.cc b/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/1.cc
index 4f9f7c3e554..20cbc1e08cd 100644
--- a/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/1.cc
+++ b/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/1.cc
@@ -20,8 +20,9 @@
 // <http://www.gnu.org/licenses/>.
 
 // 27.4.2.4 ios_base static members
-// @require@ %-*.tst
-// @diff@ %-*.tst %-*.txt
+
+// { dg-additional-files "ios_base_members_static-1.tst" }
+// { dg-final { file-io-diff "ios_base_members_static-1" } }
 
 #include <cstdio>
 #include <sstream>
diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
index 8efc6f7f089..ef511949c7b 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -1674,3 +1674,35 @@ if { [info exists env(GCC_RUNTEST_PARALLELIZE_DIR)] \
     }
 
 }
+
+# Compare output file written by test to expected result.
+# With two arguments the comparison is done via 'diff arg1 arg2'.
+# With one argument the comparison is done via 'diff arg1.tst arg1.txt'.
+proc file-io-diff { args } {
+    set nargs [llength $args]
+    if { $nargs < 1 } {
+	error "too few arguments to file-io-diff"
+    }
+    if { $nargs > 2 } {
+	error "too many arguments to file-io-diff"
+    }
+    if { $nargs == 1 } {
+	set file1 [lindex $args 0]
+	set file2 "${file1}.txt"
+	append file1 ".tst"
+    } else {
+	set file1 [lindex $args 0]
+	set file2 [lindex $args 1]
+    }
+
+    spawn -noecho diff -u $file1 $file2
+    expect {
+      -re ".+" {
+	set msg "files differ\n"
+	append msg $expect_out(0,string)
+	fail $msg
+	exp_continue
+      }
+    }
+    return
+}
