[libcxx] [test] Explicitly check that some env vars are ignored in the temp_dir_path...
authorMartin Storsjö <martin@martin.st>
Tue, 16 Mar 2021 11:19:11 +0000 (13:19 +0200)
committerMartin Storsjö <martin@martin.st>
Fri, 19 Mar 2021 07:33:26 +0000 (09:33 +0200)
This was suggested in the review of D98139.

Differential Revision: https://reviews.llvm.org/D98696

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp

index 32748de..28331c7 100644 (file)
@@ -66,6 +66,14 @@ TEST_CASE(basic_tests)
         {"TEMPDIR", env.create_dir("dir4")}
 #endif
     };
+    TestCase ignored_cases[] = {
+#ifdef _WIN32
+        {"TMPDIR", env.create_dir("dir5")},
+        {"TEMPDIR", env.create_dir("dir6")},
+#else
+        {"USERPROFILE", env.create_dir("dir5")},
+#endif
+    };
     for (auto& TC : cases) {
         PutEnv(TC.name, TC.p);
     }
@@ -114,6 +122,7 @@ TEST_CASE(basic_tests)
         UnsetEnv(TC.name);
     }
     // No env variables are defined
+    path fallback;
     {
         std::error_code ec = GetTestEC();
         path ret = temp_directory_path(ec);
@@ -123,6 +132,20 @@ TEST_CASE(basic_tests)
         TEST_CHECK(ret == "/tmp");
 #endif
         TEST_CHECK(is_directory(ret));
+        fallback = ret;
+    }
+    for (auto& TC : ignored_cases) {
+        // Check that certain variables are ignored
+        PutEnv(TC.name, TC.p);
+        std::error_code ec = GetTestEC();
+        path ret = temp_directory_path(ec);
+        TEST_CHECK(!ec);
+
+        // Check that we return the same as above when no vars were defined.
+        TEST_CHECK(ret == fallback);
+
+        // Finally erase this env variable
+        UnsetEnv(TC.name);
     }
 }