From 31b74a064317186d7e891207de803b9d6dfb2642 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 23 Dec 2022 22:57:27 +0300 Subject: Add mtime() and atime() to dir_entry --- tests/dir-iterator/driver.cxx | 26 ++++++++++++++++++++++++++ tests/dir-iterator/testscript | 2 ++ 2 files changed, 28 insertions(+) (limited to 'tests') diff --git a/tests/dir-iterator/driver.cxx b/tests/dir-iterator/driver.cxx index 92b0b57..c9f7218 100644 --- a/tests/dir-iterator/driver.cxx +++ b/tests/dir-iterator/driver.cxx @@ -7,6 +7,7 @@ #include #include #include // operator<<(ostream, exception) +#include #include #undef NDEBUG @@ -38,6 +39,10 @@ operator<< (ostream& os, entry_type e) // Ignore dangling symlinks, rather than fail trying to obtain the target // type. // +// -d +// Detect dangling symlinks, rather than fail trying to obtain the target +// type. +// int main (int argc, const char* argv[]) { @@ -80,9 +85,30 @@ main (int argc, const char* argv[]) detect_dangling ? dir_iterator::detect_dangling : dir_iterator::no_follow))) { + timestamp mt (de.mtime ()); + timestamp at (de.atime ()); + entry_type lt (de.ltype ()); entry_type t (lt == entry_type::symlink ? de.type () : lt); + const path& p (de.path ()); + path fp (de.base () / p); + + entry_time et (t == entry_type::directory + ? dir_time (path_cast (fp)) + : file_time (fp)); + + if (mt != timestamp_unknown) + assert (mt == et.modification); + + if (at != timestamp_unknown) + assert (mt == et.access); + + if (de.mtime () != timestamp_unknown) + assert (de.mtime () == et.modification); + + if (de.atime () != timestamp_unknown) + assert (de.atime () == et.access); if (verbose) { diff --git a/tests/dir-iterator/testscript b/tests/dir-iterator/testscript index 9ecc58b..9bc5513 100644 --- a/tests/dir-iterator/testscript +++ b/tests/dir-iterator/testscript @@ -7,6 +7,8 @@ test.options = -v : mkdir a; touch a/b; +sleep 1; +echo "a" >=a/b; # Change modification time. $* a >"reg b" : dir -- cgit v1.1