]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add file-io-diff to replace @diff@ markup in I/O tests
authorJonathan Wakely <jwakely@redhat.com>
Mon, 22 Jul 2024 13:39:57 +0000 (14:39 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 24 Jul 2024 11:25:26 +0000 (12:25 +0100)
This adds a new dg-final action to compare two files after a test has
run, so that we can verify that fstream operations produce the expected
results. With this change, all uses of @diff@ that seem potentially
useful have been converted to actually compare the files and FAIL if
they differ.

The file-io-diff action can take two arguments naming the files to be
compared, or for convenience it can take a single string and will
compare STR.tst and STR.txt, as that's how it's commonly used.

Additionally, all remaining uses of @require@ are converted to
dg-additional-files directives, so that the TODO in libstdc++.exp can
be resolved.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_filebuf/close/char/1.cc: Remove
@require@ and @diff@. Use dg-final file-io-diff action.
* testsuite/27_io/basic_istream/extractors_other/char/2.cc:
Likewise.
* testsuite/27_io/basic_istream/extractors_other/wchar_t/2.cc:
Likewise.
* testsuite/27_io/basic_istream/get/char/2.cc: Likewise.
* testsuite/27_io/basic_istream/get/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_istream/ignore/char/3.cc: Likewise.
* testsuite/27_io/basic_istream/ignore/wchar_t/3.cc: Likewise.
* testsuite/27_io/basic_istream/peek/char/6414.cc: Likewise.
* testsuite/27_io/basic_istream/peek/wchar_t/6414.cc: Likewise.
* testsuite/27_io/basic_istream/seekg/char/fstream.cc: Likewise.
* testsuite/27_io/basic_istream/seekg/wchar_t/fstream.cc:
Likewise.
* testsuite/27_io/basic_istream/tellg/char/fstream.cc: Likewise.
* testsuite/27_io/basic_istream/tellg/wchar_t/fstream.cc:
Likewise.
* testsuite/27_io/basic_ofstream/open/char/1.cc: Likewise.
* testsuite/27_io/basic_ostream/inserters_other/char/1.cc:
Likewise.
* testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc:
Likewise.
* testsuite/27_io/ios_base/sync_with_stdio/1.cc: Likewise.
* testsuite/27_io/basic_ostream/inserters_other/char/2.cc:
Likewise. Check file positions.
* testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc:
Likewise.
* testsuite/lib/libstdc++.exp (file-io-diff): New proc.

20 files changed:
libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc
libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/2.cc
libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/2.cc
libstdc++-v3/testsuite/27_io/basic_istream/get/char/2.cc
libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/2.cc
libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/3.cc
libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/3.cc
libstdc++-v3/testsuite/27_io/basic_istream/peek/char/6414.cc
libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/6414.cc
libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/fstream.cc
libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/fstream.cc
libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/fstream.cc
libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/fstream.cc
libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc
libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc
libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc
libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc
libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc
libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/1.cc
libstdc++-v3/testsuite/lib/libstdc++.exp

index e2b336a711d6fdb3cce6a86396bbae7137895c76..d9e9c53e3e6eda3ac7c00908a7f717f65789fcc1 100644 (file)
 // 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>
index 589402308c3077441afe85900f6a92caadccab05..77543310caa318b21f9e99c624c1786f27685d02 100644 (file)
 // 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>
index b50dd26513a955a5d3603da07aeddcdc871da107..82df1a17149de8567deb36e570b69fa291ed8be2 100644 (file)
 // 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>
index cf646f379efb28b1a24ef5e47c7085ef103a4304..95bad8badb90546cc1cf7cb0a33daf6f3c4a0f4d 100644 (file)
 // 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>
index 0ea162d8171bfdc554e29f1e7f91f1259749e203..c155e402e2c8af3350a6d55722b440d49f7dd9ba 100644 (file)
 // 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>
index 222e450e9c849efdd02bc679025c67be9ba3f4ce..acfafbcd83b1c8a180c8c0761f0804eb07fe7519 100644 (file)
 // 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>
index c9e942a712c569f0b049a9305d286e41e61bb0c2..60c2655b6066674a20d6e4c6440d5cd7af3e1475 100644 (file)
 // 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>
index 0e0b44153a8ee35dc80473f0eb08409a60d1d928..ffa0e88d8eb9da210fe653bd625c5a031a496e0e 100644 (file)
 // 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>
index fbfbfbb27816169a33e316d3f361431e9c007f63..0d2172fe85d616e162646a94448c0aabcc23e479 100644 (file)
 // 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>
index 0fa91a2716bf74addbcd5f3540db4c1cd8f602ae..52401ca88fdf845c2e1b6de4ce734c90f76e0f36 100644 (file)
 // 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>
index b792c8bc5cc809a55121cec4837f8ef270dbb837..6dc69d57516bb12edace8b1cf4735e1389ab1468 100644 (file)
 // <http://www.gnu.org/licenses/>.
 
 // { dg-require-fileio "" }
-
-// 27.6.1.3 unformatted input functions
+// { 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" } }
+
+// 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>
index a1eabd6abb4011443f8a5b8975010acead4d1fe9..8ab130a0a718f19bb8ca489617a02b2ad8131d42 100644 (file)
 // 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>
index 636193af7e349bfedf91cf6849f00ad8033f2aa5..b22871f0d7de3860f9ce0cca969a1993169627e9 100644 (file)
 // <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>
index 45227107cbd9c0eb0686f56ae1ec51ca25c6e79b..a9086a595cb1711986cb87a2bebd488cb5f9c65f 100644 (file)
 
 // 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>
index 6d30d0ce94f606a3ca4145381cc862cd53c0b28c..86a0ee8e77d02c4404120159a5e1981990e1a81c 100644 (file)
 // 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>
index 15f0d5f7b0bf75fbe4aef9e38f16687bfbe21ecb..735f2e20e9c903c9236d99c775b7e4e1911f044e 100644 (file)
@@ -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();
 }
index 7692637e16d64bb76674c62ddaad908087114d32..1aecfa4f0e90d32e99f8dedd6440c894ceb47582 100644 (file)
 // 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>
index 856af56011acb9432e20a57aa5823119e357ba99..663539a5b1936cc749396f6a221ae365648afc93 100644 (file)
@@ -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();
 }
index 4f9f7c3e554a03fb24a6b5b4f7c4236644821b24..20cbc1e08cd5fccae4ec0ea9bf92e4d86537ca31 100644 (file)
@@ -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>
index 8efc6f7f08997eaedad96e0d355386b3357720c8..ef511949c7bc0972e7c01473613a4bc5fa345894 100644 (file)
@@ -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
+}