[PATCH] D47557: Filesystem tests: un-confuse write time

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 31 15:53:01 PDT 2018


jfb updated this revision to Diff 149377.
jfb added a comment.

- Remove access time checks, simplify existing check, after talking to EricWF on IRC.


Repository:
  rCXX libc++

https://reviews.llvm.org/D47557

Files:
  test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp


Index: test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
===================================================================
--- test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
+++ test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
@@ -32,7 +32,9 @@
 
 using namespace fs;
 
-std::pair<std::time_t, std::time_t> GetTimes(path const& p) {
+struct Times { std::time_t access, write; };
+
+Times GetTimes(path const& p) {
     using Clock = file_time_type::clock;
     struct ::stat st;
     if (::stat(p.c_str(), &st) == -1) {
@@ -48,11 +50,11 @@
 }
 
 std::time_t LastAccessTime(path const& p) {
-    return GetTimes(p).first;
+    return GetTimes(p).access;
 }
 
 std::time_t LastWriteTime(path const& p) {
-    return GetTimes(p).second;
+    return GetTimes(p).write;
 }
 
 std::pair<std::time_t, std::time_t> GetSymlinkTimes(path const& p) {
@@ -228,11 +230,9 @@
     const path dir = env.create_dir("dir");
 
     const auto file_times = GetTimes(file);
-    const std::time_t file_access_time = file_times.first;
-    const std::time_t file_write_time = file_times.second;
+    const std::time_t file_write_time = file_times.write;
     const auto dir_times = GetTimes(dir);
-    const std::time_t dir_access_time = dir_times.first;
-    const std::time_t dir_write_time = dir_times.second;
+    const std::time_t dir_write_time = dir_times.write;
 
     file_time_type ftime = last_write_time(file);
     TEST_CHECK(Clock::to_time_t(ftime) == file_write_time);
@@ -253,9 +253,7 @@
 
     TEST_CHECK(ftime2 > ftime);
     TEST_CHECK(dtime2 > dtime);
-    TEST_CHECK(LastAccessTime(file) == file_access_time ||
-               LastAccessTime(file) == Clock::to_time_t(ftime2));
-    TEST_CHECK(LastAccessTime(dir) == dir_access_time);
+    TEST_CHECK(LastWriteTime(file) == Clock::to_time_t(ftime2));
 }
 
 
@@ -301,7 +299,7 @@
     };
     for (const auto& TC : cases) {
         const auto old_times = GetTimes(TC.p);
-        file_time_type old_time(Sec(old_times.second));
+        file_time_type old_time(Sec(old_times.write));
 
         std::error_code ec = GetTestEC();
         last_write_time(TC.p, TC.new_time, ec);
@@ -318,7 +316,7 @@
                 TEST_CHECK(got_time <= TC.new_time + Sec(1));
                 TEST_CHECK(got_time >= TC.new_time - Sec(1));
             }
-            TEST_CHECK(LastAccessTime(TC.p) == old_times.first);
+            TEST_CHECK(LastAccessTime(TC.p) == old_times.access);
         }
     }
 }
@@ -348,10 +346,10 @@
     file_time_type  got_time = last_write_time(sym);
     std::time_t got_time_t = Clock::to_time_t(got_time);
 
-    TEST_CHECK(got_time_t != old_times.second);
+    TEST_CHECK(got_time_t != old_times.write);
     TEST_CHECK(got_time_t == new_time_t);
     TEST_CHECK(LastWriteTime(file) == new_time_t);
-    TEST_CHECK(LastAccessTime(sym) == old_times.first);
+    TEST_CHECK(LastAccessTime(sym) == old_times.access);
     TEST_CHECK(GetSymlinkTimes(sym) == old_sym_times);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47557.149377.patch
Type: text/x-patch
Size: 3077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180531/eedd63fa/attachment.bin>


More information about the cfe-commits mailing list