STL_MSFT created this revision. STL_MSFT added reviewers: EricWF, mclow.lists. STL_MSFT added a subscriber: cfe-commits. Herald added a subscriber: aemerson.
[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 harmlessly ignore failures to open files for input and output simultaneously. The ofstream.cons tests are creating writable files (not checked into source control), where the ifstream tests will succeed. https://reviews.llvm.org/D26814 Files: test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp test/std/input.output/file.streams/fstreams/ifstream.cons/string.pass.cpp test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
Index: test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp =================================================================== --- test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp +++ test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp @@ -31,6 +31,12 @@ 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); @@ -42,5 +48,11 @@ 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()); } Index: test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp =================================================================== --- test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp +++ test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp @@ -31,6 +31,12 @@ 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()); @@ -42,5 +48,11 @@ 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()); } Index: test/std/input.output/file.streams/fstreams/ifstream.cons/string.pass.cpp =================================================================== --- test/std/input.output/file.streams/fstreams/ifstream.cons/string.pass.cpp +++ test/std/input.output/file.streams/fstreams/ifstream.cons/string.pass.cpp @@ -27,9 +27,13 @@ } { std::ifstream fs(std::string("test.dat"), std::ios_base::out); - double x = 0; - fs >> x; - assert(x == 3.25); + + if (fs) // "test.dat" might be read-only. + { // See also: test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp + double x = 0; + fs >> x; + assert(x == 3.25); + } } { std::wifstream fs(std::string("test.dat")); @@ -39,8 +43,12 @@ } { std::wifstream fs(std::string("test.dat"), std::ios_base::out); - double x = 0; - fs >> x; - assert(x == 3.25); + + if (fs) // "test.dat" might be read-only. + { // See also: test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp + double x = 0; + fs >> x; + assert(x == 3.25); + } } } Index: test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp =================================================================== --- test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp +++ test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp @@ -27,9 +27,13 @@ } { std::ifstream fs("test.dat", std::ios_base::out); - double x = 0; - fs >> x; - assert(x == 3.25); + + if (fs) // "test.dat" might be read-only. + { // See also: test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp + double x = 0; + fs >> x; + assert(x == 3.25); + } } { std::wifstream fs("test.dat"); @@ -39,8 +43,12 @@ } { std::wifstream fs("test.dat", std::ios_base::out); - double x = 0; - fs >> x; - assert(x == 3.25); + + if (fs) // "test.dat" might be read-only. + { // See also: test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp + double x = 0; + fs >> x; + assert(x == 3.25); + } } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits