martin-g commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454082653
##########
lang/c++/test/StreamTests.cc:
##########
@@ -134,36 +135,34 @@ void testNonEmpty2(const TestData &td) {
Verify1()(*is, td.dataSize);
}
-static const char filename[] = "test_str.bin";
-
-struct FileRemover {
- const std::filesystem::path file;
- explicit FileRemover(const char *fn) : file(fn) {}
- ~FileRemover() { std::filesystem::remove(file); }
+struct FileGuard {
+ const std::filesystem::path path{ std::tmpnam(nullptr) };
+ ~FileGuard() { std::filesystem::remove(path); }
Review Comment:
Should we care about failures in `remove()` here ?
Or since it is a test we don't care ?
##########
lang/c++/test/StreamTests.cc:
##########
@@ -134,36 +135,34 @@ void testNonEmpty2(const TestData &td) {
Verify1()(*is, td.dataSize);
}
-static const char filename[] = "test_str.bin";
-
-struct FileRemover {
- const std::filesystem::path file;
- explicit FileRemover(const char *fn) : file(fn) {}
- ~FileRemover() { std::filesystem::remove(file); }
+struct FileGuard {
+ const std::filesystem::path path{ std::tmpnam(nullptr) };
Review Comment:
Isn't `tmpnam` deprecated ?
Avro uses C++17, so we can use something like the following instead:
```
#include <random>
...
std::filesystem::path path = std::filesystem::temp_directory_path() /
("avro_test_" + std::to_string(std::random_device{}()));
```
##########
lang/c++/test/StreamTests.cc:
##########
@@ -134,36 +135,34 @@ void testNonEmpty2(const TestData &td) {
Verify1()(*is, td.dataSize);
}
-static const char filename[] = "test_str.bin";
-
-struct FileRemover {
- const std::filesystem::path file;
- explicit FileRemover(const char *fn) : file(fn) {}
- ~FileRemover() { std::filesystem::remove(file); }
+struct FileGuard {
+ const std::filesystem::path path{ std::tmpnam(nullptr) };
+ ~FileGuard() { std::filesystem::remove(path); }
+ const char* filename() const { return path.c_str(); };
Review Comment:
```suggestion
const char* filename() const { return path.c_str(); }
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]