[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master cd87f2d 1/5: Explicitly test dubious assumpti
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master cd87f2d 1/5: Explicitly test dubious assumptions underlying some unit tests |
Date: |
Fri, 31 Jan 2020 11:29:39 -0500 (EST) |
branch: master
commit cd87f2d487f43dab6fe7d0ae45ec58b701cf4064
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Explicitly test dubious assumptions underlying some unit tests
The code covered by this unit test is actually defective, and
appropriately misbehaves with clang. That defect is masked by a
defective assumption in the unit test. Result: the code "works" with
gcc, and the unit test appears to demonstrate that it's correct, even
though the code, the test, and gcc are all actually defective. See:
https://lists.nongnu.org/archive/html/lmi/2020-01/msg00011.html
---
stream_cast_test.cpp | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/stream_cast_test.cpp b/stream_cast_test.cpp
index 08cea91..c4562e5 100644
--- a/stream_cast_test.cpp
+++ b/stream_cast_test.cpp
@@ -72,12 +72,29 @@ int test_main(int, char*[])
// First, test each exception coded in the primary template.
+ // Induce failure in ostream inserter:
+ std::stringstream ss0;
+ ss0 << static_cast<std::streambuf*>(nullptr);
+ BOOST_TEST(std::ios_base::badbit == ss0.rdstate());
BOOST_TEST_THROW
(stream_cast<std::string>(static_cast<std::streambuf*>(nullptr))
,std::runtime_error
,lmi_test::what_regex("^Input failed")
);
+ // Induce failure in istream extractor:
+ std::stringstream ss1;
+ ss1 << "INF";
+ BOOST_TEST(std::ios_base::goodbit == ss1.rdstate());
+ double d {0};
+ ss1 >> d;
+ // This test is defective. With clang, the stream state is good.
+ // With gcc, failbit is set, but apparently that's because gcc
+ // rejects the characters 'I' and 'N'--see:
+ // https://lists.nongnu.org/archive/html/lmi/2020-01/msg00010.html
+ // https://cplusplus.github.io/LWG/lwg-active.html#2381
+std::cout << ss1.rdstate() << std::endl;
+ BOOST_TEST(std::ios_base::failbit == ss1.rdstate());
BOOST_TEST_THROW
(stream_cast<double>("INF")
,std::runtime_error