[libcxx] r289463 - [libcxx] [test] Change ifstream constructor tests to handle read-only files.

Stephan T. Lavavej via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 12 11:50:23 PST 2016


Author: stl_msft
Date: Mon Dec 12 13:50:22 2016
New Revision: 289463

URL: http://llvm.org/viewvc/llvm-project?rev=289463&view=rev
Log:
[libcxx] [test] Change ifstream constructor tests to handle read-only files.

Certain source control systems like to set the read-only bit on their files,
which interferes with opening "test.dat" for both input and output.
Fortunately, we can work around this without losing test coverage.
Now, the ifstream.cons tests have comments referring to the ofstream.cons tests.
There, we're creating writable files (not checked into source control),
where the ifstream constructor tests will succeed.

Fixes D26814.

Modified:
    libcxx/trunk/test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp
    libcxx/trunk/test/std/input.output/file.streams/fstreams/ifstream.cons/string.pass.cpp
    libcxx/trunk/test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp
    libcxx/trunk/test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp

Modified: libcxx/trunk/test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp?rev=289463&r1=289462&r2=289463&view=diff
==============================================================================
--- libcxx/trunk/test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp (original)
+++ libcxx/trunk/test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp Mon Dec 12 13:50:22 2016
@@ -25,22 +25,16 @@ int main()
         fs >> x;
         assert(x == 3.25);
     }
-    {
-        std::ifstream fs("test.dat", std::ios_base::out);
-        double x = 0;
-        fs >> x;
-        assert(x == 3.25);
-    }
+    // std::ifstream(const char*, std::ios_base::openmode) is tested in
+    // test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp
+    // which creates writable files.
     {
         std::wifstream fs("test.dat");
         double x = 0;
         fs >> x;
         assert(x == 3.25);
     }
-    {
-        std::wifstream fs("test.dat", std::ios_base::out);
-        double x = 0;
-        fs >> x;
-        assert(x == 3.25);
-    }
+    // std::wifstream(const char*, std::ios_base::openmode) is tested in
+    // test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp
+    // which creates writable files.
 }

Modified: libcxx/trunk/test/std/input.output/file.streams/fstreams/ifstream.cons/string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/file.streams/fstreams/ifstream.cons/string.pass.cpp?rev=289463&r1=289462&r2=289463&view=diff
==============================================================================
--- libcxx/trunk/test/std/input.output/file.streams/fstreams/ifstream.cons/string.pass.cpp (original)
+++ libcxx/trunk/test/std/input.output/file.streams/fstreams/ifstream.cons/string.pass.cpp Mon Dec 12 13:50:22 2016
@@ -25,22 +25,16 @@ int main()
         fs >> x;
         assert(x == 3.25);
     }
-    {
-        std::ifstream fs(std::string("test.dat"), std::ios_base::out);
-        double x = 0;
-        fs >> x;
-        assert(x == 3.25);
-    }
+    // std::ifstream(const std::string&, std::ios_base::openmode) is tested in
+    // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
+    // which creates writable files.
     {
         std::wifstream fs(std::string("test.dat"));
         double x = 0;
         fs >> x;
         assert(x == 3.25);
     }
-    {
-        std::wifstream fs(std::string("test.dat"), std::ios_base::out);
-        double x = 0;
-        fs >> x;
-        assert(x == 3.25);
-    }
+    // std::wifstream(const std::string&, std::ios_base::openmode) is tested in
+    // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
+    // which creates writable files.
 }

Modified: libcxx/trunk/test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp?rev=289463&r1=289462&r2=289463&view=diff
==============================================================================
--- libcxx/trunk/test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp (original)
+++ libcxx/trunk/test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp Mon Dec 12 13:50:22 2016
@@ -31,6 +31,12 @@ int main()
         fs >> x;
         assert(x == 3.25);
     }
+    {
+        std::ifstream fs(temp.c_str(), std::ios_base::out);
+        double x = 0;
+        fs >> x;
+        assert(x == 3.25);
+    }
     std::remove(temp.c_str());
     {
         std::wofstream fs(temp.c_str());
@@ -41,6 +47,12 @@ int main()
         double x = 0;
         fs >> x;
         assert(x == 3.25);
+    }
+    {
+        std::wifstream fs(temp.c_str(), std::ios_base::out);
+        double x = 0;
+        fs >> x;
+        assert(x == 3.25);
     }
     std::remove(temp.c_str());
 }

Modified: libcxx/trunk/test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp?rev=289463&r1=289462&r2=289463&view=diff
==============================================================================
--- libcxx/trunk/test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp (original)
+++ libcxx/trunk/test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp Mon Dec 12 13:50:22 2016
@@ -31,6 +31,12 @@ int main()
         fs >> x;
         assert(x == 3.25);
     }
+    {
+        std::ifstream fs(temp, std::ios_base::out);
+        double x = 0;
+        fs >> x;
+        assert(x == 3.25);
+    }
     std::remove(temp.c_str());
     {
         std::wofstream fs(temp);
@@ -41,6 +47,12 @@ int main()
         double x = 0;
         fs >> x;
         assert(x == 3.25);
+    }
+    {
+        std::wifstream fs(temp, std::ios_base::out);
+        double x = 0;
+        fs >> x;
+        assert(x == 3.25);
     }
     std::remove(temp.c_str());
 }




More information about the cfe-commits mailing list