[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] What does this test do?
From: |
Vadim Zeitlin |
Subject: |
Re: [lmi] What does this test do? |
Date: |
Tue, 11 May 2021 17:43:03 +0200 |
On Tue, 11 May 2021 14:25:38 +0000 Greg Chicares <gchicares@sbcglobal.net>
wrote:
GC> On 5/9/21 9:11 PM, Vadim Zeitlin wrote:
GC> > On Mon, 3 May 2021 14:50:05 +0000 Greg Chicares <gchicares@sbcglobal.net>
wrote:
GC> >
GC> > GC> Vadim--in a file that hasn't changed substantially since its 2005
original,
GC> > GC> I see:
GC> > GC>
GC> > GC> fs::directory_iterator const i(path);
GC> > GC> LMI_TEST(i->exists());
GC> > GC>
GC> > GC> and wonder: what was I thinking?
GC>
GC> Replaced, as proposed below, by
GC> LMI_TEST(fs::is_directory(path));
GC> in a soon-to-be pushed commit.
FWIW I think this is sufficient and see no need to do anything else.
GC> But let's consider the same lines, in opposite order:
GC>
GC> LMI_TEST(path.exists()); // #1
GC> LMI_TEST(is_directory(path)); // #2
GC>
GC> Is it ever useful to test both those conditions, in that order?
GC> Specifically, if #1 fails, then might #2 throw?
Even if it did, why would we care? We really just want is_directory() to
succeed, don't we? Whether it returns false or throws an exception or is
not even reached because of #1 are just different modes of failure and why
do we need to distinguish between them?
GC> In my tests, it doesn't throw: i.e.,
GC> fs::is_directory("This_path_does_not_exist");
GC> just returns 'false'. But AFAICT the standard says it calls
GC> std::filesystem::status(), which can throw if the underlying OS
GC> reports an error...so testing condition #1 before #2 might be
GC> a good idea. IOW, is the dual test in this actual lmi line:
GC>
GC> LMI_TEST(fs::exists(remote_dir_0) && fs::is_directory(remote_dir_0));
GC>
GC> useful, or wasteful?
It's superfluous, IMO. I.e. I don't see what do we lose by removing the
first part.
Regards,
VZ
pgpqLN3UZ1v_J.pgp
Description: PGP signature