lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Adding helper class for removing temporary test files


From: Vadim Zeitlin
Subject: [lmi] Adding helper class for removing temporary test files
Date: Sat, 8 Jun 2019 19:29:31 +0200

 Hello,

 A number of tests currently create temporary files that are only used
during the test execution. Some of them remove these files manually, see
e.g. istream_to_string_test.cpp. This suffers from the obvious problem that
the temporary files remain if any of the checks in the test throws an
exception (BTW, I find it curious that BOOST_TEST() doesn't catch the
unexpected exceptions resulting from the evaluation of its argument, IMO
it would be useful if it did).

 To address this, the file rate_table_test.cpp defines a simple RAII helper
called test_file_eraser which ensures that the file is erased in its dtor,
no matter what happens. However this file is not flexible enough, as it
always erases the file, and so can't be used in test_save() function in
that file, which wants to preserve the files in case of test failure.

 And, to come to the real reason I'm writing this email, this class is
private and can't be reused in the other tests, such as the upcoming
md5_test.cpp. Even if the class is trivial, I'd rather avoid duplicating it
in all the tests using temporary files. So I'd like to propose extracting
it into a header, improving it allow calling dismiss() on it to prevent it
from removing the file, and modifying the existing tests to use it instead
of std::remove().

 What do you think of this plan? And, if you agree to it, would you prefer
to add this class to the existing test_tools.hpp header or create a new one
just for it (to be called temp_file.hpp or any better name if you can
suggest one)?

 Thanks in advance,
VZ

Attachment: pgpfeNKSpFWZB.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]