summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2016-10-24 17:45:51 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2016-10-24 17:45:51 +0100
commit6daff2d946a2a656b5796e00d6ad65660315d565 (patch)
tree2fdbe7c11d477c3df27aa4e6f0894e21230764f5 /libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc
parentbb52a7e324258d55eef28d2b1c473b3973507da2 (diff)
PR71337 fix filesystem::temp_directory_path error handling
PR libstdc++/71337 * src/filesystem/ops.cc (temp_directory_path): Pass error_code argument to other filesystem operations. * testsuite/experimental/filesystem/operations/temp_directory_path.cc: Add testcase for inaccessible directory. From-SVN: r241487
Diffstat (limited to 'libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc')
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc
index 6e202c98dde..7f7e9fd7f26 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc
@@ -45,6 +45,7 @@ test01()
std::error_code ec;
fs::path p1 = fs::temp_directory_path(ec);
+ VERIFY( !ec );
VERIFY( exists(p1) );
fs::path p2 = fs::temp_directory_path();
@@ -62,6 +63,7 @@ test02()
std::error_code ec;
fs::path p = fs::temp_directory_path(ec);
VERIFY( ec );
+ VERIFY( p == fs::path() );
std::error_code ec2;
try {
@@ -72,10 +74,54 @@ test02()
VERIFY( ec2 == ec );
}
+void
+test03()
+{
+ auto p = __gnu_test::nonexistent_path();
+ create_directories(p/"tmp");
+ permissions(p, fs::perms::none);
+ setenv("TMPDIR", (p/"tmp").c_str(), 1);
+ std::error_code ec;
+ auto r = fs::temp_directory_path(ec); // libstdc++/PR71337
+ VERIFY( ec == std::make_error_code(std::errc::permission_denied) );
+ VERIFY( r == fs::path() );
+
+ std::error_code ec2;
+ try {
+ fs::temp_directory_path();
+ } catch (const fs::filesystem_error& e) {
+ ec2 = e.code();
+ }
+ VERIFY( ec2 == ec );
+
+ permissions(p, fs::perms::owner_all, ec);
+ remove_all(p, ec);
+}
+
+void
+test04()
+{
+ __gnu_test::scoped_file f;
+ setenv("TMPDIR", f.path.c_str(), 1);
+ std::error_code ec;
+ auto r = fs::temp_directory_path(ec);
+ VERIFY( ec == std::make_error_code(std::errc::not_a_directory) );
+ VERIFY( r == fs::path() );
+
+ std::error_code ec2;
+ try {
+ fs::temp_directory_path();
+ } catch (const fs::filesystem_error& e) {
+ ec2 = e.code();
+ }
+ VERIFY( ec2 == ec );
+}
int
main()
{
test01();
test02();
+ test03();
+ test04();
}